summaryrefslogtreecommitdiff
path: root/sys/src/cmd/git/test
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2023-02-19 20:44:56 -0500
committerOri Bernstein <ori@eigenstate.org>2023-02-19 20:44:56 -0500
commit31913a8524edf97ad79f9f895d6ac5761b9b2fd7 (patch)
treecc695a76c4a41527eb510c7c9462f059af652636 /sys/src/cmd/git/test
parentc3ba64f6935322f09b6de5c2285544fd471c605d (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/git/test')
-rw-r--r--sys/src/cmd/git/test/add.expected9
-rwxr-xr-xsys/src/cmd/git/test/add.rc34
-rwxr-xr-xsys/src/cmd/git/test/basic.rc67
-rwxr-xr-xsys/src/cmd/git/test/export.rc40
-rwxr-xr-xsys/src/cmd/git/test/lca.rc68
-rwxr-xr-xsys/src/cmd/git/test/merge.rc92
-rw-r--r--sys/src/cmd/git/test/mkfile11
-rwxr-xr-xsys/src/cmd/git/test/range.rc75
-rwxr-xr-xsys/src/cmd/git/test/util.rc17
9 files changed, 413 insertions, 0 deletions
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}^/..}