2 # Copyright (C) 2005-2008, The Perl Foundation.
9 # the directory to put the tests in
19 our ( $opt_u, $opt_h, $opt_c );
28 Run the tests from the Tcl distribution. This script will download
29 the tests from the Tcl CVS repository, change them slightly to use
30 our C<Test::More> like suite so we can then use prove to report the
35 The need for this script. Eventually use tcltest.tcl
41 -c Convert the .test files to .t files
42 -u Update the tests from CVS.
52 usage() and exit if $opt_h;
53 checkout_tests() and convert_tests() if not -d $DIR;
54 update_tests() and convert_tests() if $opt_u;
55 convert_tests() if $opt_c;
56 return run_tests( grep { -f $_ } @ARGV );
62 ## Convert the tests to a usable form.
65 print "Converting tests\n";
66 my @files = glob( File::Spec->catfile( $DIR, '*.test' ) );
67 for my $file (@files) {
68 my $test = substr $file, 0, -3;
70 # parrot's getopt dislikes filenames with - in them.
72 system("rm $test") if -e $test;
74 open my $ffh, '<', $file;
75 my $test_src = extract_tests(
76 do { local $/ = undef; <$ffh> }
80 warn "Extracting tests for $file\n";
81 open my $tfh, '>>', $test;
82 print {$tfh} $test_src;
90 ## Checkout the tests from CVS into $DIR.
93 print "Checking out tests from CVS\n";
95 my $tag = 'core-8-5-2'; # For the version we're targeting.
98 'cvs -z3 -d :pserver:anonymous:\@tcl.cvs.sourceforge.net:'
99 . "/cvsroot/tcl co -d $DIR -r $tag tcl/tests";
100 my $rc = system $command;
102 return ( $rc == 0 ); # just care if it failed, not how
106 ## my $var = choose(@vars)
108 ## Select the first defined variable.
112 return $_ if defined $_;
118 ## %tests = extract_tests($string)
120 ## Extract the tests from the .test file.
121 ## (test_name => [ $expl, $source, $out ])
125 my ($source) = shift;
127 # This is a bit unweildy.
131 if {[lsearch [namespace children] ::tcltest] == -1} {
132 package require tcltest
133 namespace import -force ::tcltest::*
137 package require tcltest 2
138 namespace import -force ::tcltest::*
141 if {[lsearch [namespace children] ::tcltest] == -1} {
142 package require tcltest 2
143 namespace import -force ::tcltest::*
147 if {[catch {package require tcltest 2.1}]} {
148 puts stderr "Skipping tests in [info script]. tcltest 2.1 required."
153 if {[lsearch [namespace children] ::tcltest] == -1} {
154 package require tcltest 2.1
155 namespace import -force ::tcltest::*
159 ::tcltest::cleanupTests
167 ::tcltest::cleanupTests
171 ::tcltest::cleanupTests
177 foreach my $remove (@removes) {
178 $source =~ s/\Q$remove\E//xms;
181 $source = <<'END_SHEBANG' . $source . <<'END_CLEANUP';
184 # the following lines re-execute this as a tcl script
185 # the \ at the end of these lines makes them a comment in tcl \
186 use lib qw(languages/tcl/lib tcl/lib lib ../lib ../../lib); # \
190 source lib
/test_more
.tcl
205 my (@files) = @_ ?
@_ : glob File
::Spec
->catfile( $DIR, '*.t' );
208 return runtests
(@files);
216 ## my $string = unescape( $original )
218 ## Unescape backslashes from a Tcl string.
222 return if not $string;
224 $string =~ s/\\([^abfnrtvoxu])/$1/g;
235 print "Updating tests from CVS\n";
236 system "(cd $DIR && cvs -Q up *.test)";
244 ## Print the usage message.
248 Usage: tcl-test.pl [-cu]
249 -c Convert the .test files to .t files
250 -u Update the tests from CVS.
258 # cperl-indent-level: 4
261 # vim: expandtab shiftwidth=4: