### SPAR <http://www.cpan.org/scripts/>
### 5 644 1236528312 1380446609 hint
This tests links and symbolic links, among other things. If your file
system doesn't support either or both of these, you can try running
this test with a workaround that consists in setting the environment
variable MAKEPP_LN_CP to 1, 2 or 3. If you want to use the &ln builtin
later on, always set it!
### 192 421 1162935563 1404420982 RootMakeppfile
#
# This file tests the builtin commands.
#
# Test &rm by specifying dirs first and deleting answers for files we never create
$(phony all): a b c \
dir2/c dir2/d dir2/subdir/c dir2/subdir/d dir2/subdir/d1 install_log \
c[au]t.out echo.out sed.out expr.out grep.out sort.out template.out uniq.out uc.out \
preprocess.out
&rm -fv bogus answers/bogus answers/bogus/subdir answers/bogus/file answers/bogus/subdir/file
IGNINST =
ifperl ((stat 'RootMakeppfile')[2] & 01777) != 0421
CHMOD = @&echo chmod not working, //server/share?
CHMODTEST =
perl { unlink 'answers/install_log' }
ifnsys cygwin
IGNINST = - # Because &install fails if chmod() does
endif
else
CHMOD = &chmod
CHMODTEST = perl { ((stat 'b')[2] & 0777) == 0664 && ((stat 'c')[2] & 0777) == 0750 or die }
endif
# Test comment on same line and &touch
a b:
&touch -v $(outputs) # tab comment
$(CHMOD) -v 664 $(outputs) # space comment
# Test that &ln -f removes an empty dir and &chmod
c: dir1/c b
&ln -v --force $(input) .
&ln -fv RootMakeppfile dir1
$(CHMOD) 750 c
$(CHMODTEST)
# Test &mkdir -p implicitly also making parent and -A
dir2/subdir dir2:
&echo -o $(mktemp) -- -vpfm750
&mkdir -A $(mktemp /) $(output)
# Test &ln
dir2/c: dir1/c dir2
&ln -v $(input) $(dir $(output))
# Test &ln -s
dir2/d: dir1/d dir2
&ln --verbose --symbolic ../$(input) $(output)
# Test &ln -r
dir2/subdir/c dir2/subdir/d: dir1/c dir1/d dir2
&ln --verbose --resolve $(wordlist 1, 2, $(inputs)) $(dir $(output))
# Test &ln -r with short opts
dir2/subdir/d1: dir1/d dir2
&ln -vr $(input) $(output)
# Test &sed and -r0
# helper variable for sed
what = just
%.out: %.in uniq.in
&perl -r0 'print tr/a-e//, ":"' $(inputs) --output=$(output)
&perl 'print "$$.\n"' $(input) --output=>>$(output)
&sed -v s/$$what/only/o $(input) --output=>>$(output)
&sed -v 'chomp; $$_ .= "|" . reverse . "\n"' -o +<$(output)
# Test complicated variant of &cat with missing newline and multi line file.
cat.out: sed.in uniq.in
&cat --sync-lines $(inputs 1 2 1) -o $(output)
# Test various variants of &cut
cut.out: cut.in
&cut -vf1..-2 -d\ $(input) -o $(output)
&cut -vmp '%s\0%3s\0%2s\n' -f1,3,-1 -d\ $(input) -o >>$(output)
&cut -vmf16 -d\ $(input) -o >>$(output)
&cut -vf1 -sdf $(input) -o >>$(output)
&cut -vc0,1,4..6,11..-1 $(input) -o >>$(output)
&cut -vl1,4,6..-5 $(input) -o >>$(output)
&cut -vSmf1 -dF $(input) -o >>$(output)
&cut -vSl1,-2 $(input) uniq.in -o >>$(output)
# Test various variants of &echo and its siblings
echo.out:
&echo -o $(output) - -- no options - -n -o $(output)
&echo -nE aa\\tbb \# no comment! -o >>$(output)
# NUL is the only code portable to EBCDIC
&echo 'aa\tbb\x00cc\x{0000}dd\000ee' -o >>$(output)
&printf -E '%03d\t%02.2f:%s:' 5 5 '\123' -o >>$(output)
&printf '%03d\t%02.2f:%s:\n' 5 5 '\123' -o >>$(output)
ifnsys MSWin*
&yes Hi there! -o '| read x; echo $$x >>$(output)'
&yes -o '| read x; read y; echo $$x $$y >>$(output)'
else # Complex Shell command not available on native Windows.
&echo 'Hi there!\ny y' -o >>$(output)
endif
# Test arithmetic, logical and string &expr
expr.out:
-&expr -n 8 - 3 * 2 - 2 -o $(output)
&expr 8 - 3 * 2 > 1 && "'joy'" || \'sorrow\' -o >>$(output)
# Test various variants of &grep
sub choose_a { /a/ }
grep.out grep.o grep.ou: grep.in
&grep --separator=, /a/ grep.in -o grep.o -w grep.waste
&grep -co '>>grep.o' /a/ template.tmpl
&grep --vice-versa -s, /a/ grep.in -o '>>grep.o'
&grep -r3 /a/ grep.in -o '>>grep.o'
&grep -vco '>>grep.o' &choose_a template.tmpl
&grep -l /[Jj]ust/ RootMakeppfile sed.in template.tmpl -o '>>grep.o'
&echo -o '>>grep.o'
&grep -vl /[Jj]ust/ RootMakeppfile sed.in template.tmpl -o '>>grep.o'
&echo -o '>>grep.o'
&grep -vvl /[Jj]ust/ RootMakeppfile grep.in template.tmpl uniq.in -o '>>grep.o'
&cp -vfl grep.o grep.ou
&cp -v grep.ou grep.ou1
&mv -v grep.ou1 $(output)
# Test &sort
perl { sub transform { $_ = ((split)[1] || '')."\0$_" } sub detransform { (split "\0")[1] }}
sort.out: template.tmpl
ifperl 'a' lt 'A' # Ebcdic, sorts differently
&cp -l answers/sort.out .
else
&sort $(input) -o $(output)
&echo + -o >>$(output)
&sort --compare '$$b cmp $$a' $(input) -o >>$(output)
&echo + -o >>$(output)
&sort -t '[lc, $$_]' -c '$$a->[0] cmp $$b->[0]' -d '$$_->[1]' $(input) -o >>$(output)
&echo + -o >>$(output)
&sort -t &transform -d &detransform $(input) -o >>$(output)
&echo +++ -o >>$(output)
&sort --uniq $(input) $(input) -o >>$(output)
&echo + -o >>$(output)
&sort --unique --compare '$$b cmp $$a' $(input) $(input) -o >>$(output)
&echo + -o >>$(output)
&sort -ut '[lc, $$_]' -c '$$a->[0] cmp $$b->[0]' -d '$$_->[1]' $(input) $(input) -o >>$(output)
&echo + -o >>$(output)
&sort -urt transform -d detransform $(input) $(input) -o >>$(output)
&echo + -o >>$(output)
&sort -uc 'ord( $$a ) <=> ord $$b' $(input) -o >>$(output)
endif
# Test &template
perl { %hash = (aa => 1, aaa => "1\n2", TITLE => 'Test') }
%.out: title.tmpl %.tmpl template.xml pi.xml
&template -v -o $(output) -h\\%hash THIS=foo THAT=bar:$$1: $(inputs 1 2)
&template -dv --simple=|<|/>| --multiline=|<|>|</|>| -h '+{%hash, bb => 2}' $(input 3) -o >>$(output)
&template --defined --simple='_&(?!#)_;_' --multiline='_<\?_(?=\?>)_\?>_' $(input 4) -o >>$(output)
&template -vS -o >>$(output) -h\\%hash THIS=foo THAT=bar:$$1: $(input 2)
# Test &uniq
# helper function for --compare
sub c0(\$) { substr ${$_[0]}, 0, 1 }
uniq.out: uniq.in sed.in
&uniq $(input) -o $(output)
&uniq -c 'c0( $$a ) ne c0 $$b' $(input) -o >>$(output)
&uniq -S $(inputs 2 1) -o >>$(output)
&uniq -S $(inputs 1 1) -o >>$(output) # Must reemit file name first time.
install_log:
&rm -f .install_log installog
&install --directory --mode=750 dest
$(IGNINST)&install -v --mode=640 grep.in dest
$(IGNINST)&install -vc --log installog --mode=666 sed.in dest/foobar
&sed 's/^[^ ].*/date/; s|`[^`]+(?=/dest)|`...|' .install_log installog -o install_log
&uninstall -v
&uninstall -v installog
@perl { <dest/*> and die "uninstall failed\n" }
# Test own command with frame and loaded fom a module
perl { do './mymodule.pl'; import mymodule 'c_uc' }
uc.out: uniq.in
&uc -v $(input) -o $(output)
preprocess.out: preprocess.test
&preprocess -v v4=foobar e== -h\\%hash preprocess.test -o preprocess.out
&preprocess -va v2=xyz e== preprocess.test -o >>preprocess.out
### 11 644 1141068683 1473530787 mymodule.pl
package mymodule;
require Exporter;
our @ISA = 'Exporter';
our @EXPORT = 'c_uc';
sub c_uc {
local @ARGV = @_;
Mpp::Cmds::frame {
print "\u\L$_" while <>;
} qw(f i I o O r s);
}
### -12 644 1134923188 1134923188 cut.in
! " # $ % & ' ( ) * + , - . /
0 1 2 3 4 5 6 7 8 9 : ; < = > ?
@ A B C D E F G H I J K L M N O
P Q R S T U V W X Y Z [ \ ] ^ _
` a b c d e f g h i j k l m n o
p q r s t u v w x y z { | } ~
!"# $%&' ()*+ ,-./
0123 4567 89:; <=>?
@ABC DEFG HIJK LMNO
PQRS TUVW XYZ[ \]^_
`abc defg hijk lmno
pqrs tuvw xyz{ |}~
### 0 644 1107332258 1105783994 dir2
### 1 644 1107332258 1107331351 grep.in
aha,foo,bar,with a,without
### 2 644 1404420827 1404420827 pi.xml
<?STYLE="background-color: #d8d8e8;"?><?# This tests not getting confused about nested ';' and &#n; is not a comment ?>
<div style=&STYLE;>A</div>
### 22 644 1153676973 1313824017 preprocess.test
# empty & comment
$()
$()# empty & comment not gone
con- \$()
tinuation
no \
continuation
v1 += 5
override v2 := $(v1)
define v3
long var
enddef
$()v4 = 1
show aa $e $(aa); v1 $e $(v1); v2 $e $(v2); v3 $e $(v3); v4 $e $(v4)
$()include plain text
ifeq $(v1),5
-include $( preprocess.test) # Force expand text, which didn't initially work.
endif
### -1 644 1107332258 1105995922 sed.in
just some text
### 7 644 1107332258 1106072810 template.tmpl
Just a silly test to see if @THIS@ and @aaa@
all @@THIS@@ and this@@ before here
@@THAT(stuff)@@
foo bar
goner
@@
gets replaced. 1 + 2 = @{ 1 + 2 }@
### 7 644 1113205406 1113205406 template.xml
<?xml?>
<doc name="foobar">
<aa/><aa=4/> <bb/>
<{ 1 + 2 }/> <aa>
foo bar
</aa> <aa no="go"/>
</doc>
### -6 644 1107332258 1402078423 title.tmpl
@UNDEF@@field=Title@\
@TITLE?=nothing@\
@field@\
@field { ' ' . ($_[0]+1) . " is$_[1]" }@\
@n=0@\
@field(@n@,:)@ @include( dotitle.tmpl )@
### 2 644 1402078420 1402078420 dotitle.tmpl
@TITLE@
--------------------
### 5 644 1112771877 1112771877 uniq.in
aa
aa
b
bb
bcd
### D 755 1107332258 1105873176 c/
### D 755 1107332258 1105741386 dir1/
### 1 644 1107332258 1105741331 dir1/c
c
### 1 644 1107332258 1105741386 dir1/d
d
### D 755 1172254968 1172254974 answers/
### 0 644 1107332258 1105741346 answers/a
### 0 644 1107332258 1105741350 answers/b
### 1 644 1107332258 1105873176 answers/c
c
### -10 644 1191603652 1191603922 answers/cat.out
#line 1 "sed.in"
just some text
#line 1 "uniq.in"
aa
aa
b
bb
bcd
#line 1 "sed.in"
just some text
### 48 644 1134924208 1217791214 answers/cut.out
! " # $ % & ' ( ) * + , - .
1 2 3 4 5 6 7 8 9 : ; < = >
A B C D E F G H I J K L M N
Q R S T U V W X Y Z [ \ ] ^
a b c d e f g h i j k l m n
q r s t u v w x y z { | }
0123 4567 89:; <=>?
@ABC DEFG HIJK LMNO
PQRS TUVW XYZ[ \]^_
`abc defg hijk lmno
pqrs tuvw xyz{ |}~ "