diff options
author | Ori Bernstein <ori@eigenstate.org> | 2023-02-19 20:44:56 -0500 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2023-02-19 20:44:56 -0500 |
commit | 31913a8524edf97ad79f9f895d6ac5761b9b2fd7 (patch) | |
tree | cc695a76c4a41527eb510c7c9462f059af652636 /sys/src/cmd | |
parent | c3ba64f6935322f09b6de5c2285544fd471c605d (diff) |
mkfiles: add 'mk test' support
9front has several tests scattered throughout the source,
as well as more tests in an external 'regress' repository.
Many of these tests are broken, because there is no easy
way to build and track all of them.
This pulls in several tests from different sources, deletes
the broken tests, tests with missing data, and adds a single
command that can be run from the root of the src directory
to test our system.
The hope is that as we develop new code, we add more tests,
and eventually start running the tests on every commit.
Please enter the commit message for your changes. Lines starting
Diffstat (limited to 'sys/src/cmd')
60 files changed, 1702 insertions, 33 deletions
diff --git a/sys/src/cmd/audio/flacdec/mkfile b/sys/src/cmd/audio/flacdec/mkfile index 89340bda7..0c88bed05 100644 --- a/sys/src/cmd/audio/flacdec/mkfile +++ b/sys/src/cmd/audio/flacdec/mkfile @@ -4,7 +4,7 @@ TARGET=flacdec CC=pcc -CFLAGS=-I. -I../libFLAC -I../libFLAC/FLAC -D_POSIX_SOURCE -D_BSD_EXTENSION -DPlan9 -c +CFLAGS=-I. -I../libFLAC -I../libFLAC/FLAC -D_POSIX_SOURCE -D_BSD_EXTENSION -DPlan9 %.$O: %.c $CC $CFLAGS -c $stem.c @@ -19,3 +19,6 @@ clean:V: install:V: $O.$TARGET cp $O.$TARGET $BIN/$TARGET + +test:VQ: + # nothing diff --git a/sys/src/cmd/audio/flacenc/mkfile b/sys/src/cmd/audio/flacenc/mkfile index f8bc3a111..59792f545 100644 --- a/sys/src/cmd/audio/flacenc/mkfile +++ b/sys/src/cmd/audio/flacenc/mkfile @@ -19,3 +19,6 @@ clean:V: install:V: $O.$TARGET cp $O.$TARGET $BIN/$TARGET + +test:VQ: + # nothing diff --git a/sys/src/cmd/audio/mkfile b/sys/src/cmd/audio/mkfile index 9739e1492..5116edca0 100644 --- a/sys/src/cmd/audio/mkfile +++ b/sys/src/cmd/audio/mkfile @@ -60,3 +60,9 @@ safeinstallall:V: cd $i mk clean } + +test:V: + for (i in $DIRS) @{ + cd $i + mk test + } diff --git a/sys/src/cmd/audio/mp3enc/mkfile b/sys/src/cmd/audio/mp3enc/mkfile index 828fb5f57..b005bea67 100644 --- a/sys/src/cmd/audio/mp3enc/mkfile +++ b/sys/src/cmd/audio/mp3enc/mkfile @@ -59,7 +59,3 @@ LDFLAGS= # -p testcase.new.mp3: testcase.wav $O.out $O.out --nores -h testcase.wav testcase.new.mp3 - -test:V: testcase.new.mp3 - cmp -l testcase.new.mp3 testcase.mp3 | wc -l - rm testcase.new.mp3 diff --git a/sys/src/cmd/audio/oggdec/mkfile b/sys/src/cmd/audio/oggdec/mkfile index 04c36366d..e22711d33 100644 --- a/sys/src/cmd/audio/oggdec/mkfile +++ b/sys/src/cmd/audio/oggdec/mkfile @@ -19,3 +19,6 @@ clean:V: install:V: $O.$TARGET cp $O.$TARGET $BIN/$TARGET + +test:VQ: + # nothing diff --git a/sys/src/cmd/audio/oggenc/mkfile b/sys/src/cmd/audio/oggenc/mkfile index 313d57e4a..e2b8a8bd2 100644 --- a/sys/src/cmd/audio/oggenc/mkfile +++ b/sys/src/cmd/audio/oggenc/mkfile @@ -19,3 +19,6 @@ clean:V: install:V: $O.$TARGET cp $O.$TARGET $BIN/$TARGET + +test:VQ: + # nothing diff --git a/sys/src/cmd/bzip2/mkfile b/sys/src/cmd/bzip2/mkfile index b456a1d48..8f2f6d5c3 100644 --- a/sys/src/cmd/bzip2/mkfile +++ b/sys/src/cmd/bzip2/mkfile @@ -18,20 +18,6 @@ BIN=/$objtype/bin CFLAGS=$CFLAGS -p -DPLAN9 -Ilib -test:V: $O.bzip2 $O.bunzip2 - ./$O.bzip2 -1 < sample1.ref > sample1.rb2 - ./$O.bzip2 -2 < sample2.ref > sample2.rb2 - ./$O.bzip2 -3 < sample3.ref > sample3.rb2 - ./$O.bunzip2 < sample1.bz2 > sample1.tst - ./$O.bunzip2 < sample2.bz2 > sample2.tst - ./$O.bunzip2 < sample3.bz2 > sample3.tst - cmp sample1.bz2 sample1.rb2 - cmp sample2.bz2 sample2.rb2 - cmp sample3.bz2 sample3.rb2 - cmp sample1.tst sample1.ref - cmp sample2.tst sample2.ref - cmp sample3.tst sample3.ref - bzip2recover.$O: bzip2recover.c pcc -D_POSIX_SOURCE -D_BSD_EXTENSION -c bzip2recover.c diff --git a/sys/src/cmd/cwfs/mkfile b/sys/src/cmd/cwfs/mkfile index 47b001ae7..670a2ff2d 100644 --- a/sys/src/cmd/cwfs/mkfile +++ b/sys/src/cmd/cwfs/mkfile @@ -13,3 +13,6 @@ cwfs64x.%:V: cd cwfs64x && mk $stem cleanall:V: clean emelie.clean fs64.clean cwfs64.clean cwfs64x.clean + +test:VQ: + # nothing diff --git a/sys/src/cmd/git/add b/sys/src/cmd/git/add index b980d7dc8..b980d7dc8 100644..100755 --- a/sys/src/cmd/git/add +++ b/sys/src/cmd/git/add diff --git a/sys/src/cmd/git/commit b/sys/src/cmd/git/commit index 15f85a504..15f85a504 100644..100755 --- a/sys/src/cmd/git/commit +++ b/sys/src/cmd/git/commit diff --git a/sys/src/cmd/git/compat b/sys/src/cmd/git/compat index 9e08e76db..9e08e76db 100644..100755 --- a/sys/src/cmd/git/compat +++ b/sys/src/cmd/git/compat diff --git a/sys/src/cmd/git/diff b/sys/src/cmd/git/diff index 28e69d660..28e69d660 100644..100755 --- a/sys/src/cmd/git/diff +++ b/sys/src/cmd/git/diff diff --git a/sys/src/cmd/git/import b/sys/src/cmd/git/import index ebb5dbcb6..ebb5dbcb6 100644..100755 --- a/sys/src/cmd/git/import +++ b/sys/src/cmd/git/import diff --git a/sys/src/cmd/git/rebase b/sys/src/cmd/git/rebase index 1eb03fb30..1eb03fb30 100644..100755 --- a/sys/src/cmd/git/rebase +++ b/sys/src/cmd/git/rebase diff --git a/sys/src/cmd/git/revert b/sys/src/cmd/git/revert index 1adb0d2e6..1adb0d2e6 100644..100755 --- a/sys/src/cmd/git/revert +++ b/sys/src/cmd/git/revert diff --git a/sys/src/cmd/git/test/add.expected b/sys/src/cmd/git/test/add.expected new file mode 100644 index 000000000..1b9476225 --- /dev/null +++ b/sys/src/cmd/git/test/add.expected @@ -0,0 +1,9 @@ +A a +A b +A dir/a +A dir/b +A extra/a +A extra/b +A more/a +A more/b +A more/c diff --git a/sys/src/cmd/git/test/add.rc b/sys/src/cmd/git/test/add.rc new file mode 100755 index 000000000..98c00764c --- /dev/null +++ b/sys/src/cmd/git/test/add.rc @@ -0,0 +1,34 @@ +#!/bin/rc + +. util.rc + +rm -fr scratch +mkdir -p scratch/repo + +echo @@ abs paths @@ +@{ + rfork ne + cd scratch/repo + pwd=`{pwd} + $G/init + mkdir dir + mkdir another + mkdir more + mkdir extra + touch a b c + touch dir/^(a b c) + touch another/^(a b c) + touch more/^(a b c) + touch extra/^(a b c) + $G/add a + $G/add $pwd/b + $G/add dir/a + $G/add $pwd/dir/b + $G/add more + @{cd more && $G/add ../extra/a} + @{cd more && $G/add $pwd/extra/b} + $G/$O.fs + $G/$O.walk > ../added +} + +diff -c scratch/added add.expected >/dev/null || die wrong files diff --git a/sys/src/cmd/git/test/basic.rc b/sys/src/cmd/git/test/basic.rc new file mode 100755 index 000000000..875a225cc --- /dev/null +++ b/sys/src/cmd/git/test/basic.rc @@ -0,0 +1,67 @@ +#!/bin/rc + +. util.rc + +wrkdir=`{pwd} +rm -fr scratch +mkdir -p scratch/upstream + +echo @@ version1 @@ +@{ + cd scratch/upstream + q $G/init + echo version1 > file.txt + q $G/add file.txt + q $G/commit -m version1 file.txt +} + +@{ + cd scratch + $G/clone $wrkdir/scratch/upstream downstream +} + +diff -c scratch/upstream/file.txt scratch/downstream/file.txt || die mismatch + +echo @@ version2 @@ +@{ + cd scratch/upstream + echo version2 > file.txt + q $G/commit -m version2 file.txt +} +@{ + cd scratch/downstream + q $G/pull +} +q diff -c scratch/upstream/file.txt scratch/downstream/file.txt || die mismatch + +echo @@ version3 @@ +@{ + cd scratch/upstream + echo version3 > file2.txt + $G/add file2.txt + q $G/commit -m version3 file2.txt +} +@{ + cd scratch/downstream + q $G/pull +} +q diff -c scratch/upstream/file.txt scratch/downstream/file.txt || die mismatch +q diff -c scratch/upstream/file2.txt scratch/downstream/file2.txt || die mismatch + +echo @@ version4 @@ +@{ + cd scratch/upstream + echo version4 > file.txt + $G/rm file2.txt + rm file2.txt + q $G/commit -m version4 file.txt file2.txt +} + +@{ + cd scratch/downstream + q $G/pull +} +q diff -c scratch/upstream/file.txt scratch/downstream/file.txt || die mismatch +! test -e scratch/upstream/file2.txt || die mismatch +! test -e scratch/downstream/file2.txt || die mismatch + diff --git a/sys/src/cmd/git/test/export.rc b/sys/src/cmd/git/test/export.rc new file mode 100755 index 000000000..ecd13df76 --- /dev/null +++ b/sys/src/cmd/git/test/export.rc @@ -0,0 +1,40 @@ +#!/bin/rc + +. util.rc + +rm -fr scratch +mkdir -p scratch +cd scratch + +# setup test repo +@{ + rfork ne + q $G/init a + + cd a + echo hello > a + echo goodbye > b + q $G/add a b + q $G/commit -m v1 . + cd .. + pwd + q $G/clone `{pwd}^/a b +} + +echo @@ export and apply @@ +@{ + rfork ne + @{ + cd b + echo hihi > b + q $G/commit -m export1 b + $G/export > ../export1.patch + } + + @{ + cd a + q $G/import ../export1.patch + } +} + +~ `{cd a && $G/$O.query HEAD} `{cd b && $G/$O.query HEAD} || die 'mismatched export' diff --git a/sys/src/cmd/git/test/lca.rc b/sys/src/cmd/git/test/lca.rc new file mode 100755 index 000000000..7ca1da741 --- /dev/null +++ b/sys/src/cmd/git/test/lca.rc @@ -0,0 +1,68 @@ +#!/bin/rc + +. util.rc + +rm -fr scratch +mkdir -p scratch +cd scratch + +echo @@ test lca @@ +@{ + q $G/init a + + cd a + + echo 'first' > f + q $G/add f + q $G/commit -m base f + r=`{$G/$O.query HEAD} + + echo 0 > f + q $G/commit -m a.0 . + a=`{$G/$O.query HEAD} + + for(i in `{seq 10}){ + echo $i > f + q $G/commit -m a.$i . + } + + q $G/branch -nb $r merge + echo x > f + q $G/commit -m b.0 . + b=`{$G/$O.query HEAD} + + qq $G/merge front + q $G/commit -m merge . + m=`{$G/$O.query HEAD} + +~ `{$G/$O.query $a $m @} $a || die lca a-m +~ `{$G/$O.query $a $b @} $r || die lca a-b +~ `{$G/$O.query $a $r @} $r || die lca a-r +} + +# a +# ↓ +# b→c→d→e→f +# +# date order (oldest to newest): f d c b e a +echo @@ test lca rebase @@ +@{ + q $G/init b + cd b + + touch f + + fn commit { + $G/$O.save -n regress -e regress $* f + } + + f=`{commit -m f -d 1} + e=`{commit -m e -d 5 -p $f} + d=`{commit -m d -d 2 -p $e} + c=`{commit -m c -d 3 -p $d} + b=`{commit -m b -d 4 -p $c} + a=`{commit -m a -d 6 -p $e} + +~ `{$G/$O.query $a $b @} $e || die lca a-b +~ `{$G/$O.query $b $a @} $e || die lca b-a +} diff --git a/sys/src/cmd/git/test/merge.rc b/sys/src/cmd/git/test/merge.rc new file mode 100755 index 000000000..47438f4ad --- /dev/null +++ b/sys/src/cmd/git/test/merge.rc @@ -0,0 +1,92 @@ +#!/bin/rc + +. util.rc + +rm -fr scratch +mkdir -p scratch +cd scratch +c='foo +bar +baz +' + +# setup test repo +@{ + rfork ne + q $G/init a + + cd a + echo hello > a + echo goodbye > b + echo -n $c > c + chmod +x a + q $G/add a b c + q $G/commit -m v1 . + cd .. + pwd + q $G/clone `{pwd}^/a b +} + +echo @@ merge different files @@ +@{ + rfork ne + @{ + cd a + echo x > a + q $G/commit -m diverge1a a + } + @{ + cd b + echo y > b + q $G/commit -m diverge1b b + } + + @{ + cd b + qq $G/pull + $G/merge origin/front || status='' + q $G/commit -m merged . + } +} + +flag +x +~ `{cat b/a} x || die merge 1.a +~ `{cat b/b} y || die merge 1.b +~ `''{cat b/c} $c || die merge 1.c +test -x b/a || die merge preserve exec +! test -x b/b || die merge preserve nonexec b +! test -x b/c || die merge preserve nonexec c + +echo @@ merge concurent edits @@ +@{ + rfork ne + @{ + cd a + chmod -x a + chmod +x b + echo quux >>c + q $G/commit -m diverge2a a b c + } + @{ + cd b + sed s/foo/FOO/ <c >c.new + mv c.new c + q $G/commit -m diverge2b c + + qq $G/pull + qq $G/merge origin/front + q $G/commit -m merge c + } +} + +c='FOO +bar +baz +quux +' +~ `{cat b/a} x || die # commit from a +~ `{cat b/b} y || die # commit from b +~ `''{cat b/c} $c || {diff -u b/c <{echo $c}; die merge 1.c} +! test -x b/a || die merge remove exec +test -x b/b || die merge add exec +! test -x b/c || die merge preserve nonexec c diff --git a/sys/src/cmd/git/test/mkfile b/sys/src/cmd/git/test/mkfile new file mode 100644 index 000000000..88df62585 --- /dev/null +++ b/sys/src/cmd/git/test/mkfile @@ -0,0 +1,11 @@ +</$objtype/mkfile + +TEST=\ + add\ + basic\ + export\ + lca\ + merge\ + range + +</sys/src/cmd/mktest diff --git a/sys/src/cmd/git/test/range.rc b/sys/src/cmd/git/test/range.rc new file mode 100755 index 000000000..6dbb47419 --- /dev/null +++ b/sys/src/cmd/git/test/range.rc @@ -0,0 +1,75 @@ +#!/bin/rc + +. util.rc + +rm -fr scratch +mkdir -p scratch +cd scratch + +fn commit { + $G/$O.save -n regress -e regress $* f +} + +# h→g→f +# ↓ ↓ +# e→d→c→b→a +echo @@ test range @@ +@{ + q $G/init a + cd a + touch f + + a=`{commit -m a} + b=`{commit -m b -p $a} + c=`{commit -m c -p $b} + d=`{commit -m d -p $c} + e=`{commit -m e -p $d} + f=`{commit -m f -p $c} + g=`{commit -m g -p $f} + h=`{commit -m h -p $e -p $g} + map=' + s/^'$a'$/a/ + s/^'$b'$/b/ + s/^'$c'$/c/ + s/^'$d'$/d/ + s/^'$e'$/e/ + s/^'$f'$/f/ + s/^'$g'$/g/ + s/^'$h'$/h/ + ' + + diff -u <{echo d; echo e; echo g; echo h} \ + <{$G/$O.query $f..$h | sed -e $map} || die range +} + +# b +# ↙ ↖ +# f←e←d a +# ↖ ↙ +# c +echo @@ test range 2 @@ +@{ + q $G/init b + cd b + touch f + + a=`{commit -m a} + b=`{commit -m b -p $a} + c=`{commit -m c -p $a} + d=`{commit -m d -p $b -p $c} + e=`{commit -m e -p $d} + f=`{commit -m f -p $e} + map=' + s/^'$a'$/a/ + s/^'$b'$/b/ + s/^'$c'$/c/ + s/^'$d'$/d/ + s/^'$e'$/e/ + s/^'$f'$/f/ + ' + + diff -u <{echo c; echo d; echo e; echo f} \ + <{$G/$O.query $b..$f | sed -e $map} || die range + diff -u <{echo b; echo d; echo e; echo f} \ + <{$G/$O.query $c..$f | sed -e $map} || die range +} diff --git a/sys/src/cmd/git/test/util.rc b/sys/src/cmd/git/test/util.rc new file mode 100755 index 000000000..66bfacb71 --- /dev/null +++ b/sys/src/cmd/git/test/util.rc @@ -0,0 +1,17 @@ +fn q { + {$* > /tmp/out.$pid && rm /tmp/out.$pid} || cat /tmp/out +} +fn qq { + $* >/dev/null >[2]/dev/null +} + +fn die { + st=$status + if(! ~ $st ''){ + *=($* : $st) + echo $"* + exit $"* + } +} + +G=`{cleanname `{pwd}^/..} diff --git a/sys/src/cmd/ktrans/mkfile b/sys/src/cmd/ktrans/mkfile index 1c0973630..9d2555e28 100644 --- a/sys/src/cmd/ktrans/mkfile +++ b/sys/src/cmd/ktrans/mkfile @@ -11,6 +11,3 @@ OFILES=\ $O.test: test.$O $LD $LDFLAGS -o $target $prereq - -test:V: $O.test $O.out - $O.test $O.out diff --git a/sys/src/cmd/mkfile b/sys/src/cmd/mkfile index 383f92653..e7e71e276 100644 --- a/sys/src/cmd/mkfile +++ b/sys/src/cmd/mkfile @@ -72,3 +72,6 @@ clean:V: cleancmds clean.dirs nuke:V: cleancmds nuke.dirs rm -f *.acid + +test:VQ: test.dirs + @{cd test && mk $MKFLAGS test} diff --git a/sys/src/cmd/mklib b/sys/src/cmd/mklib index 3ffbef80b..c5fb3a127 100644 --- a/sys/src/cmd/mklib +++ b/sys/src/cmd/mklib @@ -46,3 +46,9 @@ clean:V: update:V: update $UPDATEFLAGS $UPDATE + +test:VQ: $LIB + if(test -d ./test) + cd test && mk $MKFLAGS test + if not + status=() diff --git a/sys/src/cmd/mkmany b/sys/src/cmd/mkmany index 094e92134..945816880 100644 --- a/sys/src/cmd/mkmany +++ b/sys/src/cmd/mkmany @@ -79,3 +79,10 @@ clean:V: cp $stem.man $MAN/$stem man:V: $MANFILES + +test:VQ: $PROGS + if(test -d ./test) + cd test && mk $MKFLAGS test + if not + status=() + diff --git a/sys/src/cmd/mkone b/sys/src/cmd/mkone index ad0c97901..7e43ec480 100644 --- a/sys/src/cmd/mkone +++ b/sys/src/cmd/mkone @@ -60,3 +60,12 @@ $MAN/%: %.man cp $prereq $target man:V: $MAN/$TARG + +test:QV: $O.out $TESTDEP + if(test -d ./test){ + pwd + @{cd ./test && mk $MKFLAGS test} + } + if not + status=() + diff --git a/sys/src/cmd/mksyslib b/sys/src/cmd/mksyslib index 9457a8417..e4fd720bb 100644 --- a/sys/src/cmd/mksyslib +++ b/sys/src/cmd/mksyslib @@ -41,3 +41,9 @@ nuke:V: update:V: update $UPDATEFLAGS $UPDATE + +test:VQ: + if(test -d ./test) + cd test && mk $MKFLAGS test + if not + status=() diff --git a/sys/src/cmd/mktest b/sys/src/cmd/mktest new file mode 100644 index 000000000..438555132 --- /dev/null +++ b/sys/src/cmd/mktest @@ -0,0 +1,41 @@ +test:VQ: + echo $t + for(t in $TEST) @{ + if(test -d $t) + @{cd $t && mk $MKFLAGS test} + if not + mk $t.test + } + +all:VQ: + # nothing + +%.test:V: $O.% + ./$O.$stem + +%.test:V: %.rc + ./$stem.rc + +%.$O: $HFILES # don't combine with following %.$O rules + +%.$O: %.c + $CC $CFLAGS $stem.c + +%.$O: %.s + $AS $AFLAGS $stem.s + +$O.%:V: %.$O $OFILES $LIB + $LD $LDFLAGS -o $target $prereq + +# [$OS].??* avoids file names like 9.h +nuke:V: + rm -f *.[$OS] y.tab.? lex.yy.c y.debug y.output [$OS].??* *.acid $TARG $CLEANFILES + +clean:V: + for(t in $TEST) + if(test -d $t) + @{cd $t && mk $MKFLAGS clean} + rm -f *.[$OS] *.a[$OS] y.tab.? lex.yy.c y.debug y.output [$OS].??* $TARG $CLEANFILES + +%.clean:V: + rm -f $stem.[$OS] [$OS].$stem $stem.acid $stem diff --git a/sys/src/cmd/nusb/mkfile b/sys/src/cmd/nusb/mkfile index 017a19afc..53672f99c 100644 --- a/sys/src/cmd/nusb/mkfile +++ b/sys/src/cmd/nusb/mkfile @@ -36,3 +36,8 @@ update:V: echo update $i cd $i && mk 'UPDATEFLAGS='$"UPDATEFLAGS update } + +test: + for(d in $DIRS) @{ + cd $d && mk $MKFLAGS test + } diff --git a/sys/src/cmd/postscript/mkfile b/sys/src/cmd/postscript/mkfile index 7b9f4b3c0..a5c2f6cf9 100644 --- a/sys/src/cmd/postscript/mkfile +++ b/sys/src/cmd/postscript/mkfile @@ -48,3 +48,6 @@ $TARGETS:V: cd $i; mk $target } + +test:VQ: + # nothing diff --git a/sys/src/cmd/spell/mkfile b/sys/src/cmd/spell/mkfile index 013a82eda..05eab7047 100644 --- a/sys/src/cmd/spell/mkfile +++ b/sys/src/cmd/spell/mkfile @@ -39,8 +39,3 @@ nuke:V: clean:V: rm -f *.[$OS] [$OS].out [$OS].pcode y.tab.? y.debug y.output $TARG - -test:V: $O.out brspell - time ./$O.out -b -f brspell </dev/null >y - time ./$O.out -b -f brspell <x >z - cmp y z diff --git a/sys/src/cmd/test/date.rc b/sys/src/cmd/test/date.rc new file mode 100755 index 000000000..5499e3f2b --- /dev/null +++ b/sys/src/cmd/test/date.rc @@ -0,0 +1,91 @@ +#!/bin/rc + +rfork en +cat /adm/timezone/GMT > /env/timezone + +nl=' +' + +fn check { + r=`$nl{../$O.seconds $1} + if(! ~ $r $2){ + echo "$"r" + echo "$"2" + echo $status + >[1=2] echo fail: $1: got $r expected $2 + exit 'fail' + } +} + +# examples from manpage, and shuffles +rfork ne +check '23 may 2011' 1306108800 +check 'may 23 2011' 1306108800 +check 'may 2011 23' 1306108800 +check '23 2011 may' 1306108800 +check '2011 may 23' 1306108800 +check '2011 23 may' 1306108800 + +# now with timezones +check '23 may 2011 edt' 1306123200 +check '23 may 2011 gmt' 1306108800 + +# If the tz is present, the results should stay +# the same if we change zones. +@{ + rfork en + cat /adm/timezone/US_Pacific >/env/timezone + check '23 may 2011 edt' 1306123200 + check '23 may 2011 gmt' 1306108800 +} + +# now with all variations on times. +check 'may 23 2011 0' 1306108800 +check 'may 23 2011 0:1' 1306108860 +check 'may 23 2011 0:1:2' 1306108862 + +# now with times and timezones +check '23 may 2011 edt' 1306123200 +check '23 may 2011 gmt' 1306108800 + +# formats from ../$O.date(1) +check 'Sun, 14 Jun 2020 22:08:48 -0700' 1592197728 +check 'Sun, 14 Jun 2020 -0700' 1592118000 +check '2020-06-14' 1592092800 +check '2020-06-14T22:14:17-07:00' 1592198057 + +# colloquial american format (eww) +check '06/14/2020' 1592092800 +check '06/01/2020' 1590969600 + + +# Arizona has no DST +@{ + rfork en + cat /adm/timezone/US_Arizona >/env/timezone + check 'Mon, Jun 21 17:38:02 MST 2020' 1592786282 +} + +# CET is a timezone with no hard-coded +# timezone name -- it should round trip +@{ + rfork en + cat /adm/timezone/CET >/env/timezone + tm=1592782682 + ds=`{../$O.date $tm} + r=`{../$O.seconds $"ds} + if(! ~ $tm $r) + >[1=2] echo fail: CET: got $r expected $tm +} + +# The other EST should also round trip. +@{ + rfork en + cat /adm/timezone/Australia_ACT >/env/timezone + tm=1592782682 + ds=`$nl{../$O.date $tm} + r=`$nl{../$O.seconds $ds} + if(! ~ $tm $r) + >[1=2] echo fail: Austraila_ACT: got $r expected $tm +} +exit '' diff --git a/sys/src/cmd/test/mkfile b/sys/src/cmd/test/mkfile new file mode 100644 index 000000000..17719e706 --- /dev/null +++ b/sys/src/cmd/test/mkfile @@ -0,0 +1,9 @@ +</$objtype/mkfile + +TEST=\ + date\ + patch\ + ramfs\ + test\ + +</sys/src/cmd/mktest diff --git a/sys/src/cmd/test/patch/basic.expected b/sys/src/cmd/test/patch/basic.expected new file mode 100644 index 000000000..190423f88 --- /dev/null +++ b/sys/src/cmd/test/patch/basic.expected @@ -0,0 +1,100 @@ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 diff --git a/sys/src/cmd/test/patch/basic.in b/sys/src/cmd/test/patch/basic.in new file mode 100644 index 000000000..1f5a7255c --- /dev/null +++ b/sys/src/cmd/test/patch/basic.in @@ -0,0 +1,93 @@ +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +13 +12 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 diff --git a/sys/src/cmd/test/patch/basic.patch b/sys/src/cmd/test/patch/basic.patch new file mode 100644 index 000000000..326d4cfd0 --- /dev/null +++ b/sys/src/cmd/test/patch/basic.patch @@ -0,0 +1,42 @@ +--- basic.in ++++ basic.out +@@ -1,3 +1,5 @@ ++1 ++2 + 3 + 4 + 5 +@@ -10,8 +12,8 @@ + 12 + 13 + 14 +-13 +-12 ++15 ++16 + 17 + 18 + 19 +@@ -35,6 +37,8 @@ + 37 + 38 + 39 ++40 ++41 + 42 + 43 + 44 +@@ -80,6 +84,7 @@ + 84 + 85 + 86 ++87 + 88 + 89 + 90 +@@ -91,3 +96,5 @@ + 96 + 97 + 98 ++99 ++100 diff --git a/sys/src/cmd/test/patch/create.expected b/sys/src/cmd/test/patch/create.expected new file mode 100644 index 000000000..08fe19ca4 --- /dev/null +++ b/sys/src/cmd/test/patch/create.expected @@ -0,0 +1,12 @@ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 diff --git a/sys/src/cmd/test/patch/create.patch b/sys/src/cmd/test/patch/create.patch new file mode 100644 index 000000000..021c9d7f3 --- /dev/null +++ b/sys/src/cmd/test/patch/create.patch @@ -0,0 +1,15 @@ +--- /dev/null ++++ create.out +@@ -1,0 +1,12 @@ ++1 ++2 ++3 ++4 ++5 ++6 ++7 ++8 ++9 ++10 ++11 ++12 diff --git a/sys/src/cmd/test/patch/delete.expected b/sys/src/cmd/test/patch/delete.expected new file mode 100644 index 000000000..f00c965d8 --- /dev/null +++ b/sys/src/cmd/test/patch/delete.expected @@ -0,0 +1,10 @@ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 diff --git a/sys/src/cmd/test/patch/delete.patch b/sys/src/cmd/test/patch/delete.patch new file mode 100644 index 000000000..2b6c1b5aa --- /dev/null +++ b/sys/src/cmd/test/patch/delete.patch @@ -0,0 +1,15 @@ +--- delete.out ++++ /dev/null +@@ -1,12 +1,0 @@ +-1 +-2 +-3 +-4 +-5 +-6 +-7 +-8 +-9 +-10 +-11 +-12 diff --git a/sys/src/cmd/test/patch/header.expected b/sys/src/cmd/test/patch/header.expected new file mode 100644 index 000000000..190423f88 --- /dev/null +++ b/sys/src/cmd/test/patch/header.expected @@ -0,0 +1,100 @@ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 diff --git a/sys/src/cmd/test/patch/header.in b/sys/src/cmd/test/patch/header.in new file mode 100644 index 000000000..1f5a7255c --- /dev/null +++ b/sys/src/cmd/test/patch/header.in @@ -0,0 +1,93 @@ +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +13 +12 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 diff --git a/sys/src/cmd/test/patch/header.patch b/sys/src/cmd/test/patch/header.patch new file mode 100644 index 000000000..b8ac887aa --- /dev/null +++ b/sys/src/cmd/test/patch/header.patch @@ -0,0 +1,54 @@ +diff should handle headers just fine, so +this file contains a few lines of header +and footer, with a couple of false starts, +consisting of lines starting with +--- some words +but no immediately following ++++ words +lines + +--- header.in ++++ header.out +@@ -1,3 +1,5 @@ ++1 ++2 + 3 + 4 + 5 +@@ -10,8 +12,8 @@ + 12 + 13 + 14 +-13 +-12 ++15 ++16 + 17 + 18 + 19 +@@ -35,6 +37,8 @@ + 37 + 38 + 39 ++40 ++41 + 42 + 43 + 44 +@@ -80,6 +84,7 @@ + 84 + 85 + 86 ++87 + 88 + 89 + 90 +@@ -91,3 +96,5 @@ + 96 + 97 + 98 ++99 ++100 +-- signature footer: should not get picked up +and here is the footer that should +also be ignored. diff --git a/sys/src/cmd/test/patch/mkfile b/sys/src/cmd/test/patch/mkfile new file mode 100644 index 000000000..959f8becb --- /dev/null +++ b/sys/src/cmd/test/patch/mkfile @@ -0,0 +1,5 @@ +</$objtype/mkfile + +TEST=patch + +</sys/src/cmd/mktest diff --git a/sys/src/cmd/test/patch/multifile.patch b/sys/src/cmd/test/patch/multifile.patch new file mode 100644 index 000000000..15abb859c --- /dev/null +++ b/sys/src/cmd/test/patch/multifile.patch @@ -0,0 +1,89 @@ +--- multifile2.in ++++ multifile2.out +@@ -1,21 +1,19 @@ +-77777 + 77778 + 77779 + 77780 + 77781 + 77782 +-77783 +-77784 +-77785 +-77786 +-77787 +-77788 + 77789 ++77788 ++77787 ++77786 ++77785 ++77784 ++77783 + 77790 + 77791 + 77792 + 77793 + 77794 +-77795 + 77796 + 77797 + +of course, each patch can have its own comment +lines mixed in, so we should handle these. +--- multifile1.in ++++ multifile1.out +@@ -14,16 +14,6 @@ + 12 + 17 + 18 +-19 +-20 +-21 +-22 +-23 +-24 +-25 +-26 +-27 +-28 + 29 + 30 + 31 +@@ -32,20 +22,6 @@ + 34 + 35 + 36 +-37 +-38 +-39 +-42 +-43 +-44 +-45 +-46 +-47 +-48 +-49 +-50 +-51 +-52 + 53 + 54 + 55 +@@ -73,11 +49,11 @@ + 77 + 78 + 79 +-80 +-81 +-82 +-83 + 84 ++83 ++82 ++81 ++80 + 85 + 86 + 88 diff --git a/sys/src/cmd/test/patch/multifile1.expected b/sys/src/cmd/test/patch/multifile1.expected new file mode 100644 index 000000000..36218e8fd --- /dev/null +++ b/sys/src/cmd/test/patch/multifile1.expected @@ -0,0 +1,69 @@ +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +13 +12 +17 +18 +29 +30 +31 +32 +33 +34 +35 +36 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +84 +83 +82 +81 +80 +85 +86 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 diff --git a/sys/src/cmd/test/patch/multifile1.in b/sys/src/cmd/test/patch/multifile1.in new file mode 100644 index 000000000..1f5a7255c --- /dev/null +++ b/sys/src/cmd/test/patch/multifile1.in @@ -0,0 +1,93 @@ +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +13 +12 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 diff --git a/sys/src/cmd/test/patch/multifile2.expected b/sys/src/cmd/test/patch/multifile2.expected new file mode 100644 index 000000000..d8c0a5bde --- /dev/null +++ b/sys/src/cmd/test/patch/multifile2.expected @@ -0,0 +1,19 @@ +77778 +77779 +77780 +77781 +77782 +77789 +77788 +77787 +77786 +77785 +77784 +77783 +77790 +77791 +77792 +77793 +77794 +77796 +77797 diff --git a/sys/src/cmd/test/patch/multifile2.in b/sys/src/cmd/test/patch/multifile2.in new file mode 100644 index 000000000..649b7dc6a --- /dev/null +++ b/sys/src/cmd/test/patch/multifile2.in @@ -0,0 +1,21 @@ +77777 +77778 +77779 +77780 +77781 +77782 +77783 +77784 +77785 +77786 +77787 +77788 +77789 +77790 +77791 +77792 +77793 +77794 +77795 +77796 +77797 diff --git a/sys/src/cmd/test/patch/nop.expected b/sys/src/cmd/test/patch/nop.expected new file mode 100644 index 000000000..f00c965d8 --- /dev/null +++ b/sys/src/cmd/test/patch/nop.expected @@ -0,0 +1,10 @@ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 diff --git a/sys/src/cmd/test/patch/patch.rc b/sys/src/cmd/test/patch/patch.rc new file mode 100755 index 000000000..28c222939 --- /dev/null +++ b/sys/src/cmd/test/patch/patch.rc @@ -0,0 +1,39 @@ +#!/bin/rc -e + +fn check{ + if(! cmp $1 $2){ + >[2=1] echo fail: $1 $2 + >[2=1] diff -u $1 $2 + exit mismatch + } + status=() +} + +fn checkpatch{ + rm -f $1.out + ../../$O.patch $1.patch + check $1.out $1.expected +} + +checkpatch basic +checkpatch header +checkpatch create + +seq 12 > delete.out +../../$O.patch delete.patch +test ! -f delete.out + +rm -f multifile^(1 2)^.out +chmod 640 multifile1.in +chmod 400 multifile2.in +../../$O.patch multifile.patch +check multifile1.out multifile1.expected +check multifile2.out multifile2.expected + +if(! ~ `{walk -ex multifile1.out} --rw-r-----) + exit misperm1 +if(! ~ `{walk -ex multifile2.out} --rw-------) + exit misperm2 + + +status=() diff --git a/sys/src/cmd/test/ramfs.rc b/sys/src/cmd/test/ramfs.rc new file mode 100755 index 000000000..9ec516ce2 --- /dev/null +++ b/sys/src/cmd/test/ramfs.rc @@ -0,0 +1,40 @@ +#!/bin/rc +rfork e + +attach=' +Tversion 8192 9P2000 +Rversion 8192 9P2000 +Tattach 1 -1 '^$user^' '''' +Rattach {0,0,d} +Twalk 1 2 +Rwalk +' + +fn assert{ + aux/9pcon -ac '../6.ramfs -i' >/dev/null || exit $status +} + + +# attach +assert <<. +$attach +. + +# create/write/read +assert <<. +$attach +Tcreate 2 testfile 777 2 +Rcreate {1,0,0} 0 +Twrite 2 0 hello +Rwrite 5 +Tclunk 2 +Rclunk +Twalk 1 2 testfile +Rwalk {1,2,0} +Topen 2 0 +Ropen {1,2,0} 0 +Tread 2 0 5 +Rread hello +Tclunk 2 +Rclunk +. diff --git a/sys/src/cmd/test/test.rc b/sys/src/cmd/test/test.rc new file mode 100755 index 000000000..633581d56 --- /dev/null +++ b/sys/src/cmd/test/test.rc @@ -0,0 +1,135 @@ +#!/bin/rc + +rfork e + +ERROR=0 +FAILED=0 + +fn t{ + # $1 -> exit code + # $2 -> $test expression + + expect=$1 + shift + + # check for syntax errors + syntax=`{../$O.test $* >[2=1]} + if(~ $"syntax ''){ + switch($expect){ + case 0 + if(! ../$O.test $*) failed $expect $* + case 1 + if(../$O.test $*) failed $expect $* + } + } + if not + error +} + +fn error{ + echo + echo ' '^$"syntax + ERROR=`{echo $ERROR 1 + p | dc} +} + +fn failed{ + echo -n $1^': test' $*(2-)^'^: failed' + echo ' failed' + FAILED=`{echo $FAILED 1 + p | dc} +} + + +t 0 b '=' b +t 1 b '!=' b +t 0 '(' b '=' b ')' +t 1 ! '(' b '=' b ')' +t 1 ! -f /bin/rc + +t 0 -h '=' -h +t 0 -o '=' -o +#t 1 -f '=' h +t 1 -h '=' f +t 1 -o '=' f +t 1 f '=' -o + +t 0 '(' -h '=' -h ')' +t 1 '(' a '=' -h ')' +#t 1 '(' -f '=' h ')' +t 0 -h '=' -h -o a +t 0 '(' -h '=' -h ')' -o 1 +t 0 -h '=' -h -o -h '=' -h +t 0 '(' -h '=' -h ')' -o '(' -h '=' -h ')' +t 0 roedelheim '=' roedelheim +t 1 potsdam '=' berlin-dahlem + +t 0 -d / +t 0 -d / -a a '!=' b +t 1 -z -z +t 0 -n -n + +t 0 0 +t 0 '(' 0 ')' +t 0 '-E' +t 0 -X -a -X +t 0 -XXX +t 0 '(' -E ')' +t 0 true -o X +t 0 true -o -X +t 0 '(' '(' '(' a '=' a ')' -o 1 ')' -a 1 ')' +#t 1 -h / +t 0 -r / +t 1 -w /dev/zero +t 0 -w /dev/null +t 1 -x /dev/null +t 0 -x /bin/rc +#t 0 -c /dev/null +#t 0 -b /dev/fd0a -o -b /dev/rfd0a -o true +t 0 -f /adm/users +t 0 -s /adm/users + +t 1 ! '(' 700 -le 1000 -a -n 1 -a 20 '=' 20 ')' +t 0 100 -eq 100 +t 0 100 -lt 200 +t 1 1000 -lt 200 +t 0 1000 -gt 200 +t 0 1000 -ge 200 +t 0 1000 -ge 1000 + +t 1 2 -ne 2 +t 0 0 -eq 0 +t 1 -5 -eq 5 +t 0 '(' 0 -eq 0 ')' +t 1 1 -eq 0 -o a '=' a -a 1 -eq 0 -o a '=' aa +#t 0 '" +123 " -eq 123' +#t 1 '"-123 " -gt " -1"' +t 0 123 -gt -123 +t 0 -0 -eq +0 +t 1 +0 -gt 0 +t 0 0 -eq 0 +t 0 0000 -eq -0 +t 0 -1 -gt -2 +t 1 1 -gt 2 +t 1 4294967296 -eq 0 +t 0 12345678901234567890 -eq +12345678901234567890 + +t 1 '' -o '' +t 1 '' -a '' +t 1 a -a '' +t 0 a -a ! '' +t 1 '' +t 0 ! '' + +t 0 1 -eq 1 +t 1 ! 1 -eq 1 +t 0 ! ! 1 -eq 1 +t 1 ! ! ! 1 -eq 1 +t 1 ! '(' XXX -o XXX ')' +t 0 ! '(' ! '(' XXX -o XXX ')' ')' + +if(! ~ $ERROR 0 || ! ~ $FAILED 0){ + echo + echo 'Syntax errors:' $ERROR 'Failed:' $FAILED +} +if(! ~ $ERROR 0 || ! ~ $FAILED 0) + exit 'failures' +exit '' diff --git a/sys/src/cmd/test/zones.rc b/sys/src/cmd/test/zones.rc new file mode 100755 index 000000000..065399d39 --- /dev/null +++ b/sys/src/cmd/test/zones.rc @@ -0,0 +1,19 @@ +#!/bin/rc + +rfork en + +msg=() +for(f in /adm/timezone/*){ + if(! ~ $f /adm/timezone/README){ + cat $f >/env/timezone + tm=`{../6.date -f'WW, DD MMM YYYY hh:mm:ss Z'} + x=`{../6.date -n} + y=`{../6.seconds $"tm} + if(! ~ $x $y){ + echo $f $tm $x $y are not equal + msg=($msg $f) + } + } +} + +exit $"msg diff --git a/sys/src/cmd/upas/binscripts/mkfile b/sys/src/cmd/upas/binscripts/mkfile index 68df60ab6..27aed8493 100644 --- a/sys/src/cmd/upas/binscripts/mkfile +++ b/sys/src/cmd/upas/binscripts/mkfile @@ -27,4 +27,7 @@ nuke:V: $BIN/%: %.rc cp $stem.rc $BIN/$stem +test:VQ: + # nothing + <../mkupas diff --git a/sys/src/cmd/upas/mkfile b/sys/src/cmd/upas/mkfile index 3933b137b..9e60d4cd9 100644 --- a/sys/src/cmd/upas/mkfile +++ b/sys/src/cmd/upas/mkfile @@ -43,3 +43,14 @@ safeinstallall:V: cd $i mk safeinstallall } + +test:V: + for (i in $LIBS) @{ + cd $i + mk test + } + for (i in $PROGS) @{ + cd $i + mk test + } + diff --git a/sys/src/cmd/vl/mkfile b/sys/src/cmd/vl/mkfile index 96a4d7800..ca887fcea 100644 --- a/sys/src/cmd/vl/mkfile +++ b/sys/src/cmd/vl/mkfile @@ -28,9 +28,3 @@ compat.$O: ../cc/compat x:V: $O.out $O.out -la -o/dev/null x.v - -test:V: $O.out - rm -f xxx - mv $O.out xxx - ./xxx $OFILES - cmp $O.out xxx |