Skip to content

Commit

Permalink
runtest.py: process output/errors as regex match.
Browse files Browse the repository at this point in the history
Update output test data to be regex compatible.
  • Loading branch information
kanaka committed Nov 30, 2018
1 parent 96c09dc commit f6f5d4f
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 44 deletions.
28 changes: 20 additions & 8 deletions runtest.py
Expand Up @@ -215,15 +215,19 @@ def next(self):
self.line_num += 1
self.data.pop(0)
break
elif line[0:2] == "; ":
elif line[0:2] == ";/":
self.out = self.out + line[2:] + sep
self.line_num += 1
self.data.pop(0)
else:
self.ret = "*"
self.ret = ""
break
if self.ret: break
if self.ret != None: break

if self.out[-2:] == sep and not self.ret:
# If there is no return value, output should not end in
# separator
self.out = self.out[0:-2]
return self.form

args = parser.parse_args(sys.argv[1:])
Expand Down Expand Up @@ -293,16 +297,23 @@ def assert_prompt(runner, prompts, timeout):
# The repeated form is to get around an occasional OS X issue
# where the form is repeated.
# https://github.com/kanaka/mal/issues/30
expected = ["%s%s%s%s" % (t.form, sep, t.out, t.ret),
"%s%s%s%s%s%s" % (t.form, sep, t.form, sep, t.out, t.ret)]
expects = ["%s%s%s%s" % (re.escape(t.form), sep,
t.out, re.escape(t.ret)),
"%s%s%s%s%s%s" % (re.escape(t.form), sep,
re.escape(t.form), sep,
t.out, re.escape(t.ret))]

r.writeline(t.form)
try:
test_cnt += 1
res = r.read_to_prompt(['\r\n[^\s()<>]+> ', '\n[^\s()<>]+> '],
timeout=args.test_timeout)
#print "%s,%s,%s" % (idx, repr(p.before), repr(p.after))
if t.ret == "*" or res in expected:
if (t.ret == "" and t.out == ""):
log(" -> SUCCESS (result ignored)")
pass_cnt += 1
elif (re.search(expects[0], res, re.S) or
re.search(expects[1], res, re.S)):
log(" -> SUCCESS")
pass_cnt += 1
else:
Expand All @@ -314,11 +325,12 @@ def assert_prompt(runner, prompts, timeout):
log(" -> FAIL (line %d):" % t.line_num)
fail_cnt += 1
fail_type = ""
log(" Expected : %s" % repr(expected[0]))
log(" Expected : %s" % repr(expects[0]))
log(" Got : %s" % repr(res))
failed_test = """%sFAILED TEST (line %d): %s -> [%s,%s]:
Expected : %s
Got : %s""" % (fail_type, t.line_num, t.form, repr(t.out), t.ret, repr(expected[0]), repr(res))
Got : %s""" % (fail_type, t.line_num, t.form, repr(t.out),
t.ret, repr(expects[0]), repr(res))
failures.append(failed_test)
except:
_, exc, _ = sys.exc_info()
Expand Down
13 changes: 8 additions & 5 deletions tests/step1_read_print.mal
Expand Up @@ -75,15 +75,18 @@ false
;=>""

;; Testing reader errors
;;; TODO: fix these so they fail correctly
(1 2
; expected ')', got EOF
;/.*(EOF|end of input|unbalanced).*
[1 2
; expected ']', got EOF
;/.*(EOF|end of input|unbalanced).*

;;; These should throw some error with no return value
"abc
; expected '"', got EOF
;/.+
(1 "abc
; expected ')', got EOF
;/.+
(1 "abc"
;/.+

;; Testing read of quoting
'1
Expand Down
3 changes: 2 additions & 1 deletion tests/step2_eval.mal
Expand Up @@ -20,8 +20,9 @@
(/ (- (+ 515 (* -87 311)) 296) 27)
;=>-994

;;; This should throw an error with no return value
(abc 1 2 3)
; .*\'abc\' not found.*
;/.+

;; Testing empty list
()
Expand Down
2 changes: 1 addition & 1 deletion tests/step3_env.mal
Expand Up @@ -31,7 +31,7 @@ MYNUM

;; Check env lookup non-fatal error
(abc 1 2 3)
; .*\'abc\' not found.*
;/.*\'?abc\'? not found.*
;; Check that error aborts def!
(def! w 123)
(def! w (abc))
Expand Down
44 changes: 22 additions & 22 deletions tests/step4_if_fn_do.mal
Expand Up @@ -173,14 +173,14 @@

;; Testing do form
(do (prn "prn output1"))
; "prn output1"
;/"prn output1"
;=>nil
(do (prn "prn output2") 7)
; "prn output2"
;/"prn output2"
;=>7
(do (prn "prn output1") (prn "prn output2") (+ 1 2))
; "prn output1"
; "prn output2"
;/"prn output1"
;/"prn output2"
;=>3

(do (def! a 6) 7 (+ a 8))
Expand Down Expand Up @@ -341,69 +341,69 @@ a

;; Testing prn
(prn)
;
;/
;=>nil

(prn "")
; ""
;/""
;=>nil

(prn "abc")
; "abc"
;/"abc"
;=>nil

(prn "abc def" "ghi jkl")
; "abc def" "ghi jkl"
;/"abc def" "ghi jkl"

(prn "\"")
; "\""
;/"\\""
;=>nil

(prn "abc\ndef\nghi")
; "abc\ndef\nghi"
;/"abc\\ndef\\nghi"
;=>nil

(prn "abc\\def\\ghi")
; "abc\\def\\ghi"
;/"abc\\\\def\\\\ghi"
nil

(prn (list 1 2 "abc" "\"") "def")
; (1 2 "abc" "\"") "def"
;/\(1 2 "abc" "\\""\) "def"
;=>nil


;; Testing println
(println)
;
;/
;=>nil

(println "")
;
;/
;=>nil

(println "abc")
; abc
;/abc
;=>nil

(println "abc def" "ghi jkl")
; abc def ghi jkl
;/abc def ghi jkl

(println "\"")
; "
;/"
;=>nil

(println "abc\ndef\nghi")
; abc
; def
; ghi
;/abc
;/def
;/ghi
;=>nil

(println "abc\\def\\ghi")
; abc\def\ghi
;/abc\\def\\ghi
;=>nil

(println (list 1 2 "abc" "\"") "def")
; (1 2 abc ") def
;/\(1 2 abc "\) def
;=>nil

;>>> optional=True
Expand Down
2 changes: 1 addition & 1 deletion tests/step6_file.mal
Expand Up @@ -99,7 +99,7 @@

;; Testing comments in a file
(load-file "../tests/incB.mal")
; "incB.mal finished"
;/"incB.mal finished"
;=>"incB.mal return string"
(inc4 7)
;=>11
Expand Down
12 changes: 6 additions & 6 deletions tests/step9_try.mal
Expand Up @@ -5,11 +5,11 @@
;=>123

(try* (abc 1 2) (catch* exc (prn "exc is:" exc)))
; "exc is:" "'abc' not found"
;/"exc is:" "'abc' not found"
;=>nil

(try* (throw "my exception") (catch* exc (do (prn "exc:" exc) 7)))
; "exc:" "my exception"
;/"exc:" "my exception"
;=>7

;;; Test that throw is a function:
Expand Down Expand Up @@ -48,10 +48,10 @@
(apply + 4 (list 5))
;=>9
(apply prn (list 1 2 "3" (list)))
; 1 2 "3" ()
;/1 2 "3" \(\)
;=>nil
(apply prn 1 2 (list "3" (list)))
; 1 2 "3" ()
;/1 2 "3" \(\)
;=>nil
(apply list (list))
;=>()
Expand Down Expand Up @@ -124,7 +124,7 @@
(apply + 4 [5])
;=>9
(apply prn 1 2 ["3" 4])
; 1 2 "3" 4
;/1 2 "3" 4
;=>nil
(apply list [])
;=>()
Expand Down Expand Up @@ -307,7 +307,7 @@
;;
;; Testing throwing non-strings
(try* (throw (list 1 2 3)) (catch* exc (do (prn "err:" exc) 7)))
; "err:" (1 2 3)
;/"err:" \(1 2 3\)
;=>7

;;
Expand Down

0 comments on commit f6f5d4f

Please sign in to comment.