- Made runtest "use strict".
[wine] / programs / winetest / runtest
1 #!/usr/bin/perl
2 #
3 # Wrapper script to run tests from inside the Wine tree
4 #
5 # Usage: runtest [options] input_file [perl_args...]
6 #
7
8 use strict;
9
10 sub usage
11 {
12     print STDERR <<EOF;
13
14 Usage: $0 [options] input_file [perl_args...]
15
16 Options:
17     -q       quiet mode
18     -v       verbose mode (can be specified multiple times)
19     -I dir   prepend dir to Perl include path
20     -P name  set the current platform name
21     -M names set the module names to be tested
22     -T dir   set Wine tree top directory (autodetected if not specified)
23
24 EOF
25     exit 1;
26 }
27
28 # default values
29 my $platform = $ENV{WINETEST_PLATFORM};
30 $ENV{WINETEST_DEBUG} ||= 1;
31
32 my $topobjdir;
33 my $infile;
34 my @include_dirs;
35 my @modules;
36
37 # parse command-line options
38 while ($#ARGV >= 0)
39 {
40     my $arg = shift @ARGV;
41     if ($arg eq "-h") { usage; }
42     if ($arg eq "-q") { $ENV{WINETEST_DEBUG} = 0; next; }
43     if ($arg eq "-v") { $ENV{WINETEST_DEBUG}++; next; }
44     if ($arg eq "-P") { $platform = shift @ARGV; next; }
45     if ($arg eq "-M") { push @modules, split /,/, shift @ARGV; next; }
46     if ($arg eq "-I") { push @include_dirs, shift @ARGV; next; }
47     if ($arg eq "-T")
48     {
49         $topobjdir = shift @ARGV;
50         usage unless (-d $topobjdir);
51         next;
52     }
53     $infile = $arg;
54     last;
55 }
56
57 # we must have found an input file
58 usage unless defined($infile);
59
60 # check/detect topobjdir
61 if (defined($topobjdir))
62 {
63     unless (-f $topobjdir . "/server/wineserver")
64     {
65         printf STDERR "Wrong -T argument, %s/server/wineserver does not exist\n", $topobjdir;
66         usage;
67     }
68 }
69 else  # try to detect it automatically
70 {
71     if (-f "./server/wineserver") { $topobjdir = "."; }
72     elsif (-f "../server/wineserver") { $topobjdir = ".."; }
73     elsif (-f "../../server/wineserver") { $topobjdir = "../.."; }
74     elsif (-f "../../../server/wineserver") { $topobjdir = "../../.."; }
75 }
76
77 # set environment variables needed for Wine
78 if (defined($topobjdir))
79 {
80     chop($topobjdir = `cd $topobjdir && pwd`);
81     $ENV{LD_LIBRARY_PATH} = $topobjdir . "/dlls:" . $topobjdir . ":" . $ENV{LD_LIBRARY_PATH};
82     $ENV{WINESERVER} ||= $topobjdir . "/server/wineserver";
83     $ENV{WINELOADER} ||= $topobjdir . "/wine";
84     $ENV{WINETEST_PLATFORM} = $platform || "wine";
85 }
86 else
87 {
88     $ENV{WINETEST_PLATFORM} = $platform || "windows";
89 }
90
91 # check for include/ dir in script source directory and append it to search path
92 my $basedir = $0;
93 if ($basedir =~ /\//) { $basedir =~ s!/[^/]+$!!; }
94 else { $basedir = "."; }
95 if (-d $basedir . "/include") { push @include_dirs, $basedir . "/include"; }
96
97 $ENV{PERL5LIB} = join( ":", @include_dirs, split( ":", $ENV{PERL5LIB} ) );
98 if (@modules)
99 {
100     if (defined($ENV{WINEOPTIONS})) { $ENV{WINEOPTIONS} .= " "; }
101     $ENV{WINEOPTIONS} .= "--dll " . join(',',@modules) . "=b";
102 }
103
104 # and now exec winetest
105 if (defined($topobjdir))
106 {
107     exec $topobjdir . "/programs/winetest/winetest", $infile, @ARGV;
108 }
109 exec "winetest", $infile, @ARGV;
110 print STDERR "Could not exec winetest\n";