summaryrefslogtreecommitdiff
path: root/itcl/itcl/tests/all.tcl
blob: ddefa468dd760c682aec3e0f939da6add3157ce1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# all.tcl --
#
# This file contains a top-level script to run all of the Tcl
# tests.  Execute it by invoking "source all.test" when running tcltest
# in this directory.
#
# Copyright (c) 1998-2000 by Ajuba Solutions
# All rights reserved.
# 
# RCS: @(#) $Id$

package require tcltest
namespace import -force ::tcltest::*

# Look for the -exedir flag and find a suitable tclsh executable.

if {(![info exists argv]) || ([llength $argv] < 1)} {
    set flagArray {}
} else {
    set flagArray $argv
}

array set flag $flagArray
if {[info exists flag(-exedir)]} {
    set shell [lindex \
	    [glob -nocomplain \
	    [file join $flag(-exedir) tclsh*.bin] \
	    [file join $flag(-exedir) tclsh*]] 0]
} else {
    set shell $::tcltest::tcltest
}

set ::tcltest::testSingleFile false

# use [pwd] trick to expand relative file paths to absolute paths - MMc
set cwd [pwd]
cd [file dirname [info script]]
set ::tcltest::testsDirectory [pwd]
cd $cwd

set logfile [file join $::tcltest::temporaryDirectory Log.txt]

puts stdout "Using interp: $shell"
puts stdout "Running tests in working dir: $::tcltest::testsDirectory"
if {[llength $::tcltest::skip] > 0} {
    puts stdout "Skipping tests that match:  $::tcltest::skip"
}
if {[llength $::tcltest::match] > 0} {
    puts stdout "Only running tests that match:  $::tcltest::match"
}

if {[llength $::tcltest::skipFiles] > 0} {
    puts stdout "Skipping test files that match:  $::tcltest::skipFiles"
}
if {[llength $::tcltest::matchFiles] > 0} {
    puts stdout "Only sourcing test files that match:  $::tcltest::matchFiles"
}

set timeCmd {clock format [clock seconds]}
puts stdout "Tests began at [eval $timeCmd]"

# source each of the specified tests
foreach file [lsort [::tcltest::getMatchingFiles]] {
    set tail [file tail $file]
    puts stdout $tail

    # Change to the tests directory so the value of the following
    # variable is set correctly when we spawn the child test processes

    cd $::tcltest::testsDirectory
    set cmd [concat [list | $shell $file] [split $argv] \
	    [list -outfile $logfile]]
    if {[catch {
	set pipeFd [open $cmd "r"] 
	while {[gets $pipeFd line] >= 0} {
	    puts $::tcltest::outputChannel $line
	}
	close $pipeFd
    } msg]} {
	# Print results to ::tcltest::outputChannel.
	puts $::tcltest::outputChannel $msg
    }

    # Now concatenate the temporary log file to
    # ::tcltest::outputChannel 
    if {[catch {
	set fd [open $logfile "r"]
	while {![eof $fd]} {
	    gets $fd line
	    if {![eof $fd]} {
		if {[regexp {^([^:]+):\tTotal\t([0-9]+)\tPassed\t([0-9]+)\tSkipped\t([0-9]+)\tFailed\t([0-9]+)} $line null testFile Total Passed Skipped Failed]} {
		    foreach index [list "Total" "Passed" "Skipped" \
			    "Failed"] {
			incr ::tcltest::numTests($index) [set $index]
		    }
		    incr ::tcltest::numTestFiles
		    if {$Failed > 0} {
			lappend ::tcltest::failFiles $testFile
		    }
		}
		puts $::tcltest::outputChannel $line
	    }
	}
	close $fd
    } msg]} {
	puts $::tcltest::outputChannel $msg
    }
}

set numFailures [llength $::tcltest::failFiles]

# cleanup
puts stdout "\nTests ended at [eval $timeCmd]"
::tcltest::cleanupTests 1

if {$numFailures > 0} {
    return -code error -errorcode $numFailures \
	    -errorinfo "Found $numFailures test file failures"
} else {
    return
}
exit