ref: 2605b26a91d34983201cf0e7c643e28eda4cb159
parent: e6baf91cf4a7df1de7d0d64688cf3f5ed0b89d1a
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Feb 19 10:03:15 EST 2018
[tests/ar] Improve -q test This version of the test does a more specific test.
--- /dev/null
+++ b/tests/ar/execute/00-test-q.sh
@@ -1,0 +1,74 @@
+#!/bin/sh
+
+exec >> test.log 2>&1
+
+set -e
+
+TZ=UTC
+tmp1=`mktemp`
+tmp2=`mktemp`
+pwd=$PWD
+
+trap "rm -f $tmp1 $tmp2 file.a;\
+ rm -f *.tst" 0 2 3
+
+###########################################################################
+#Generate a bunch of files that we can use to test -q
+
+for i in `awk 'BEGIN {for (i=0; i <999; ++i) print i}'`
+do
+ echo $i > $i.tst
+done
+
+
+###########################################################################
+#Append all the generated files one by one
+
+rm -f file.a
+ls | grep .tst | sort -n | xargs -n 1 ar -qv file.a
+
+ar -t file.a |
+tee -a test.log |
+awk '$0 != NR-1 ".tst" {
+ printf "bad line %d:%s\n", NR, $0
+ exit 1
+}'
+
+###########################################################################
+#Appenp all the generated files 10 by 10
+
+rm -f file.a
+ls | grep .tst | sort -n | xargs -n 10 ar -qv file.a
+
+ar -t file.a |
+tee -a test.log |
+awk '$0 != NR-1 ".tst" {
+ printf "bad line %d:%s\n", NR, $0
+ exit 1
+}'
+
+
+###########################################################################
+#Test special cases
+
+#empty file list
+rm -f file.a
+ar -qv file.a
+if !test -f file.a
+then
+ echo "ar -q didn't generated empty archive" >&2
+ exit 1
+fi
+
+#recursive inclusion
+rm -f file.a
+ar -qv file.a file.a
+
+
+#missed file
+ar -qv file.a badfile.a || true
+if ar -qv file.a badfile.a
+then
+ echo "ar -q failed to detect missed file" >&2
+ exit 1
+fi
--- a/tests/ar/execute/Makefile
+++ b/tests/ar/execute/Makefile
@@ -9,4 +9,6 @@
SCCPREFIX=$(ROOTDIR) PATH=$(ROOTDIR)/bin:$$PATH ./chktest.sh
clean :
- rm -f *.a
+ rm -f *.a test.log
+ rm -f file*
+ rm -f *.dst
--- a/tests/ar/execute/chktest.sh
+++ b/tests/ar/execute/chktest.sh
@@ -1,14 +1,37 @@
#!/bin/sh
ttyflags=`stty -g`
-trap "stty $ttyflags;tabs -8" 0 2 3 15
+trap "stty $ttyflags;tabs -8;rm -rf master.a file*" 0 2 3 15
stty tabs
tabs 40
ulimit -c 40
rm -f test.log
+rm -rf file* master.a
-for i in test*.sh
+uid=`id -u`
+gid=`id -g`
+
+cat <<"EOF" >master.a
+!<arch>
+file1 315532800 $uid $gid 100644 79 `
+This is the first file,
+and it should go in the
+first position in the archive.
+
+file2 315532800 $uid $gid 100644 125 `
+But this other one is the second one,
+and it shouldn't go in the first position
+because it should go in the second position.
+
+file3 315532800 $uid $gid 100644 118 `
+and at the end, this is the last file
+that should go at the end of the file,
+thus it should go in the third position.
+EOF
+
+for i in *-test*.sh
do
+ printf "Test: %s\n\n" $i >> test.log
printf "%s\t" $i
./$i && echo [OK] || echo [FAIL]
done
--- a/tests/ar/execute/test-q.sh
+++ /dev/null
@@ -1,97 +1,0 @@
-#!/bin/sh
-
-exec >> test.log 2>&1
-
-set -e
-
-TZ=UTC
-tmp1=`mktemp`
-tmp2=`mktemp`
-pwd=$PWD
-
-trap "cd $pwd && rm -rf $tmp1 $tmp2 file*" 0 2 3
-
-rm -f file.a
-
-############################################################################
-#create the test files
-mkdir -p files
-cd files
-
-cat <<! >file1
-This is the first file,
-and it should go in the
-first position in the archive.
-!
-
-cat <<! >file2
-But this other one is the second one,
-and it shouldn't go in the first position
-because it should go in the second position.
-!
-
-cat <<! >file3
-and at the end, this is the last file
-that should go at the end of the file,
-thus it should go in the third position.
-!
-
-cat <<! >file4
-Ok, we can add a new file
-and see what happens
-!
-
-touch -t 198001010000 file?
-
-############################################################################
-#generate the archive with the members in files
-ar -qv ../file.a file1 file2
-ar -qv ../file.a file3
-cd ..
-
-############################################################################
-#verify that the output of ar -t is correct
-
-ar -t file.a > $tmp1
-cat <<! > $tmp2
-file1
-file2
-file3
-!
-
-cmp $tmp1 $tmp2
-
-############################################################################
-#and now check that -tv doesn't break the code
-
-ar -tv file.a >$tmp1
-cat <<! >$tmp2
-rw-r--r-- `id -u`/`id -g` Tue Jan 1 00:00:00 1980 file1
-rw-r--r-- `id -u`/`id -g` Tue Jan 1 00:00:00 1980 file2
-rw-r--r-- `id -u`/`id -g` Tue Jan 1 00:00:00 1980 file3
-!
-
-cmp $tmp1 $tmp2
-
-############################################################################
-#extract the files
-ar -xv file.a file1 file2 file3
-
-cmp file1 files/file1
-cmp file2 files/file2
-cmp file3 files/file3
-
-rm -f file1 file2 file3
-
-############################################################################
-#stress quick append
-
-for i in `awk 'BEGIN {for (i=0; i <999; ++i) print i}'`
-do
- touch file-$i
- ar -qv file.a file-$i
-done
-
-rm file.a
-
-ls | grep file- | xargs -n 10 ar -qv file.a