Revamp tests

This commit is contained in:
Enrico Lumetti 2022-08-13 23:47:05 +02:00
parent 1a0eeea38b
commit 18ebacb00b
14 changed files with 169 additions and 17 deletions

52
complete-tests.rkt Normal file
View File

@ -0,0 +1,52 @@
#lang racket
(provide read-bril-file read-rvar-file complete-tests)
(require json rackunit (only-in bril program-to-jsexpr))
(require "uniquify.rkt")
(require "remove-complex-oper.rkt")
(require "explicate-control.rkt")
(require "cvar-to-bril.rkt")
(define-namespace-anchor anc)
(define ns (namespace-anchor->namespace anc))
(define (read-bril-file path)
(with-input-from-file path
(lambda () (read-json))))
(define (read-rvar-file path)
(with-input-from-file path
(lambda ()
(parameterize ([current-namespace ns])
(namespace-attach-module-declaration ns '"rvar.rkt")
(namespace-require '"rvar.rkt")
(eval (read))))))
(define (rvar-to-cvar program)
(explicate-control (remove-complex-opera*-2 (uniquify program))))
(define (rvar-to-bril-json program)
(program-to-jsexpr (cvar-to-bril (rvar-to-cvar program))))
(define (complete-rvar-test test-desc rvar-path bril-path)
(test-case
test-desc
(let ([rvar (read-rvar-file rvar-path)]
[bril (read-bril-file bril-path)])
(test-case
"RVar->bril"
(parameterize ([current-namespace ns])
(namespace-attach-module-declaration ns '"rvar.rkt")
(namespace-require '"rvar.rkt")
(check-equal? bril (rvar-to-bril-json rvar)))))))
(define complete-tests
(test-suite
"Complete Tests"
(complete-rvar-test
"Simple RVar Tests"
"complete-tests/test1.rvar"
"complete-tests/test1.bril")))

62
complete-tests/test1.bril Normal file
View File

@ -0,0 +1,62 @@
{
"functions": [
{
"args": [],
"instrs": [
{
"label": "start"
},
{
"dest": "tmp.0",
"op": "const",
"type": "int",
"value": 1
},
{
"dest": "tmp.1",
"op": "const",
"type": "int",
"value": 0
},
{
"args": [
"tmp.1",
"tmp.0"
],
"dest": "tmp.1",
"funcs": [],
"labels": [],
"op": "sub",
"type": "int"
},
{
"dest": "tmp.2",
"op": "const",
"type": "int",
"value": 2
},
{
"args": [
"tmp.1",
"tmp.2"
],
"dest": "tmp.3",
"funcs": [],
"labels": [],
"op": "add",
"type": "int"
},
{
"args": [
"tmp.3"
],
"funcs": [],
"labels": [],
"op": "return"
}
],
"name": "main"
}
]
}

View File

@ -0,0 +1,5 @@
(Program '()
(Prim '+
(list (Prim '- (list (Int 1)))
(Int 2))))

9
run-all-tests.rkt Normal file
View File

@ -0,0 +1,9 @@
#lang racket
(require rackunit rackunit/text-ui)
(require "tests/all-tests.rkt")
(require "complete-tests.rkt")
(run-tests all-tests)
(run-tests complete-tests)

24
tests/all-tests.rkt Normal file
View File

@ -0,0 +1,24 @@
#lang racket
(provide all-tests)
(require rackunit)
(require "test-rint.rkt")
(require "test-rvar.rkt")
(require "test-cvar.rkt")
(require "test-uniquify.rkt")
;(require "test-remove-complex-opera.rkt")
;(require "test-explicate-control.rkt")
(require "test-cvar-to-bril.rkt")
(define all-tests
(test-suite
"All tests"
rint-tests
rvar-tests
cvar-tests
uniquify-tests
;remove-complex-opera-tests
;explicate-control-tests
cvar-to-bril-tests))

View File

@ -3,11 +3,11 @@
(provide cvar-to-bril-tests) (provide cvar-to-bril-tests)
(require rackunit) (require rackunit)
(require "cvar-to-bril.rkt") (require "../cvar-to-bril.rkt")
(require "uniquify.rkt") (require "../uniquify.rkt")
(require "remove-complex-oper.rkt") (require "../remove-complex-oper.rkt")
(require "explicate-control.rkt") (require "../explicate-control.rkt")
(require "rvar.rkt") (require "../rvar.rkt")
(require bril/interpreter) (require bril/interpreter)
(define listings (define listings

View File

@ -4,7 +4,7 @@
(require rackunit) (require rackunit)
(require "test-util.rkt") (require "test-util.rkt")
(require "cvar.rkt") (require "../cvar.rkt")
(define seq-1 (define seq-1
(Return (Int 0))) (Return (Int 0)))

View File

@ -1,10 +1,10 @@
#lang racket #lang racket
(provide test-rint-tests) (provide rint-tests)
(require rackunit) (require rackunit)
(require "test-util.rkt") (require "test-util.rkt")
(require "rint.rkt") (require "../rint.rkt")
(define eight (Int 8)) (define eight (Int 8))
(define rd (Prim 'read '())) (define rd (Prim 'read '()))
@ -12,7 +12,7 @@
(define ast1.1 (Prim '+ (list rd neg-eight))) (define ast1.1 (Prim '+ (list rd neg-eight)))
(define program (Program '() ast1.1)) (define program (Program '() ast1.1))
(define test-rint-tests (define rint-tests
(test-suite (test-suite
"RInt interpretation tests" "RInt interpretation tests"
(test-case (test-case

View File

@ -1,14 +1,14 @@
#lang racket #lang racket
(provide test-rvar-tests) (provide rvar-tests)
(require rackunit) (require rackunit)
(require "rvar.rkt") (require "../rvar.rkt")
(define (interp-exp env e) (define (interp-exp env e)
((send (new interp-RVar-class) interp-exp env) e)) ((send (new interp-RVar-class) interp-exp env) e))
(define test-rvar-tests (define rvar-tests
(test-suite (test-suite
"RVar interpretation testsuite" "RVar interpretation testsuite"

View File

@ -1,12 +1,12 @@
#lang racket #lang racket
(provide test-uniquify-tests) (provide uniquify-tests)
(require rackunit) (require rackunit)
(require "rvar.rkt") (require "../rvar.rkt")
(require "uniquify.rkt") (require "../uniquify.rkt")
(require/expose "uniquify.rkt" (uniquify-exp)) (require/expose "../uniquify.rkt" (uniquify-exp))
; returns both the resulting symtable and the uniquified program ; returns both the resulting symtable and the uniquified program
(define (list-uniquify-exp symtable) (define (list-uniquify-exp symtable)
@ -26,7 +26,7 @@
(Var 'y)) (Var 'y))
(Prim '+ (list (Var 'x) (Int 5)))))) (Prim '+ (list (Var 'x) (Int 5))))))
(define test-uniquify-tests (define uniquify-tests
(test-suite (test-suite
"Uniquify pass testsuite" "Uniquify pass testsuite"
(test-case (test-case