Changes in / [14d2bdf:25296a3]


Ignore:
Location:
src/tests
Files:
2 edited

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
     1make: *** 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  
    3232#               running test functions
    3333################################################################################
    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)
     34def run_test_instance(test, dry_run):
     35        sh("rm -f .out/%s.log" % test, dry_run)
    3936        sh("rm -f %s > /dev/null 2>&1" % test, dry_run)
    4037
    4138        # 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)
    4340
    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 ""
    4743
    48                 # run test
    49                 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)
    5046
    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)
    5549
    56                 # diff the output of the files
    57                 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)
    5852
    5953        # clean the executable
     
    6256        return retcode
    6357
    64 def run_tests(tests, generate, dry_run) :
     58def run_tests(tests, dry_run) :
    6559        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 ) )
    7160
    7261        failed = False;
    7362        for t in tests:
    74                 if not generate :
    75                         print("%20s  " % t, end="")
     63                print("%10s  " % t, end="")
    7664                sys.stdout.flush()
    77                 test_failed = run_test_instance(t, generate, dry_run)
     65                test_failed = run_test_instance(t, dry_run)
    7866                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")
    8268
    8369        sh('make clean > /dev/null 2>&1', dry_run)
    8470
    85         if generate :
    86                 print( "Done" )
     71        return 0 if failed else 1
    8772
    88         return 0 if failed else 1
     73################################################################################
     74#               generate expectation functions
     75################################################################################
     76def 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
     92def 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)
    89105
    90106################################################################################
     
    99115options = parser.parse_args()
    100116
    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)
     117tests = listTests()
    105118
    106 tests = listTests() if options.all else options.tests
     119if options.all :
     120        if len(options.tests) > 0 :
     121                print('ERROR: cannot specify tests with \'--all\' option', file=sys.stderr)
     122                sys.exit(1)
    107123
    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
     129else :
     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
     140sys.exit(0)
Note: See TracChangeset for help on using the changeset viewer.