Follow upstream changes -- rest
[git-darcs-import.git] / tests / shell_harness
blob5a0c48efaa948fe7a97a7ad78c759651ad3d0c04
1 #!/usr/bin/perl -w
3 # Run each of the shell tests, capturing the output, and reporting passed
4 # or failed.
6 use Cwd;
7 use File::Find;
9 # Place to put test output to avoid cluttering test/
10 mkdir 'test_output', 0750;
12 # Override the users default .darcs settings
13 $ENV{HOME} = cwd();
14 mkdir '.darcs';
15 system 'echo ALL --ignore-times >> .darcs/defaults';
16 # Used for finding darcs, but may not be defined by the shell
17 $ENV{PWD} = cwd();
19 # Put the right darcs first in PATH
20 my $darcspath="$ENV{HOME}/..";
21 if ($ENV{DARCS}) {
22 # User has asked for a particular darcs...
23 my $actualdarcs=`which $ENV{DARCS}`;
24 my $darcspath=`dirname "$actualdarcs"`;
26 $ENV{PATH} = "$darcspath:$ENV{PATH}";
28 # Some environment variables can act as defaults that we don't want
29 $ENV{EMAIL} = $ENV{DARCS_EMAIL} = 'tester';
31 # These two environment variables will turn off darcs' "Christmas mode".
32 # It will make the tests run a tad faster, and make darcs' output
33 # independent of the testing systems locale and environment.
34 $ENV{DARCS_DONT_COLOR} = 1;
35 $ENV{DARCS_DONT_ESCAPE_ANYTHING} = 1;
37 my $OK = 1;
38 my @Failures;
39 my @Passes;
41 `which bash`;
42 if( $? != 0 ) {
43 die "You need bash to run the shell tests!"
46 for my $test (@ARGV) {
47 my $test_out = "test_output/$test.out";
49 printf "Running %-40s", "$test ...";
51 my $output = `bash $test 2>&1`;
53 if( $? == 0 ) {
54 push @Passes, $test;
55 print " passed.\n";
57 else {
58 $OK = 0;
59 push @Failures, $test;
61 print " FAILED!\n";
62 print "Output from failed $test:\n$output";
64 # give ourselves write permissions to every file in a tmp dir
65 # (in case a script sets permissions and fails to clean up
66 # after itself)
67 my @tmpdirs = glob("tmp* temp*");
68 if (@tmpdirs > 0) {
69 find (sub { chmod 0755, $_; }, @tmpdirs);
73 my $CWD = cwd();
74 if ($CWD =~ /bugs/ && $#Passes >= 0) {
75 print "Some tests passed:\n";
76 print "\t$_\n" for @Passes;
78 if ($OK) {
79 print "All tests successful!\n";
81 else {
82 print "TESTS FAILED!\n";
83 print "\t$_\n" for @Failures;
86 # Exit with non-zero if anything failed.
87 exit !$OK;