From 018d44cf4cbf757ba0140ea3370ef0be83d00de4 Mon Sep 17 00:00:00 2001 From: tg Date: Tue, 1 Apr 2008 16:01:45 +0000 Subject: [PATCH] export __progname as environment to the test script, so that the "$0" abuse can stop --- check.pl | 7 ++++++- check.t | 54 +++++++++++++++++++++++++++--------------------------- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/check.pl b/check.pl index a6b00af..84a5955 100644 --- a/check.pl +++ b/check.pl @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.pl,v 1.15 2008/03/23 20:54:29 tg Exp $ +# $MirOS: src/bin/mksh/check.pl,v 1.16 2008/04/01 16:01:45 tg Exp $ # $OpenBSD: th,v 1.12 2005/05/28 04:53:47 millert Exp $ #- # Example test: @@ -57,6 +57,7 @@ # (values taken from the environment of # the test harness). # ENV is set to /nonexistant. +# __progname is set to the -p argument. # file-setup mps Used to create files, directories # and symlinks. First word is either # file, dir or symlink; second word is @@ -493,6 +494,10 @@ run_test } push(@argv, $temps) if defined $test{'script'}; + #XXX realpathise, use which/whence -p, or sth. like that + #XXX if !$program_kludge, we get by with not doing it for now tho + $new_env{'__progname'} = $argv[0]; + # The following doesn't work with perl5... Need to do it explicitly - yuck. #%ENV = %new_env; foreach $k (keys(%ENV)) { diff --git a/check.t b/check.t index 81f972a..7404e21 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.163 2008/03/28 13:46:51 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.164 2008/04/01 16:01:45 tg Exp $ # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ @@ -1454,7 +1454,7 @@ stdin: bar="bar baz" tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<t1 - print '#!'"$0"'\nprint "a=$ENV{FOO}";' >t2 + print '#!'"$__progname"'\nprint "a=$ENV{FOO}";' >t1 + print '#!'"$__progname"'\nprint "a=$ENV{FOO}";' >t2 print '#!/usr/bin/env perl\nprint "a=$ENV{FOO}\n";' >t3 print '#!/usr/bin/env perl\nprint "a=$ENV{FOO}\n";' >t4 chmod +x t? @@ -4261,8 +4261,8 @@ description: Reading the UTF-8 BOM should enable the utf8-hack flag category: pdksh,!dutf stdin: - "$0" -c ':; x=$(set +o); if [[ $x = *utf8* ]]; then print on; else print off; fi' - "$0" -c ':; x=$(set +o); if [[ $x = *utf8* ]]; then print on; else print off; fi' + "$__progname" -c ':; x=$(set +o); if [[ $x = *utf8* ]]; then print on; else print off; fi' + "$__progname" -c ':; x=$(set +o); if [[ $x = *utf8* ]]; then print on; else print off; fi' expected-stdout: off on @@ -4309,7 +4309,7 @@ description: category: disabled arguments: !-o!posix! stdin: - cp "$0" sh + cp "$__progname" sh ./sh -c 'alias; typeset -f' rm -f sh expected-stdout: @@ -4345,7 +4345,7 @@ description: category: pdksh arguments: !-o!posix! stdin: - cp "$0" sh + cp "$__progname" sh ./sh -c 'alias; typeset -f' rm -f sh expected-stdout: @@ -4446,12 +4446,12 @@ description: This is by design. And that some things fail in both. stdin: export x=abcdefghi n=2 - "$0" -c 'print v${x:(n)}x' - "$0" -c 'print w${x: n}x' - "$0" -c 'print x${x:n}x' - "$0" -c 'print y${x:}x' - "$0" -c 'print z${x}x' - "$0" -c 'x=abcdef;y=123;echo ${x:${y:2:1}:2}' >/dev/null 2>&1; print $? + "$__progname" -c 'print v${x:(n)}x' + "$__progname" -c 'print w${x: n}x' + "$__progname" -c 'print x${x:n}x' + "$__progname" -c 'print y${x:}x' + "$__progname" -c 'print z${x}x' + "$__progname" -c 'x=abcdef;y=123;echo ${x:${y:2:1}:2}' >/dev/null 2>&1; print $? expected-stdout: vcdefghix wcdefghix @@ -4482,8 +4482,8 @@ name: dot-needs-argument description: check Debian #415167 solution: '.' without arguments should fail stdin: - "$0" -c . - "$0" -c source + "$__progname" -c . + "$__progname" -c source expected-exit: e != 0 expected-stderr-pattern: /\.: missing argument.*\n.*\.: missing argument/