1 |
< |
# $MirOS: src/bin/mksh/check.pl,v 1.37 2014/08/19 07:43:32 tg Exp $ |
1 |
> |
# $MirOS: src/bin/mksh/check.pl,v 1.49 2017/05/05 21:17:31 tg Exp $ |
2 |
|
# $OpenBSD: th,v 1.1 2013/12/02 20:39:44 millert Exp $ |
3 |
|
#- |
4 |
|
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011, |
5 |
< |
# 2012, 2013, 2014 |
6 |
< |
# Thorsten Glaser <tg@mirbsd.org> |
5 |
> |
# 2012, 2013, 2014, 2015, 2017 |
6 |
> |
# mirabilos <m@mirbsd.org> |
7 |
|
# |
8 |
|
# Provided that these terms and disclaimer and all copyright notices |
9 |
|
# are retained or reproduced in an accompanying document, permission |
73 |
|
# the following minimal environment: |
74 |
|
# HOME, LD_LIBRARY_PATH, LOCPATH, |
75 |
|
# LOGNAME, PATH, SHELL, UNIXMODE, |
76 |
< |
# USER |
76 |
> |
# UNIXROOT, USER |
77 |
|
# (values taken from the environment of |
78 |
|
# the test harness). |
79 |
|
# CYGWIN is set to nodosfilewarning. |
80 |
|
# ENV is set to /nonexistant. |
81 |
|
# __progname is set to the -p argument. |
82 |
|
# __perlname is set to $^X (perlexe). |
83 |
+ |
# @utflocale@ is substituted from -U. |
84 |
|
# file-setup mps Used to create files, directories |
85 |
|
# and symlinks. First word is either |
86 |
|
# file, dir or symlink; second word is |
153 |
|
# p tag takes parameters (used with m). |
154 |
|
# s tag can be used several times. |
155 |
|
|
156 |
+ |
# require Config only if it exists |
157 |
|
# pull EINTR from POSIX.pm or Errno.pm if they exist |
158 |
|
# otherwise just skip it |
159 |
|
BEGIN { |
160 |
+ |
eval { |
161 |
+ |
require Config; |
162 |
+ |
import Config; |
163 |
+ |
1; |
164 |
+ |
}; |
165 |
|
$EINTR = 0; |
166 |
|
eval { |
167 |
|
require POSIX; |
178 |
|
}; |
179 |
|
|
180 |
|
use Getopt::Std; |
174 |
– |
use Config; |
181 |
|
|
182 |
|
$os = defined $^O ? $^O : 'unknown'; |
183 |
|
|
185 |
|
|
186 |
|
$Usage = <<EOF ; |
187 |
|
Usage: $prog [-Pv] [-C cat] [-e e=v] [-p prog] [-s fn] [-T dir] \ |
188 |
< |
[-t tmo] name ... |
188 |
> |
[-t tmo] [-U lcl] name ... |
189 |
|
-C c Specify the comma separated list of categories the program |
190 |
|
belongs to (see category field). |
191 |
|
-e e=v Set the environment variable e to v for all tests |
198 |
|
scaned for test files (which end in .t). |
199 |
|
-T dir Use dir instead of /tmp to hold temporary files |
200 |
|
-t t Use t as default time limit for tests (default is unlimited) |
201 |
+ |
-U lcl Use lcl as UTF-8 locale (e.g. C.UTF-8) instead of the default |
202 |
|
-v Verbose mode: print reason test failed. |
203 |
|
name specifies the name of the test(s) to run; if none are |
204 |
|
specified, all tests are run. |
247 |
|
|
248 |
|
%known_tests = (); |
249 |
|
|
250 |
< |
if (!getopts('C:e:Pp:s:T:t:v')) { |
250 |
> |
if (!getopts('C:Ee:Pp:s:T:t:U:v')) { |
251 |
|
print STDERR $Usage; |
252 |
|
exit 1; |
253 |
|
} |
256 |
|
die "$prog: no test set specified (use -s)\n" if !defined $opt_s; |
257 |
|
$test_prog = $opt_p; |
258 |
|
$verbose = defined $opt_v && $opt_v; |
259 |
+ |
$is_ebcdic = defined $opt_E && $opt_E; |
260 |
|
$test_set = $opt_s; |
261 |
|
$temp_base = $opt_T || "/tmp"; |
262 |
+ |
$utflocale = $opt_U || (($os eq "hpux") ? "en_US.utf8" : "en_US.UTF-8"); |
263 |
|
if (defined $opt_t) { |
264 |
|
die "$prog: bad -t argument (should be number > 0): $opt_t\n" |
265 |
|
if $opt_t !~ /^\d+$/ || $opt_t <= 0; |
267 |
|
} |
268 |
|
$program_kludge = defined $opt_P ? $opt_P : 0; |
269 |
|
|
270 |
+ |
if ($is_ebcdic) { |
271 |
+ |
$categories{'shell:ebcdic-yes'} = 1; |
272 |
+ |
$categories{'shell:ascii-no'} = 1; |
273 |
+ |
} else { |
274 |
+ |
$categories{'shell:ebcdic-no'} = 1; |
275 |
+ |
$categories{'shell:ascii-yes'} = 1; |
276 |
+ |
} |
277 |
+ |
|
278 |
|
if (defined $opt_C) { |
279 |
|
foreach $c (split(',', $opt_C)) { |
280 |
|
$c =~ s/\s+//; |
292 |
|
# Set up a very minimal environment |
293 |
|
%new_env = (); |
294 |
|
foreach $env (('HOME', 'LD_LIBRARY_PATH', 'LOCPATH', 'LOGNAME', |
295 |
< |
'PATH', 'SHELL', 'UNIXMODE', 'USER')) { |
295 |
> |
'PATH', 'SHELL', 'UNIXMODE', 'UNIXROOT', 'USER')) { |
296 |
|
$new_env{$env} = $ENV{$env} if defined $ENV{$env}; |
297 |
|
} |
298 |
|
$new_env{'CYGWIN'} = 'nodosfilewarning'; |
299 |
|
$new_env{'ENV'} = '/nonexistant'; |
300 |
+ |
|
301 |
|
if (($os eq 'VMS') || ($Config{perlpath} =~ m/$Config{_exe}$/i)) { |
302 |
|
$new_env{'__perlname'} = $Config{perlpath}; |
303 |
|
} else { |
304 |
|
$new_env{'__perlname'} = $Config{perlpath} . $Config{_exe}; |
305 |
|
} |
306 |
+ |
$new_env{'__perlname'} = $^X if ($new_env{'__perlname'} eq '') and -f $^X and -x $^X; |
307 |
+ |
if ($new_env{'__perlname'} eq '') { |
308 |
+ |
foreach $pathelt (split /:/,$ENV{'PATH'}) { |
309 |
+ |
chomp($pathelt = `pwd`) if $pathelt eq ''; |
310 |
+ |
my $x = $pathelt . '/' . $^X; |
311 |
+ |
next unless -f $x and -x $x; |
312 |
+ |
$new_env{'__perlname'} = $x; |
313 |
+ |
last; |
314 |
+ |
} |
315 |
+ |
} |
316 |
+ |
$new_env{'__perlname'} = $^X if ($new_env{'__perlname'} eq ''); |
317 |
+ |
|
318 |
|
if (defined $opt_e) { |
319 |
|
# XXX need a way to allow many -e arguments... |
320 |
|
if ($opt_e =~ /^([a-zA-Z_]\w*)(|=(.*))$/) { |
342 |
|
die "$prog: couldn't cd to $pwd - $!\n" if !chdir($pwd); |
343 |
|
|
344 |
|
if (!$program_kludge) { |
345 |
< |
$test_prog = "$pwd/$test_prog" if substr($test_prog, 0, 1) ne '/'; |
345 |
> |
$test_prog = "$pwd/$test_prog" if (substr($test_prog, 0, 1) ne '/') && |
346 |
> |
($os ne 'os2' || substr($test_prog, 1, 1) ne ':'); |
347 |
|
die "$prog: $test_prog is not executable - bye\n" |
348 |
< |
if (! -x $test_prog && $os ne 'os2'); |
348 |
> |
if (! -x $test_prog && $os ne 'os2'); |
349 |
|
} |
350 |
|
|
351 |
|
@trap_sigs = ('TERM', 'QUIT', 'INT', 'PIPE', 'HUP'); |
599 |
|
} |
600 |
|
push(@argv, $temps) if defined $test{'script'}; |
601 |
|
|
602 |
< |
#XXX realpathise, use which/whence -p, or sth. like that |
602 |
> |
#XXX realpathise, use command -v/whence -p/which, or sth. like that |
603 |
|
#XXX if !$program_kludge, we get by with not doing it for now tho |
604 |
|
$new_env{'__progname'} = $argv[0]; |
605 |
|
|
894 |
|
$char = 1; |
895 |
|
} |
896 |
|
} |
897 |
< |
return "first difference: line $lineno, char $char (wanted '" |
898 |
< |
. &format_char($ce) . "', got '" |
868 |
< |
. &format_char($cg) . "'"; |
897 |
> |
return "first difference: line $lineno, char $char (wanted " . |
898 |
> |
&format_char($ce) . ", got " . &format_char($cg); |
899 |
|
} |
900 |
|
|
901 |
|
sub |
902 |
|
format_char |
903 |
|
{ |
904 |
< |
local($ch, $s); |
904 |
> |
local($ch, $s, $q); |
905 |
|
|
906 |
|
$ch = ord($_[0]); |
907 |
+ |
$q = "'"; |
908 |
+ |
|
909 |
+ |
if ($is_ebcdic) { |
910 |
+ |
if ($ch == 0x15) { |
911 |
+ |
return $q . '\n' . $q; |
912 |
+ |
} elsif ($ch == 0x16) { |
913 |
+ |
return $q . '\b' . $q; |
914 |
+ |
} elsif ($ch == 0x05) { |
915 |
+ |
return $q . '\t' . $q; |
916 |
+ |
} elsif ($ch < 64 || $ch == 255) { |
917 |
+ |
return sprintf("X'%02X'", $ch); |
918 |
+ |
} |
919 |
+ |
return sprintf("'%c' (X'%02X')", $ch, $ch); |
920 |
+ |
} |
921 |
+ |
|
922 |
+ |
$s = sprintf("0x%02X (", $ch); |
923 |
|
if ($ch == 10) { |
924 |
< |
return '\n'; |
924 |
> |
return $s . $q . '\n' . $q . ')'; |
925 |
|
} elsif ($ch == 13) { |
926 |
< |
return '\r'; |
926 |
> |
return $s . $q . '\r' . $q . ')'; |
927 |
|
} elsif ($ch == 8) { |
928 |
< |
return '\b'; |
928 |
> |
return $s . $q . '\b' . $q . ')'; |
929 |
|
} elsif ($ch == 9) { |
930 |
< |
return '\t'; |
930 |
> |
return $s . $q . '\t' . $q . ')'; |
931 |
|
} elsif ($ch > 127) { |
932 |
< |
$ch -= 127; |
933 |
< |
$s = "M-"; |
888 |
< |
} else { |
889 |
< |
$s = ''; |
932 |
> |
$ch -= 128; |
933 |
> |
$s .= "M-"; |
934 |
|
} |
935 |
|
if ($ch < 32) { |
936 |
< |
$s .= '^'; |
893 |
< |
$ch += ord('@'); |
936 |
> |
return sprintf("%s^%c)", $s, $ch + ord('@')); |
937 |
|
} elsif ($ch == 127) { |
938 |
< |
return $s . "^?"; |
938 |
> |
return $s . "^?)"; |
939 |
|
} |
940 |
< |
return $s . sprintf("%c", $ch); |
940 |
> |
return sprintf("%s'%c')", $s, $ch); |
941 |
|
} |
942 |
|
|
943 |
|
sub |
1199 |
|
print STDERR "$prog:$test{':long-name'}: env-setup field doesn't start and end with the same character\n"; |
1200 |
|
return undef; |
1201 |
|
} |
1202 |
+ |
|
1203 |
+ |
$test{'env-setup'} =~ s/\@utflocale\@/$utflocale/g; |
1204 |
|
} |
1205 |
|
if (defined $test{'expected-exit'}) { |
1206 |
|
local($val) = $test{'expected-exit'}; |
1210 |
|
print STDERR "$prog:$test{':long-name'}: expected-exit value $val not in 0..255\n"; |
1211 |
|
return undef; |
1212 |
|
} |
1213 |
< |
} elsif ($val !~ /^([\s<>+-=*%\/&|!()]|\b[wse]\b|\bSIG[A-Z][A-Z0-9]*\b)+$/) { |
1213 |
> |
} elsif ($val !~ /^([\s\d<>+=*%\/&|!()-]|\b[wse]\b|\bSIG[A-Z][A-Z0-9]*\b)+$/) { |
1214 |
|
print STDERR "$prog:$test{':long-name'}: bad expected-exit expression: $val\n"; |
1215 |
|
return undef; |
1216 |
|
} |