Changes in / [14d2bdf:25296a3]
- Location:
- src/tests
- Files:
-
- 2 edited
-
.expect/vector_test.txt (modified) (1 diff)
-
test.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/tests/.expect/vector_test.txt
r14d2bdf r25296a3 1 enter N elements and C-d on a separate line: 2 Array elements: 3 1 2 3 4 5 4 Array elements reversed: 5 5 4 3 2 1 1 make: *** No rule to make target `vector_int.c', needed by `vector_int.o'. Stop. 2 /bin/sh: ./vector_test: Is a directory -
src/tests/test.py
r14d2bdf r25296a3 32 32 # running test functions 33 33 ################################################################################ 34 def run_test_instance(test, generate, dry_run): 35 36 out_file = (".out/%s.log" % test) if not generate else (".expect/%s.txt" % test) 37 38 sh("rm -f %s" % out_file, dry_run) 34 def run_test_instance(test, dry_run): 35 sh("rm -f .out/%s.log" % test, dry_run) 39 36 sh("rm -f %s > /dev/null 2>&1" % test, dry_run) 40 37 41 38 # build, skipping to next test on error 42 make_ret = sh("make -j 1 %s > %s 2>&1" % (test, out_file), dry_run)39 sh("make -j 1 %s >> .out/%s.log 2>&1" % (test, test), dry_run) 43 40 44 if make_ret == 0 : 45 # fetch optional input 46 stdinput = "< .in/%s.txt" % test if isfile(".in/%s.txt" % test) else "" 41 # fetch optional input 42 stdinput = "< .in/%s.txt" % test if isfile(".in/%s.txt" % test) else "" 47 43 48 # run test49 sh("./%s %s > %s 2>&1" % (test, stdinput, out_file), dry_run)44 # run test 45 sh("./%s %s >> .out/%s.log 2>&1" % (test, stdinput, test), dry_run) 50 46 51 retcode = 0 52 if not generate : 53 # touch expected files so empty output are supported by default 54 sh("touch .expect/%s.txt" % test, dry_run) 47 # touch expected files so empty output are supported by default 48 sh("touch .expect/%s.txt" % test, dry_run) 55 49 56 # diff the output of the files57 retcode = sh("diff .expect/%s.txt .out/%s.log" % (test, test), dry_run)50 # diff the output of the files 51 retcode = sh("diff .expect/%s.txt .out/%s.log" % (test, test), dry_run) 58 52 59 53 # clean the executable … … 62 56 return retcode 63 57 64 def run_tests(tests, generate,dry_run) :58 def run_tests(tests, dry_run) : 65 59 sh('make clean > /dev/null 2>&1', dry_run) 66 sh('mkdir -p .out .expect', dry_run)67 68 if generate :69 print( "Regenerate tests for: ", end="" )70 print( ", ".join( tests ) )71 60 72 61 failed = False; 73 62 for t in tests: 74 if not generate : 75 print("%20s " % t, end="") 63 print("%10s " % t, end="") 76 64 sys.stdout.flush() 77 test_failed = run_test_instance(t, generate,dry_run)65 test_failed = run_test_instance(t, dry_run) 78 66 failed = test_failed or failed 79 80 if not generate : 81 print("FAILED" if test_failed else "PASSED") 67 print("FAILED" if test_failed else "PASSED") 82 68 83 69 sh('make clean > /dev/null 2>&1', dry_run) 84 70 85 if generate : 86 print( "Done" ) 71 return 0 if failed else 1 87 72 88 return 0 if failed else 1 73 ################################################################################ 74 # generate expectation functions 75 ################################################################################ 76 def generate_test_expect(test): 77 sh("rm -f .out/%s.log" % test, False) 78 sh("rm -f %s > /dev/null 2>&1" % test, False) 79 80 # build, skipping to next test on error 81 sh("make -j 8 %s > .expect/%s.txt 2>&1" % (test, test), False) 82 83 # fetch optional input 84 stdinput = "< .in/%s.txt" % test if isfile(".in/%s.txt" % test) else "" 85 86 # run test 87 sh("./%s %s >> .expect/%s.txt 2>&1" % (test, stdinput, test), False) 88 89 # clean the executable 90 sh("rm -f %s > /dev/null 2>&1" % test, False) 91 92 def generate_expect(tests) : 93 sh('make clean > /dev/null 2>&1', False) 94 95 print( "Regenerate tests for" ) 96 97 print( ", ".join( tests ) ) 98 99 for t in tests: 100 generate_test_expect( t ) 101 102 print( "Done" ) 103 104 sh('make clean > /dev/null 2>&1', False) 89 105 90 106 ################################################################################ … … 99 115 options = parser.parse_args() 100 116 101 if len(options.tests) > 0 and options.all : 102 print('ERROR: must have option \'--all\' or non-empty test list', file=sys.stderr) 103 parser.print_help() 104 sys.exit(1) 117 tests = listTests() 105 118 106 tests = listTests() if options.all else options.tests 119 if options.all : 120 if len(options.tests) > 0 : 121 print('ERROR: cannot specify tests with \'--all\' option', file=sys.stderr) 122 sys.exit(1) 107 123 108 sys.exit( run_tests(tests, options.generate_expected, options.dry_run) ) 124 if options.generate_expected : 125 generate_expect( tests ) 126 else : 127 sys.exit( run_tests(tests, options.dry_run) ) 128 129 else : 130 if len(options.tests) == 0 : 131 print('ERROR: must have option \'--all\' or non-empty test list', file=sys.stderr) 132 parser.print_help() 133 sys.exit(1) 134 135 if options.generate_expected : 136 generate_expect( options.tests ) 137 else : 138 sys.exit( run_tests(options.tests, options.dry_run) ) 139 140 sys.exit(0)
Note:
See TracChangeset
for help on using the changeset viewer.