1# See the file LICENSE for redistribution information.
2#
3# Copyright (c) 2001,2008 Oracle.  All rights reserved.
4#
5# $Id: shelltest.tcl,v 12.13 2008/01/08 20:58:53 bostic Exp $
6#
7# TEST	scr###
8# TEST	The scr### directories are shell scripts that test a variety of
9# TEST	things, including things about the distribution itself.  These
10# TEST	tests won't run on most systems, so don't even try to run them.
11#
12# shelltest.tcl:
13#	Code to run shell script tests, to incorporate Java, C++,
14#	example compilation, etc. test scripts into the Tcl framework.
15proc shelltest {{ run_one 0 } { xml 0 }} {
16	source ./include.tcl
17	global shelltest_list
18	global xmlshelltest_list
19
20	set SH /bin/sh
21	if { [file executable $SH] != 1 } {
22		puts "Shell tests require valid shell /bin/sh: not found."
23		puts "Skipping shell tests."
24		return 0
25	}
26
27	if { $xml == 1 } {
28		set shelltest_list $xmlshelltest_list
29	}
30
31	if { $run_one == 0 } {
32		puts "Running shell script tests..."
33
34		foreach testpair $shelltest_list {
35			set dir [lindex $testpair 0]
36			set test [lindex $testpair 1]
37
38			env_cleanup $testdir
39			shelltest_copy $test_path/$dir $testdir
40			shelltest_run $SH $dir $test $testdir
41		}
42	} else {
43		set run_one [expr $run_one - 1];
44		set dir [lindex [lindex $shelltest_list $run_one] 0]
45		set test [lindex [lindex $shelltest_list $run_one] 1]
46
47		env_cleanup $testdir
48		shelltest_copy $test_path/$dir $testdir
49		shelltest_run $SH $dir $test $testdir
50	}
51}
52
53proc shelltest_copy { fromdir todir } {
54	set globall [glob $fromdir/*]
55
56	foreach f $globall {
57		file copy $f $todir/
58	}
59}
60
61proc shelltest_run { sh srcdir test testdir } {
62	puts "Running shell script $srcdir ($test)..."
63
64	set ret [catch {exec $sh -c "cd $testdir && sh $test" >&@ stdout} res]
65
66	if { $ret != 0 } {
67		puts "FAIL: shell test $srcdir/$test exited abnormally"
68	}
69}
70
71proc scr001 {} { shelltest 1 }
72proc scr002 {} { shelltest 2 }
73proc scr003 {} { shelltest 3 }
74proc scr004 {} { shelltest 4 }
75proc scr005 {} { shelltest 5 }
76proc scr006 {} { shelltest 6 }
77proc scr007 {} { shelltest 7 }
78proc scr008 {} { shelltest 8 }
79proc scr009 {} { shelltest 9 }
80proc scr010 {} { shelltest 10 }
81proc scr011 {} { shelltest 11 }
82proc scr012 {} { shelltest 12 }
83proc scr013 {} { shelltest 13 }
84proc scr014 {} { shelltest 14 }
85proc scr015 {} { shelltest 15 }
86proc scr016 {} { shelltest 16 }
87proc scr017 {} { shelltest 17 }
88proc scr018 {} { shelltest 18 }
89proc scr019 {} { shelltest 19 }
90proc scr020 {} { shelltest 20 }
91proc scr021 {} { shelltest 21 }
92proc scr022 {} { shelltest 22 }
93proc scr023 {} { shelltest 23 }
94proc scr024 {} { shelltest 24 }
95proc scr025 {} { shelltest 25 }
96proc scr026 {} { shelltest 26 }
97proc scr027 {} { shelltest 27 }
98proc scr028 {} { shelltest 28 }
99proc scr029 {} { shelltest 29 }
100proc scr030 {} { shelltest 30 }
101proc scr031 {} { shelltest 31 }
102proc scr032 {} { shelltest 32 }
103proc scr033 {} { shelltest 33 }
104proc scr034 {} { shelltest 34 }
105proc scr035 {} { shelltest 35 }
106