X-Git-Url: http://git.hcoop.net/jackhill/mal.git/blobdiff_plain/3169070063b2cb877200117ebb384269d73bcb93..2b8e0ea42046505635e8f4c9d96e594c595948c2:/runtest.py diff --git a/runtest.py b/runtest.py index 736768a8..aacd7704 100755 --- a/runtest.py +++ b/runtest.py @@ -18,6 +18,10 @@ parser.add_argument('--start-timeout', default=10, type=int, help="default timeout for initial prompt") parser.add_argument('--test-timeout', default=20, type=int, help="default timeout for each individual test action") +parser.add_argument('--pre-eval', default=None, type=str, + help="Mal code to evaluate prior to running the test") +parser.add_argument('--redirect', action='store_true', + help="Run implementation in bash and redirect output to /dev/null") parser.add_argument('test_file', type=argparse.FileType('r'), help="a test file formatted as with mal test data") @@ -30,7 +34,12 @@ test_data = args.test_file.read().split('\n') if args.rundir: os.chdir(args.rundir) -p = spawn(args.mal_cmd[0], args.mal_cmd[1:]) +if args.redirect: + # Redirect to try and force raw mode (no ASCII codes) + p = spawn('/bin/bash -c "' + " ".join(args.mal_cmd) + ' |tee /dev/null"') +else: + p = spawn(args.mal_cmd[0], args.mal_cmd[1:]) + test_idx = 0 def read_test(data): @@ -70,14 +79,24 @@ def read_test(data): return form, output, ret, test_idx +def assert_prompt(timeout): + # Wait for the initial prompt + idx = p.expect(['user> ', 'mal-user> ', EOF, TIMEOUT], + timeout=timeout) + if idx not in [0,1]: + print "Did not get 'user> ' or 'mal-user> ' prompt" + print " Got : %s" % repr(p.before) + sys.exit(1) + # Wait for the initial prompt -idx = p.expect(['user> ', 'mal-user> ', EOF, TIMEOUT], - timeout=args.start_timeout) -if idx not in [0,1]: - print "Never got 'user> ' prompt" - print " Got : %s" % repr(p.before) - sys.exit(1) +assert_prompt(args.start_timeout) + +# Send the pre-eval code if any +if args.pre_eval: + sys.stdout.write("RUNNING pre-eval: %s" % args.pre_eval) + p.sendline(args.pre_eval) + assert_prompt(args.test_timeout) fail_cnt = 0