Ignore:
Timestamp:
Jul 8, 2013, 11:27:13 AM (7 years ago)
Author:
marius@…
Message:

Added color, formatted output and help proc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/gsoc13-tests/tests/test.tcl

    r107862 r107883  
    2525proc print_help {arg} {
    2626    if { $arg == "tests" } {
    27         puts "test list"
     27        puts "The list of abailable tests is:"
     28        foreach test $::test_suite {
     29            puts [puts -nonewline "  "]$test
     30        }
    2831    } else {
    29         puts "help message"
     32        puts "Usage: tclsh test.tcl \[-debug level\] \[-t test\] \[-l\]\n"
     33        puts "  -debug LVL : sets the level of printed debug info \[0-3\]"
     34        puts "  -t TEST    : run a specific test"
     35        puts "  -l         : print the list of available tests"
     36        puts "  -h, -help  : print this message\n"
    3037    }
    3138}
     
    3441foreach arg $argv {
    3542    if { $arg == "-h" || $arg == "-help" } {
    36         print_help
     43        print_help ""
    3744        exit 0
    3845    } elseif { $arg == "-debug" } {
    3946        set index [expr [lsearch $argv $arg] + 1]
    4047        set level [lindex $argv $index]
    41         if { $level >= 0 && $level <= 5 } {
     48        if { $level >= 0 && $level <= 3 } {
    4249            append arguments "-debug " $level
    4350        } else {
     
    5865            exit 1
    5966        }
    60     }       
     67    } elseif { $arg == "-l" } {
     68        print_help tests
     69        exit 0
     70    }
    6171}
     72
    6273
    6374# Run tests
     
    7384   
    7485        set result [eval exec tclsh test.tcl $arguments]
    75         puts $result
     86        set total [lrange [split $result "\t"] 2 2]
     87        set pass [lrange [split $result "\t"] 4 4]
     88        set fail [lrange [split $result "\t"] 8 8]
     89
     90        set out ""
     91        if { $fail != 0 } {
     92            # Color failed tests.
     93            append out "\x1b\[1;31mTotal:" $total " Passed:" $pass " Failed:" $fail "  \x1b\[0m" $test
     94        } else {
     95            append out "Total:" $total " Passed:" $pass " Failed:" $fail "  " $test
     96        }
     97        puts $out
    7698   
    7799        cd ../..
Note: See TracChangeset for help on using the changeset viewer.