From 387edf547eb09b27ca6d49772eb048d729f09cf4 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 20 Sep 2014 13:09:14 -0500 Subject: Move testsuite out of scripts/test into its own top level tests directory, and make ctrl-c kill "make test" more reliably. --- tests/basename.test | 23 +++++ tests/blkid.test | 44 +++++++++ tests/blkid/cramfs.bz2 | Bin 0 -> 121 bytes tests/blkid/ext2.bz2 | Bin 0 -> 2396 bytes tests/blkid/ext3.bz2 | Bin 0 -> 4132 bytes tests/blkid/ext4.bz2 | Bin 0 -> 2491 bytes tests/blkid/f2fs.bz2 | Bin 0 -> 634 bytes tests/blkid/minix.bz2 | Bin 0 -> 157 bytes tests/blkid/msdos.bz2 | Bin 0 -> 288 bytes tests/blkid/ntfs.bz2 | Bin 0 -> 35854 bytes tests/blkid/reiser3.bz2 | Bin 0 -> 329 bytes tests/blkid/squashfs.bz2 | Bin 0 -> 158 bytes tests/blkid/vfat.bz2 | Bin 0 -> 291 bytes tests/blkid/xfs.bz2 | Bin 0 -> 437 bytes tests/bzcat.test | 26 +++++ tests/cat.test | 31 ++++++ tests/chgrp.test | 102 ++++++++++++++++++++ tests/chmod.test | 244 +++++++++++++++++++++++++++++++++++++++++++++++ tests/cksum.test | 29 ++++++ tests/cmp.test | 35 +++++++ tests/cp.test | 101 ++++++++++++++++++++ tests/cpio.test | 39 ++++++++ tests/cut.test | 47 +++++++++ tests/dd.test | 83 ++++++++++++++++ tests/dirname.test | 10 ++ tests/du.test | 26 +++++ tests/echo.test | 37 +++++++ tests/expand.test | 44 +++++++++ tests/expr.test | 10 ++ tests/factor.test | 18 ++++ tests/find.test | 42 ++++++++ tests/grep.test | 98 +++++++++++++++++++ tests/groupadd.test | 56 +++++++++++ tests/groupdel.test | 27 ++++++ tests/head.test | 17 ++++ tests/hostname.test | 18 ++++ tests/link.test | 26 +++++ tests/ln.test | 70 ++++++++++++++ tests/losetup.test | 46 +++++++++ tests/ls.test | 49 ++++++++++ tests/lsattr.test | 159 ++++++++++++++++++++++++++++++ tests/md5sum.test | 22 +++++ tests/mkdir.test | 73 ++++++++++++++ tests/mkfifo.test | 28 ++++++ tests/modinfo.test | 30 ++++++ tests/mount.test | 87 +++++++++++++++++ tests/mv.test | 98 +++++++++++++++++++ tests/nl.test | 50 ++++++++++ tests/pgrep.test | 122 ++++++++++++++++++++++++ tests/printf.test | 29 ++++++ tests/pwd.test | 26 +++++ tests/readlink.test | 67 +++++++++++++ tests/renice.test | 110 +++++++++++++++++++++ tests/rev.test | 25 +++++ tests/rm.test | 46 +++++++++ tests/rmdir.test | 55 +++++++++++ tests/seq.test | 28 ++++++ tests/sha1sum.test | 57 +++++++++++ tests/sort.test | 100 +++++++++++++++++++ tests/split.test | 31 ++++++ tests/tac.test | 29 ++++++ tests/tail.test | 61 ++++++++++++ tests/tar.test | 73 ++++++++++++++ tests/test.test | 67 +++++++++++++ tests/touch.test | 24 +++++ tests/useradd.test | 90 +++++++++++++++++ tests/uudecode.test | 27 ++++++ tests/uuencode.test | 26 +++++ tests/wc.test | 48 ++++++++++ tests/xargs.test | 35 +++++++ tests/xzcat.test | 26 +++++ tests/zcat.test | 26 +++++ 72 files changed, 3173 insertions(+) create mode 100755 tests/basename.test create mode 100755 tests/blkid.test create mode 100644 tests/blkid/cramfs.bz2 create mode 100644 tests/blkid/ext2.bz2 create mode 100644 tests/blkid/ext3.bz2 create mode 100644 tests/blkid/ext4.bz2 create mode 100644 tests/blkid/f2fs.bz2 create mode 100644 tests/blkid/minix.bz2 create mode 100644 tests/blkid/msdos.bz2 create mode 100644 tests/blkid/ntfs.bz2 create mode 100644 tests/blkid/reiser3.bz2 create mode 100644 tests/blkid/squashfs.bz2 create mode 100644 tests/blkid/vfat.bz2 create mode 100644 tests/blkid/xfs.bz2 create mode 100644 tests/bzcat.test create mode 100755 tests/cat.test create mode 100755 tests/chgrp.test create mode 100644 tests/chmod.test create mode 100755 tests/cksum.test create mode 100755 tests/cmp.test create mode 100755 tests/cp.test create mode 100755 tests/cpio.test create mode 100644 tests/cut.test create mode 100644 tests/dd.test create mode 100755 tests/dirname.test create mode 100755 tests/du.test create mode 100755 tests/echo.test create mode 100755 tests/expand.test create mode 100644 tests/expr.test create mode 100755 tests/factor.test create mode 100644 tests/find.test create mode 100755 tests/grep.test create mode 100644 tests/groupadd.test create mode 100644 tests/groupdel.test create mode 100755 tests/head.test create mode 100644 tests/hostname.test create mode 100755 tests/link.test create mode 100644 tests/ln.test create mode 100755 tests/losetup.test create mode 100644 tests/ls.test create mode 100644 tests/lsattr.test create mode 100755 tests/md5sum.test create mode 100755 tests/mkdir.test create mode 100755 tests/mkfifo.test create mode 100755 tests/modinfo.test create mode 100644 tests/mount.test create mode 100644 tests/mv.test create mode 100644 tests/nl.test create mode 100644 tests/pgrep.test create mode 100644 tests/printf.test create mode 100755 tests/pwd.test create mode 100755 tests/readlink.test create mode 100644 tests/renice.test create mode 100644 tests/rev.test create mode 100644 tests/rm.test create mode 100755 tests/rmdir.test create mode 100755 tests/seq.test create mode 100755 tests/sha1sum.test create mode 100755 tests/sort.test create mode 100755 tests/split.test create mode 100644 tests/tac.test create mode 100755 tests/tail.test create mode 100644 tests/tar.test create mode 100755 tests/test.test create mode 100755 tests/touch.test create mode 100644 tests/useradd.test create mode 100644 tests/uudecode.test create mode 100644 tests/uuencode.test create mode 100755 tests/wc.test create mode 100755 tests/xargs.test create mode 100644 tests/xzcat.test create mode 100644 tests/zcat.test (limited to 'tests') diff --git a/tests/basename.test b/tests/basename.test new file mode 100755 index 0000000..2f7a2ec --- /dev/null +++ b/tests/basename.test @@ -0,0 +1,23 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +# Removal of extra /'s +testing "basename /-only" "basename ///////" "/\n" "" "" +testing "basename trailing /" "basename a//////" "a\n" "" "" +testing "basename combined" "basename /////a///b///c///d/////" "d\n" "" "" + +# Standard suffix behavior. +testing "basename suffix" "basename a/b/c/d.suffix .suffix" "d\n" "" "" + +# A suffix cannot be the entire result. +testing "basename suffix=result" "basename .txt .txt" ".txt\n" "" "" + +# Deal with suffix appearing in the filename +testing "basename reappearing suffix 1" "basename a.txt.txt .txt" "a.txt\n" "" "" +testing "basename reappearing suffix 2" "basename a.txt.old .txt" "a.txt.old\n" "" "" + +# A suffix should be a real suffix, only a the end. +testing "basename invalid suffix" "basename isthisasuffix? suffix" "isthisasuffix?\n" "" "" diff --git a/tests/blkid.test b/tests/blkid.test new file mode 100755 index 0000000..3f676df --- /dev/null +++ b/tests/blkid.test @@ -0,0 +1,44 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +BDIR="$TOPDIR/tests/blkid" + +bzcat "$BDIR"/squashfs.bz2 > temp.img +testing "blkid file" "blkid temp.img" 'temp.img: TYPE="squashfs"\n' "" "" +rm temp.img + +testing "blkid cramfs" 'bzcat "$BDIR"/cramfs.bz2 | blkid -' \ + '-: LABEL="mycramfs" TYPE="cramfs"\n' "" "" +testing "blkid ext2" 'bzcat "$BDIR"/ext2.bz2 | blkid -' \ + '-: LABEL="myext2" UUID="e59093ba-4135-4fdb-bcc4-f20beae4dfaf" TYPE="ext2"\n' \ + "" "" +testing "blkid ext3" 'bzcat "$BDIR"/ext3.bz2 | blkid -' \ + '-: LABEL="myext3" UUID="79d1c877-1a0f-4e7d-b21d-fc32ae3ef101" TYPE="ext2"\n' \ + "" "" +testing "blkid ext4" 'bzcat "$BDIR"/ext4.bz2 | blkid -' \ + '-: LABEL="myext4" UUID="dc4b7c00-c0c0-4600-af7e-0335f09770fa" TYPE="ext2"\n' \ + "" "" +testing "blkid f2fs" 'bzcat "$BDIR"/f2fs.bz2 | blkid -' \ + '-: LABEL="" UUID="b53d3619-c204-4c0b-8504-36363578491c" TYPE="f2fs"\n' \ + "" "" +testing "blkid msdos" 'bzcat "$BDIR"/msdos.bz2 | blkid -' \ + '-: LABEL="mymsdos " UUID="5108-1e6e" TYPE="vfat"\n' "" "" +testing "blkid ntfs" 'bzcat "$BDIR"/ntfs.bz2 | blkid -' \ + '-: UUID="8585600838bfe16e" TYPE="ntfs"\n' "" "" +testing "blkid reiserfs" 'bzcat "$BDIR"/reiser3.bz2 | blkid -' \ + '-: LABEL="" UUID="a5b99bec-45cc-41d7-986e-32f4b6fc28f2" TYPE="reiserfs"\n' \ + "" "" +testing "blkid squashfs" 'bzcat "$BDIR"/squashfs.bz2 | blkid -' \ + '-: TYPE="squashfs"\n' "" "" +testing "blkid vfat" 'bzcat "$BDIR"/vfat.bz2 | blkid -' \ + '-: LABEL="myvfat " UUID="1db9-5673" TYPE="vfat"\n' "" "" +testing "blkid xfs" 'bzcat "$BDIR"/xfs.bz2 | blkid -' \ + '-: LABEL="XFS_test" UUID="d63a1dc3-27d5-4dd4-8b38-f4f97f495c6f" TYPE="xfs"\n' \ + "" "" + +#testing "blkid minix" 'bzcat "$BDIR"/minix.bz2 | blkid -' +#adfs bfs btrfs cramfs jfs nilfs romfs +#vfat // fat32 fat12 fat16 diff --git a/tests/blkid/cramfs.bz2 b/tests/blkid/cramfs.bz2 new file mode 100644 index 0000000..37438fe Binary files /dev/null and b/tests/blkid/cramfs.bz2 differ diff --git a/tests/blkid/ext2.bz2 b/tests/blkid/ext2.bz2 new file mode 100644 index 0000000..e27c4d7 Binary files /dev/null and b/tests/blkid/ext2.bz2 differ diff --git a/tests/blkid/ext3.bz2 b/tests/blkid/ext3.bz2 new file mode 100644 index 0000000..be7f11f Binary files /dev/null and b/tests/blkid/ext3.bz2 differ diff --git a/tests/blkid/ext4.bz2 b/tests/blkid/ext4.bz2 new file mode 100644 index 0000000..a8314f9 Binary files /dev/null and b/tests/blkid/ext4.bz2 differ diff --git a/tests/blkid/f2fs.bz2 b/tests/blkid/f2fs.bz2 new file mode 100644 index 0000000..4111e87 Binary files /dev/null and b/tests/blkid/f2fs.bz2 differ diff --git a/tests/blkid/minix.bz2 b/tests/blkid/minix.bz2 new file mode 100644 index 0000000..b2f022e Binary files /dev/null and b/tests/blkid/minix.bz2 differ diff --git a/tests/blkid/msdos.bz2 b/tests/blkid/msdos.bz2 new file mode 100644 index 0000000..26c9b66 Binary files /dev/null and b/tests/blkid/msdos.bz2 differ diff --git a/tests/blkid/ntfs.bz2 b/tests/blkid/ntfs.bz2 new file mode 100644 index 0000000..b654ecd Binary files /dev/null and b/tests/blkid/ntfs.bz2 differ diff --git a/tests/blkid/reiser3.bz2 b/tests/blkid/reiser3.bz2 new file mode 100644 index 0000000..b2adfc8 Binary files /dev/null and b/tests/blkid/reiser3.bz2 differ diff --git a/tests/blkid/squashfs.bz2 b/tests/blkid/squashfs.bz2 new file mode 100644 index 0000000..2f1b793 Binary files /dev/null and b/tests/blkid/squashfs.bz2 differ diff --git a/tests/blkid/vfat.bz2 b/tests/blkid/vfat.bz2 new file mode 100644 index 0000000..1df8b89 Binary files /dev/null and b/tests/blkid/vfat.bz2 differ diff --git a/tests/blkid/xfs.bz2 b/tests/blkid/xfs.bz2 new file mode 100644 index 0000000..a757196 Binary files /dev/null and b/tests/blkid/xfs.bz2 differ diff --git a/tests/bzcat.test b/tests/bzcat.test new file mode 100644 index 0000000..8bc5f5c --- /dev/null +++ b/tests/bzcat.test @@ -0,0 +1,26 @@ +#!/bin/bash + +# Copyright 2014 Divya Kothari +# Copyright 2014 Naha Maggu + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" +echo "hello" > file +tar -cjf file.tar.bz2 file +# Get system bzcat +bzcatExe=`which bzcat` +$bzcatExe file.tar.bz2 > bzcatOut +testing "bzcat - decompresses a single file" "bzcat file.tar.bz2 > Tempfile && echo "yes"; diff Tempfile bzcatOut && echo "yes"; rm -rf file* bzcatOut Tempfile" "yes\nyes\n" "" "" + +#testing "name" "command" "result" "infile" "stdin" +echo "hello" > file1 +echo "hi" > file2 +echo "Hi, Good morning !! I am a bzcat tester" > file3 +tar -cjf file1.tar.bz2 file1 +tar -cjf file2.tar.bz2 file2 +tar -cjf file3.tar.bz2 file3 +# Get system bzcat +bzcatExe=`which bzcat` +$bzcatExe file1.tar.bz2 file2.tar.bz2 file3.tar.bz2 > bzcatOut +testing "bzcat - decompresses multiple files" "bzcat file1.tar.bz2 file2.tar.bz2 file3.tar.bz2 > Tempfile && echo "yes" ; diff Tempfile bzcatOut && echo "yes"; rm -rf file* bzcatOut Tempfile " "yes\nyes\n" "" "" diff --git a/tests/cat.test b/tests/cat.test new file mode 100755 index 0000000..3d5842a --- /dev/null +++ b/tests/cat.test @@ -0,0 +1,31 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +echo "one" > file1 +echo "two" > file2 +testing "cat" "cat && echo yes" "oneyes\n" "" "one" +testing "cat -" "cat - && echo yes" "oneyes\n" "" "one" +testing "cat file1 file2" "cat file1 file2" "one\ntwo\n" "" "" +testing "cat - file" "cat - file1" "zero\none\n" "" "zero\n" +testing "cat file -" "cat file1 -" "one\nzero\n" "" "zero\n" + +testing "cat file1 notfound file2" \ + "cat file1 notfound file2 2>stderr && echo ok ; cat stderr; rm stderr" \ + "one\ntwo\ncat: notfound: No such file or directory\n" "" "" + +testing "cat file1" \ + "cat /proc/self/exe > file1 && cmp /proc/self/exe file1 && echo yes" \ + "yes\n" "" "" + +testing "cat - file1" \ + "cat - file1 | diff -a -U 0 - file1 | tail -n 1" \ + "-hello\n" "" "hello\n" + +testing "cat > /dev/full" \ + "cat - > /dev/full 2>stderr && echo ok; cat stderr; rm stderr" \ + "cat: xwrite: No space left on device\n" "" "zero\n" + +rm file1 file2 \ No newline at end of file diff --git a/tests/chgrp.test b/tests/chgrp.test new file mode 100755 index 0000000..2af9385 --- /dev/null +++ b/tests/chgrp.test @@ -0,0 +1,102 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +if [ "$(id -u)" -ne 0 ] +then + echo "SKIPPED: chgrp (not root)" + continue 2>/dev/null + exit +fi + +# We chgrp between "root" and the last group in /etc/group. + +GRP="$(sed -n '$s/:.*//p' /etc/group)" + +# Set up a little testing hierarchy + +rm -rf testdir && +mkdir -p testdir/dir/dir/dir testdir/dir2 && +touch testdir/dir/file && +ln -s ../dir/dir testdir/dir2/dir && +ln -s ../dir/file testdir/dir2/file || exit 1 + +# Wrapper to reset groups and return results + +IN="cd testdir && chgrp -R $GRP dir dir2 &&" +OUT="&& cd .. && echo \$(ls -lR testdir | awk '{print \$4}')" + +# The groups returned by $OUT are, in order: +# dir dir2 dir/dir dir/file dir/dir/dir dir2/dir dir2/file + +#testing "name" "command" "result" "infile" "stdin" + +# Basic smoketest +testing "chgrp dir" "$IN chgrp root dir $OUT" \ + "root $GRP $GRP $GRP $GRP $GRP $GRP\n" "" "" +testing "chgrp file" "$IN chgrp root dir/file $OUT" \ + "$GRP $GRP $GRP root $GRP $GRP $GRP\n" "" "" +testing "chgrp dir and file" "$IN chgrp root dir dir/file $OUT" \ + "root $GRP $GRP root $GRP $GRP $GRP\n" "" "" + +# symlinks (affect target, not symlink) +testing "chgrp symlink->file" "$IN chgrp root dir2/file $OUT" \ + "$GRP $GRP $GRP root $GRP $GRP $GRP\n" "" "" +testing "chgrp symlink->dir" "$IN chgrp root dir2/dir $OUT" \ + "$GRP $GRP root $GRP $GRP $GRP $GRP\n" "" "" +testing "chgrp -h symlink->dir" "$IN chgrp -h root dir2/dir $OUT" \ + "$GRP $GRP $GRP $GRP $GRP root $GRP\n" "" "" + +# What does -h do (affect symlink, not target) +testing "chgrp -h symlink->file" "$IN chgrp -h root dir2/file $OUT" \ + "$GRP $GRP $GRP $GRP $GRP $GRP root\n" "" "" +testing "chgrp -h symlink->dir" "$IN chgrp -h root dir2/dir $OUT" \ + "$GRP $GRP $GRP $GRP $GRP root $GRP\n" "" "" + +# chgrp -R (note, -h is implied by -R) + +testing "chgrp -R dir" "$IN chgrp -R root dir $OUT" \ + "root $GRP root root root $GRP $GRP\n" "" "" +testing "chgrp -R dir2" "$IN chgrp -R root dir2 $OUT" \ + "$GRP root $GRP $GRP $GRP root root\n" "" "" +testing "chgrp -R symlink->dir" "$IN chgrp -R root dir2/dir $OUT" \ + "$GRP $GRP $GRP $GRP $GRP root $GRP\n" "" "" +testing "chgrp -R symlink->file" "$IN chgrp -R root dir2/file $OUT" \ + "$GRP $GRP $GRP $GRP $GRP $GRP root\n" "" "" + +# chgrp -RP (same as -R by itself) + +testing "chgrp -RP dir2" "$IN chgrp -RP root dir2 $OUT" \ + "$GRP root $GRP $GRP $GRP root root\n" "" "" +testing "chgrp -RP symlink->dir" "$IN chgrp -RP root dir2/dir $OUT" \ + "$GRP $GRP $GRP $GRP $GRP root $GRP\n" "" "" +testing "chgrp -RP symlink->file" "$IN chgrp -RP root dir2/file $OUT" \ + "$GRP $GRP $GRP $GRP $GRP $GRP root\n" "" "" + +# chgrp -RH (change target but only recurse through symlink->dir on cmdline) + +testing "chgrp -RH dir2" "$IN chgrp -RH root dir2 $OUT" \ + "$GRP root root root $GRP $GRP $GRP\n" "" "" +testing "chgrp -RH symlink->dir" "$IN chgrp -RH root dir2/dir $OUT" \ + "$GRP $GRP root $GRP root $GRP $GRP\n" "" "" +testing "chgrp -RH symlink->file" "$IN chgrp -RH root dir2/file $OUT" \ + "$GRP $GRP $GRP root $GRP $GRP $GRP\n" "" "" + +# chgrp -RL (change target and always recurse through symlink->dir) + +testing "chgrp -RL dir2" "$IN chgrp -RL root dir2 $OUT" \ + "$GRP root root root root $GRP $GRP\n" "" "" +testing "chgrp -RL symlink->dir" "$IN chgrp -RL root dir2/dir $OUT" \ + "$GRP $GRP root $GRP root $GRP $GRP\n" "" "" +testing "chgrp -RL symlink->file" "$IN chgrp -RL root dir2/file $OUT" \ + "$GRP $GRP $GRP root $GRP $GRP $GRP\n" "" "" + +# -HLP are NOPs without -R +testing "chgrp -H without -R" "$IN chgrp -H root dir2/dir $OUT" \ + "$GRP $GRP root $GRP $GRP $GRP $GRP\n" "" "" +testing "chgrp -L without -R" "$IN chgrp -L root dir2/dir $OUT" \ + "$GRP $GRP root $GRP $GRP $GRP $GRP\n" "" "" +testing "chgrp -P without -R" "$IN chgrp -P root dir2/dir $OUT" \ + "$GRP $GRP root $GRP $GRP $GRP $GRP\n" "" "" + +rm -rf testdir diff --git a/tests/chmod.test b/tests/chmod.test new file mode 100644 index 0000000..77106a6 --- /dev/null +++ b/tests/chmod.test @@ -0,0 +1,244 @@ +#!/bin/bash + +# Copyright 2013 Divya Kothari +# Copyright 2013 Robin Mittal + +#testing "name" "command" "result" "infile" "stdin" + +PERM="---""--x""-w-""-wx""r--""r-x""rw-""rwx" + +num2perm() +{ + for i in 0 1 2 + do + num=${1:$i:1} + printf "%s" ${PERM:$(($num*3)):3} + done + echo +} + +# Creating test files to test chmod command +mkdir dir +touch file + +# We don't need to test all 511 permissions +for u in 0 1 2 3 4 5 6 7 +do + for g in 0 3 6 + do + for o in 0 7 + do + if [ "$type" == file ] + then + type=dir + rm -rf "./$type" && mkdir $type + DASH=d + else + type=file + rm -f "./$type" && touch $type + DASH=- + fi + DASHES=$(num2perm $u$g$o) + testing "chmod $u$g$o $type" "chmod $u$g$o $type && + ls -ld $type | cut -d' ' -f 1 | cut -d. -f 1" "$DASH$DASHES\n" "" "" + done + done +done + +rm -rf dir file && mkdir dir && touch file +testing "chmod 750 dir 640 file" \ + "chmod 750 dir 640 file 2>/dev/null || + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-x---\n-rwxr-x---\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod 666 dir file" \ + "chmod 666 dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drw-rw-rw-\n-rw-rw-rw-\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod 765 *" "chmod 765 * && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxrw-r-x\n-rwxrw-r-x\n" "" "" + +##### u,g,o,a=r,w,x +rm -rf dir file && mkdir dir && touch file +testing "chmod u=r dir file" "chmod u=r dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "dr--r-xr-x\n-r--r--r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod u=w dir file" "chmod u=w dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d-w-r-xr-x\n--w-r--r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod u=x dir file" "chmod u=x dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d--xr-xr-x\n---xr--r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod u+r dir file" "chmod u+r dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod u+w dir file" "chmod u+w dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod u+x dir file" "chmod u+x dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rwxr--r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod u-r dir file" "chmod u-r dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d-wxr-xr-x\n--w-r--r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod u-w dir file" "chmod u-w dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "dr-xr-xr-x\n-r--r--r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod u-x dir file" "chmod u-x dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drw-r-xr-x\n-rw-r--r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod g=r dir file" "chmod g=r dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr--r-x\n-rw-r--r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod g=w dir file" "chmod g=w dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwx-w-r-x\n-rw--w-r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod g=x dir file" "chmod g=x dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwx--xr-x\n-rw---xr--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod g+r dir file" "chmod g+r dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod g+w dir file" "chmod g+w dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxrwxr-x\n-rw-rw-r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod g+x dir file" "chmod g+x dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r-xr--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod g-r dir file" "chmod g-r dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwx--xr-x\n-rw----r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod g-w dir file" "chmod g-w dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod g-x dir file" "chmod g-x dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr--r-x\n-rw-r--r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod o=r dir file" "chmod o=r dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr--\n-rw-r--r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod o=w dir file" "chmod o=w dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-x-w-\n-rw-r---w-\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod o=x dir file" "chmod o=x dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-x--x\n-rw-r----x\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod o+r dir file" "chmod o+r dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod o+w dir file" "chmod o+w dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xrwx\n-rw-r--rw-\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod o+x dir file" "chmod o+x dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r-x\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod o-r dir file" "chmod o-r dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-x--x\n-rw-r-----\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod o-w dir file" "chmod o-w dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod o-x dir file" "chmod o-x dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr--\n-rw-r--r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod a=r dir file" "chmod a=r dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "dr--r--r--\n-r--r--r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod a=w dir file" "chmod a=w dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d-w--w--w-\n--w--w--w-\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod a=x dir file" "chmod a=x dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d--x--x--x\n---x--x--x\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod a+r dir file" "chmod a+r dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod a+w dir file" "chmod a+w dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxrwxrwx\n-rw-rw-rw-\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod a+x dir file" "chmod a+x dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rwxr-xr-x\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod a-r dir file" "chmod a-r dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d-wx--x--x\n--w-------\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod a-w dir file" "chmod a-w dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "dr-xr-xr-x\n-r--r--r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod a-x dir file" "chmod a-x dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drw-r--r--\n-rw-r--r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod =r dir file" "chmod =r dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "dr--r--r--\n-r--r--r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod =w dir file" "chmod =w dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d-w-------\n--w-------\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod =x dir file" "chmod =x dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d--x--x--x\n---x--x--x\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod +r dir file" "chmod +r dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod +w dir file" "chmod +w dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod +x dir file" "chmod +x dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rwxr-xr-x\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod -r dir file" "chmod -r dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d-wx--x--x\n--w-------\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod -w dir file" "chmod -w dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "dr-xr-xr-x\n-r--r--r--\n" "" "" + +rm -rf dir file && mkdir dir && touch file +testing "chmod -x dir file" "chmod -x dir file && + ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drw-r--r--\n-rw-r--r--\n" "" "" + +# Removing test files for cleanup purpose +rm -rf dir file diff --git a/tests/cksum.test b/tests/cksum.test new file mode 100755 index 0000000..152dc12 --- /dev/null +++ b/tests/cksum.test @@ -0,0 +1,29 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + + +#testing "name" "command" "result" "infile" "stdin" + +# Default behavior on stdin and on files. +testing "cksum on stdin" "echo -n hello | cksum" "3287646509 5\n" "" "" +echo -n "hello" > tmpfile +testing "cksum on file" "cksum tmpfile" "3287646509 5 tmpfile\n" "" "" +rm -f tmpfile +touch one two +testing "cksum on multiple files" "cksum one two" "4294967295 0 one\n4294967295 0 two\n" "" "" +rm -f one two + +# Check the length suppression, both calculate the CRC on 'abc' but the second +# option has length suppression on and has the length concatenated to 'abc'. +testing "cksum on abc including length" "echo -n 'abc' | cksum" "1219131554 3\n" "" "" +testing "cksum on abc excluding length" "echo -ne 'abc\x3' | cksum -N" "1219131554 4\n" "" "" + +# cksum on no contents gives 0xffffffff (=4294967295) +testing "cksum on no data post-inversion" "echo -n "" | cksum" "4294967295 0\n" "" "" +# If we do preinversion we will then get 0. +testing "cksum on no data pre+post-inversion" "echo -n "" | cksum -P" "0 0\n" "" "" +# If we skip the post-inversion we also get 0 +testing "cksum on no data no inversion" "echo -n "" | cksum -I" "0 0\n" "" "" +# Two wrongs make a right. +testing "cksum on no data pre-inversion" "echo -n "" | cksum -PI" "4294967295 0\n" "" "" diff --git a/tests/cmp.test b/tests/cmp.test new file mode 100755 index 0000000..ef53b37 --- /dev/null +++ b/tests/cmp.test @@ -0,0 +1,35 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +testing "cmp not enough arguments [fail]" "cmp input 2>/dev/null || echo yes" "yes\n" "foo" "" +testing "cmp missing file1 [fail]" "cmp file1 input 2>/dev/null || echo yes" "yes\n" "foo" "" + +#mkdir dir +#testing "cmp directory [fail]" "cmp dir dir 2>/dev/null || echo yes" \ + #"yes\n" "" "" +#rmdir dir + +echo "ab +c" > input2 + +testing "cmp identical files, stdout" "cmp input input2" "" "ab\nc\n" "" +testing "cmp identical files, return code" "cmp input input2 && echo yes" "yes\n" "ab\nc\n" "" + +testing "cmp EOF, stderr" "cmp input input2 2>&1" "cmp: EOF on input2\n" "ab\nc\nx" "" +testing "cmp EOF, return code" "cmp input input2 2>/dev/null || echo yes" "yes\n" "ab\nc\nx" "" +# The gnu/dammit version fails this because posix says "char" and they don't. +testing "cmp diff, stdout" "cmp input input2" "input input2 differ: char 4, line 2\n" "ab\nx\nx" "" +testing "cmp diff, return code" "cmp input input2 > /dev/null || echo yes" "yes\n" "ab\nx\nx" "" + +testing "cmp -s EOF, return code" "cmp -s input input2 || echo yes" "yes\n" "ab\nc\nx" "" +testing "cmp -s diff, return code" "cmp -s input input2 || echo yes" "yes\n" "ab\nx\nx" "" + +testing "cmp -l EOF, stderr" "cmp -l input input2 2>&1" "cmp: EOF on input2\n" "ab\nc\nx" "" +testing "cmp -l diff and EOF, stdout and stderr" "cmp -l input input2 2>&1 | sort" "4 170 143\ncmp: EOF on input2\n" "ab\nx\nx" "" + +rm input2 + +testing "cmp stdin and file" "cmp input -" "input - differ: char 4, line 2\n" "ab\nc\n" "ab\nx\n" +#testing "cmp stdin and stdin" "cmp input -" "" "" "ab\nc\n" + diff --git a/tests/cp.test b/tests/cp.test new file mode 100755 index 0000000..4327256 --- /dev/null +++ b/tests/cp.test @@ -0,0 +1,101 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +# Create test file +dd if=/dev/urandom of=random bs=64 count=1 2> /dev/null + +#testing "name" "command" "result" "infile" "stdin" + +testing "cp not enough arguments [fail]" "cp one 2>/dev/null || echo yes" \ + "yes\n" "" "" +testing "cp -missing source [fail]" "cp missing two 2>/dev/null || echo yes" \ + "yes\n" "" "" +testing "cp file->file" "cp random two && cmp random two && echo yes" \ + "yes\n" "" "" +rm two + +mkdir two +testing "cp file->dir" "cp random two && cmp random two/random && echo yes" \ + "yes\n" "" "" +rm two/random +testing "cp file->dir/file" \ + "cp random two/random && cmp random two/random && echo yes" \ + "yes\n" "" "" +testing "cp -r dir->missing" \ + "cp -r two three && cmp random three/random && echo yes" \ + "yes\n" "" "" +touch walrus +testing "cp -r dir->file [fail]" \ + "cp -r two walrus 2>/dev/null || echo yes" "yes\n" "" "" +touch two/three +testing "cp -r dir hits file." \ + "cp -r three two 2>/dev/null || echo yes" "yes\n" "" "" +rm -rf two three walrus + +touch two +chmod 000 two +testing "cp file->inaccessable [fail]" \ + "cp random two 2>/dev/null || echo yes" "yes\n" "" "" +rm -f two + +touch two +chmod 000 two +testing "cp -f file->inaccessable" \ + "cp -f random two && cmp random two && echo yes" "yes\n" "" "" +mkdir sub +chmod 000 sub +testing "cp file->inaccessable_dir [fail]" \ + "cp random sub 2>/dev/null || echo yes" "yes\n" "" "" +rm two +rmdir sub + +# This test fails because our -rf deletes existing target files without +# regard to what we'd be copying over it. Posix says to only do that if +# we'd be copying a file over the file, but does not say _why_. + +#mkdir dir +#touch file +#testing "cp -rf dir file [fail]" "cp -rf dir file 2>/dev/null || echo yes" \ +# "yes\n" "" "" +#rm -rf dir file + +touch one two +testing "cp file1 file2 missing [fail]" \ + "cp one two missing 2>/dev/null || echo yes" "yes\n" "" "" +mkdir dir +testing "cp dir file missing [fail]" \ + "cp dir two missing 2>/dev/null || echo yes" "yes\n" "" "" +testing "cp -rf dir file missing [fail]" \ + "cp dir two missing 2>/dev/null || echo yes" "yes\n" "" "" +testing "cp file1 file2 file [fail]" \ + "cp random one two 2>/dev/null || echo yes" "yes\n" "" "" +testing "cp file1 file2 dir" \ + "cp random one dir && cmp random dir/random && cmp one dir/one && echo yes" \ + "yes\n" "" "" +rm one two random +rm -rf dir + +mkdir -p one/two/three/four +touch one/two/three/five +touch one/{six,seven,eight} +testing "cp -r /abspath dest" \ + "cp -r \"$(readlink -f one)\" dir && diff -r one dir && echo yes" \ + "yes\n" "" "" +testing "cp -r dir again" "cp -r one/. dir && diff -r one dir && echo yes" \ + "yes\n" "" "" +mkdir dir2 +testing "cp -r dir1/* dir2" \ + "cp -r one/* dir2 && diff -r one dir2 && echo yes" "yes\n" "" "" +rm -rf one dir dir2 + +# cp -r ../source destdir +# cp -r one/two/three missing +# cp -r one/two/three two +# mkdir one; touch one/two; ln -s two one/three +# cp file1 file2 dir +# cp file1 missing file2 -> dir + +# Make sure it's truncating existing file +# copy with -d at top level, with -d in directory, without -d at top level, +# without -d in directory diff --git a/tests/cpio.test b/tests/cpio.test new file mode 100755 index 0000000..d0528e5 --- /dev/null +++ b/tests/cpio.test @@ -0,0 +1,39 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +# We need to test name and file padding. +# This means all possible values of strlen(name)+1 % 4, +# plus file sizes of at least 0-4. + +touch a bb ccc dddd +testing "cpio name padding" "cpio -o -H newc|cpio -it" "a\nbb\nccc\ndddd\n" "" "a\nbb\nccc\ndddd\n" +rm a bb ccc dddd + +touch a +printf '1' >b +printf '22' >c +printf '333' >d +testing "cpio file padding" "cpio -o -H newc|cpio -it" "a\nb\nc\nd\n" "" "a\nb\nc\nd\n" +rm a b c d + +touch a +printf '1' >bb +printf '22' >ccc +printf '333' >dddd +# With the proper padding, header length, and file length, +# the relevant bit should be here: +# 110*5 + 4*3 + 2 + 6*3 = 550 + 12 + 20 = 582 +# files are padded to n*4, names are padded to 2 + n*4 due to the header length +testing "cpio archive length" "cpio -o -H newc|dd ibs=2 skip=291 count=5" "TRAILER!!!" "" "a\nbb\nccc\ndddd\n" +testing "cpio archive magic" "cpio -o -H newc|dd ibs=2 count=3" "070701" "" "a\n" +# check name length (8 bytes before the empty "crc") +testing "cpio name length" "cpio -o -H newc|dd ibs=2 skip=47 count=4" "00000002" "" "a\n" +rm a bb ccc dddd + +# archive dangling symlinks and empty files even if we cannot open them +touch a; chmod a-rwx a; ln -s a/cant b +testing "cpio archives unreadable empty files" "cpio -o -H newc|cpio -it" "a\nb\n" "" "a\nb\n" +chmod u+rw a; rm -f a b + + diff --git a/tests/cut.test b/tests/cut.test new file mode 100644 index 0000000..a001952 --- /dev/null +++ b/tests/cut.test @@ -0,0 +1,47 @@ +#!/bin/bash + +# Copyright 2013 Robin Mittal +# Copyright 2013 Divya Kothari +# Copyright 2013 Kyungwan.Han + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" +#set -x + +# Creating test file for testing cut +echo "one:two:three:four:five:six:seven +alpha:beta:gamma:delta:epsilon:zeta:eta:teta:iota:kappa:lambda:mu +the quick brown fox jumps over the lazy dog" >abc.txt + +testing "cut with -c (a-b)" "cut -c 4-10 abc.txt" ":two:th\nha:beta\n quick \n" "" "" +testing "cut with -f (a-)" "cut -d ':' -f 5- abc.txt" "five:six:seven\nepsilon:zeta:eta:teta:iota:kappa:lambda:mu\nthe quick brown fox jumps over the lazy dog\n" "" "" + +testing "cut with -f (a)" "cut -d ' ' -f 3 abc.txt" "one:two:three:four:five:six:seven\nalpha:beta:gamma:delta:epsilon:zeta:eta:teta:iota:kappa:lambda:mu\nbrown\n" "" "" + +testing "cut with echo, -c (a-b)" "echo 'ref_categorie=test' | cut -c 1-15 " "ref_categorie=t\n" "" "" +testing "cut with echo, -c (a)" "echo 'ref_categorie=test' | cut -c 14" "=\n" "" "" + +# Modifying abc.txt data as per new testcase +echo "abcdefghijklmnopqrstuvwxyz" >abc.txt + +testing "cut with -c (a,b,c)" "cut -c 4,5,20 abc.txt" "det\n" "" "" + +testing "cut with -b (a,b,c)" "cut -b 4,5,20 abc.txt" "det\n" "" "" + +# Modifying abc.txt data as per testcase +echo "406378:Sales:Itorre:Jan +031762:Marketing:Nasium:Jim +636496:Research:Ancholie:Mel +396082:Sales:Jucacion:Ed" >abc.txt + +testing "cut with -d -f(:) -s" "cut -d: -f3 -s abc.txt" "Itorre\nNasium\nAncholie\nJucacion\n" "" "" + +testing "cut with -d -f( ) -s" "cut -d' ' -f3 -s abc.txt && echo yes" "yes\n" "" "" + +testing "cut with -d -f(a) -s" "cut -da -f3 -s abc.txt" "n\nsium:Jim\n\ncion:Ed\n" "" "" + +testing "cut with -d -f(a) -s -n" "cut -da -f3 -s -n abc.txt" "n\nsium:Jim\n\ncion:Ed\n" "" "" + +# Removing abc.txt file for cleanup purpose +rm abc.txt diff --git a/tests/dd.test b/tests/dd.test new file mode 100644 index 0000000..9bdcac5 --- /dev/null +++ b/tests/dd.test @@ -0,0 +1,83 @@ +#!/bin/bash + +# Copyright 2013 Robin Mittal +# Copyright 2013 Divya Kothari + +[ -f testing.sh ] && . testing.sh + +# 'dd' command, stderr prints redirecting to /dev/null +opt="2>/dev/null" + +#testing "name" "command" "result" "infile" "stdin" + +testing "dd if=(file)" "dd if=input $opt" "I WANT\n" "I WANT\n" "" +testing "dd of=(file)" "dd of=file $opt && cat file" "I WANT\n" "" "I WANT\n" +testing "dd if=file of=file" "dd if=input of=foo $opt && cat foo && rm -f foo" \ + "I WANT\n" "I WANT\n" "" +testing "dd if=file | dd of=file" "dd if=input $opt | dd of=foo $opt && + cat foo && rm -f foo" "I WANT\n" "I WANT\n" "" +testing "dd (stdout)" "dd $opt" "I WANT\n" "" "I WANT\n" +testing "dd sync,noerror" \ + "dd if=input of=outFile seek=8860 bs=1M conv=sync,noerror $opt && + stat -c \"%s\" outFile && rm -f outFile" "9291431936\n" "I WANT\n" "" +testing "dd if=file of=(null)" \ + "dd if=input of=/dev/null $opt && echo 'yes'" "yes\n" "I WANT\n" "" +testing "dd with if of bs" \ + "dd if=/dev/zero of=sda.txt bs=512 count=1 $opt && + stat -c '%s' sda.txt && rm -f sda.txt" "512\n" "" "" +testing "dd with if of ibs obs" \ + "dd if=/dev/zero of=sda.txt ibs=512 obs=256 count=1 $opt && + stat -c '%s' sda.txt && rm -f sda.txt" "512\n" "" "" +testing "dd with if of ibs obs count" \ + "dd if=/dev/zero of=sda.txt ibs=512 obs=256 count=3 $opt && + stat -c '%s' sda.txt && rm -f sda.txt" "1536\n" "" "" + +ln -s input softlink +testing "dd if=softlink" "dd if=softlink $opt" "I WANT\n" "I WANT\n" "" +unlink softlink + +ln -s file softlink +testing "dd if=file of=softlink" "dd if=input of=softlink $opt && + [ -f file -a -L softlink ] && cat softlink" "I WANT\n" "I WANT\n" "" +unlink softlink && rm -f file + +testing "dd if=file of=file (same file)" "dd if=input of=input $opt && + [ -f input ] && cat input && echo 'yes'" "yes\n" "I WANT\n" "" + +testing "dd with ibs obs bs" "dd ibs=2 obs=5 bs=9 $opt" "I WANT\n" "" "I WANT\n" +testing "dd with ibs obs bs if" "dd ibs=2 obs=5 bs=9 if=input $opt" \ + "I WANT\n" "I WANT\n" "" + +testing "dd with ibs obs count" "dd ibs=1 obs=1 count=1 $opt" "I" "" "I WANT\n" +testing "dd with ibs obs count if" "dd ibs=1 obs=1 count=3 if=input $opt" \ + "I W" "I WANT\n" "" + +testing "dd with count" "dd count=1 $opt" "I WANT\n" "" "I WANT\n" +testing "dd with count if" "dd count=1 if=input $opt" "I WANT\n" "I WANT\n" "" + +testing "dd with skip" "dd skip=0 $opt" "I WANT\n" "" "I WANT\n" +testing "dd with skip if" "dd skip=0 if=input $opt" "I WANT\n" "I WANT\n" "" + +testing "dd with seek" "dd seek=0 $opt" "I WANT\n" "" "I WANT\n" +testing "dd with seek if" "dd seek=0 if=input $opt" "I WANT\n" "I WANT\n" "" + +# These type of conv is not supported in toybox: 'ascii', 'ebcdic', 'ibm', +# 'block', 'unblock', 'nocreat', 'notronc', 'lcase', 'ucase', 'excl', 'swab' + +# Testing only 'notrunc', 'noerror', 'fsync', 'sync' + +testing "dd conv=notrunc" "dd conv=notrunc $opt" "I WANT\n" "" "I WANT\n" +testing "dd conv=notrunc with IF" "dd conv=notrunc if=input $opt" "I WANT\n" \ + "I WANT\n" "" + +testing "dd conv=noerror" "dd conv=noerror $opt" "I WANT\n" "" "I WANT\n" +testing "dd conv=noerror with IF" "dd conv=noerror if=input $opt" "I WANT\n" \ + "I WANT\n" "" + +testing "dd conv=fsync" "dd conv=fsync $opt" "I WANT\n" "" "I WANT\n" +testing "dd conv=fsync with IF" "dd conv=fsync if=input $opt" "I WANT\n" \ + "I WANT\n" "" + +testing "dd conv=sync" "dd conv=sync $opt | head -n 1" "I WANT\n" "" "I WANT\n" +testing "dd conv=sync with IF" "dd conv=sync if=input $opt | head -n 1" "I WANT\n" \ + "I WANT\n" "" diff --git a/tests/dirname.test b/tests/dirname.test new file mode 100755 index 0000000..a007538 --- /dev/null +++ b/tests/dirname.test @@ -0,0 +1,10 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +testing "dirname /-only" "dirname ///////" "/\n" "" "" +testing "dirname trailing /" "dirname a//////" ".\n" "" "" +testing "dirname combined" "dirname /////a///b///c///d/////" "/////a///b///c\n" "" "" +testing "dirname /a/" "dirname /////a///" "/\n" "" "" diff --git a/tests/du.test b/tests/du.test new file mode 100755 index 0000000..ee4867b --- /dev/null +++ b/tests/du.test @@ -0,0 +1,26 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +# we only test with -k since getting POSIX version is variable +# POSIXLY_CORRECT is sometimes needed, sometimes -P is needed, +# while -k is the default on most Linux systems + +mkdir -p du_test/test du_2/foo +testing "du (no options)" "du -k du_test" "4\tdu_test/test\n8\tdu_test\n" "" "" +testing "du -s" "du -k -s du_test" "8\tdu_test\n" "" "" +ln -s ../du_2 du_test/xyz +# "du shall count the size of the symbolic link" +# I assume this means the space used to store the link name +testing "du counts symlinks without following" "du -ks du_test" "12\tdu_test\n" "" "" +testing "du -L follows symlinks" "du -ksL du_test" "16\tdu_test\n" "" "" +# if -H and -L are specified, the last takes priority +testing "du -HL follows symlinks" "du -ksHL du_test" "16\tdu_test\n" "" "" +testing "du -H does not follow unspecified symlinks" "du -ksH du_test" "12\tdu_test\n" "" "" +testing "du -LH does not follow unspecified symlinks" "du -ksLH du_test" "12\tdu_test\n" "" "" +testing "du -H follows specified symlinks" "du -ksH du_test/xyz" "8\tdu_test/xyz\n" "" "" + +rm -rf du_test du_2 + diff --git a/tests/echo.test b/tests/echo.test new file mode 100755 index 0000000..3f562fd --- /dev/null +++ b/tests/echo.test @@ -0,0 +1,37 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +# This one's tricky both because echo is a shell builtin (so $PATH is +# irrelevant) and because the "result" field is parsed with echo -e. +# To make it work, "$CMD" is an explicit path to the command being tested, +# so "result" keeps using the shell builtin but we test the one in toybox. + +CMD="$(which echo)" + +#testing "name" "command" "result" "infile" "stdin" + +testing "echo" "$CMD && echo yes" "\nyes\n" "" "" +testing "echo 1 2 3" "$CMD one two three" "one two three\n" "" "" +testing "echo with spaces" "$CMD 'one two three'" \ + "one two three\n" "" "" +testing "echo -n" "$CMD -n" "" "" "" +testing "echo -n one" "$CMD -n one" "one" "" "" +testing "echo one -n" "$CMD one -n" "one -n\n" "" "" +testing "echo -en" "$CMD -en 'one\ntwo'" "one\ntwo" "" "" +testing "echo --hello" "$CMD --hello" "--hello\n" "" "" +testing "echo -e all" "$CMD -e '\a\b\c\f\n\r\t\v\\\0123'" \ + "\a\b\c\f\n\r\t\v\\\0123\n" "" "" +testing "echo -nex hello" "$CMD -nex hello" "-nex hello\n" "" "" + +# Octal formatting tests +testing "echo -e octal values" \ + "$CMD -ne '\01234 \0060 \060 \0130\0131\0132 \077\012'" \ + "S4 0 0 XYZ ?\n" "" "" + +# Hexadecimal value tests +testing "echo -e hexadecimal values" \ + "$CMD -ne '\x534 \x30 \x58\x59\x5a \x3F\x0A'"\ + "S4 0 XYZ ?\n" "" "" + +testing "echo -e \p" "$CMD -e '\\p'" "\\p\n" "" "" diff --git a/tests/expand.test b/tests/expand.test new file mode 100755 index 0000000..510f89f --- /dev/null +++ b/tests/expand.test @@ -0,0 +1,44 @@ +#!/bin/bash + +# POSIX 2008 compliant expand tests. +# Copyright 2012 by Jonathan Clairembault + +[ -f testing.sh ] && . testing.sh + +# some basic tests + +testing "expand default" "expand input" " foo bar\n" "\tfoo\tbar\n" "" +testing "expand default stdin" "expand" " foo bar\n" "" "\tfoo\tbar\n" +testing "expand single" "expand -t 2 input" " foo bar\n" "\tfoo\tbar\n" "" +testing "expand tablist" "expand -t 5,10,12 input" " foo bar foo\n" "\tfoo\tbar\tfoo\n" "" +testing "expand backspace" "expand input" "foobarfoo\b\b bar\n" "foobarfoo\b\b\tbar\n" "" + +# advanced tests + +POW=15 +TABSTOP=1 +BIGTAB=" " +for i in $(seq $POW); do + BIGTAB=$BIGTAB$BIGTAB + TABSTOP=$[$TABSTOP*2] +done +testing "expand long tab single" "expand -t $TABSTOP input" "${BIGTAB}foo\n" "\tfoo\n" "" +testing "expand long tab tablist" "expand -t $TABSTOP,$[TABSTOP+5] input" \ + "${BIGTAB}foo bar\n" "\tfoo\tbar\n" "" + +testing "expand multiline single" "expand -t 4 input" "foo \n bar\n" "foo\t\n\tbar\n" "" +testing "expand multiline tablist" "expand -t 4,8 input" \ + "foo bar\n bar foo\n" "foo\t\tbar\n\tbar\tfoo\n" "" +POW=15 +BIGLINE="foo " +for i in $(seq $POW); do + BIGLINE=$BIGLINE$BIGLINE +done +if [ $POW -gt 0 ]; then + EXPANDLINE="${BIGLINE} foo\n" +else + EXPANDLINE="${BIGLINE} foo\n" +fi +BIGLINE="${BIGLINE}\tfoo\n" +testing "expand long line single" "expand input" \ + "${EXPANDLINE}" "$BIGLINE" "" diff --git a/tests/expr.test b/tests/expr.test new file mode 100644 index 0000000..cce7d9d --- /dev/null +++ b/tests/expr.test @@ -0,0 +1,10 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +testing "expr integer" "expr 5" "5\n" "" "" +testing "expr integer negative" "expr -5" "-5\n" "" "" +testing "expr string" "expr astring" "astring\n" "" "" +testing "expr 1 + 3" "expr 1 + 3" "4\n" "" "" +testing "expr 5 + 6 * 3" "expr 5 + 6 \* 3" "23\n" "" "" +testing "expr ( 5 + 6 ) * 3" "expr \( 5 + 6 \) \* 3" "33\n" "" "" diff --git a/tests/factor.test b/tests/factor.test new file mode 100755 index 0000000..a3e4cbf --- /dev/null +++ b/tests/factor.test @@ -0,0 +1,18 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +testing "factor -32" "factor -32" "-32: -1 2 2 2 2 2\n" "" "" +testing "factor 0" "factor 0" "0: 0\n" "" "" +testing "factor 1" "factor 1" "1: 1\n" "" "" +testing "factor 2" "factor 2" "2: 2\n" "" "" +testing "factor 3" "factor 3" "3: 3\n" "" "" +testing "factor 4" "factor 4" "4: 2 2\n" "" "" +testing "factor 10000000017" "factor 10000000017" \ + "10000000017: 3 3 3 7 7 7 1079797\n" "" "" +testing "factor 10000000018" "factor 10000000018" \ + "10000000018: 2 131 521 73259\n" "" "" +testing "factor 10000000019" "factor 10000000019" \ + "10000000019: 10000000019\n" "" "" diff --git a/tests/find.test b/tests/find.test new file mode 100644 index 0000000..cbbce5f --- /dev/null +++ b/tests/find.test @@ -0,0 +1,42 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +mkdir dir +cd dir +touch file +mkfifo fifo +ln -s fifo link +cd .. + +#testing "name" "command" "result" "infile" "stdin" + +# Testing operators + +testing "find -type l -a -type d -o -type p" \ + "find dir -type l -a -type d -o -type p" "dir/fifo\n" "" "" +testing "find -type l -type d -o -type p" "find dir -type l -type d -o -type p" \ + "dir/fifo\n" "" "" +testing "find -type l -o -type d -a -type p" \ + "find dir -type l -o -type d -a -type p" "dir/link\n" "" "" +testing "find -type l -o -type d -type p" "find dir -type l -o -type d -type p" \ + "dir/link\n" "" "" +testing "find -type l ( -type d -o -type l )" \ + "find dir -type l \( -type d -o -type l \)" "dir/link\n" "" "" +testing "find extra parantheses" \ + "find dir \( \( -type l \) \( -type d -o \( \( -type l \) \) \) \)" \ + "dir/link\n" "" "" +testing "find ( -type p -o -type d ) -type p" \ + "find dir \( -type p -o -type d \) -type p" "dir/fifo\n" "" "" +testing "find -type l -o -type d -type p -o -type f" \ + "find dir -type l -o -type d -type p -o -type f | sort" \ + "dir/file\ndir/link\n" "" "" + +# Testing short-circuit evaluations + +testing "find -type f -a -print" \ + "find dir -type f -a -print" "dir/file\n" "" "" +testing "find -print -o -print" \ + "find dir -type f -a \( -print -o -print \)" "dir/file\n" "" "" + +rm -rf dir diff --git a/tests/grep.test b/tests/grep.test new file mode 100755 index 0000000..13b1af7 --- /dev/null +++ b/tests/grep.test @@ -0,0 +1,98 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +# Copyright 2013 by Kyungsu Kim +# Copyright 2013 by Kyungwan Han + +#testing "name" "command" "result" "infile" "stdin" + +testing "grep -c" "grep -c 123 input" "3\n" "123\ncount 123\n123\nfasdfasdf" "" + +echo -e "this is test" > foo +echo -e "this is test2" > foo2 +echo -e "this is foo3" > foo3 +testing "grep -l" "grep -l test foo foo2 foo3" "foo\nfoo2\n" "" "" +rm foo foo2 foo3 + +testing "grep -q" "grep -q test input && echo yes" "yes\n" "this is a test\n" "" +testing "grep -E" "grep -E '[0-9]' input" "1234123asdfas123123\n1\n" \ + "1234123asdfas123123\nabc\n1\nabcde" "" +testing "grep -e" "grep -e '[0-9]' input" "1234123asdfas123123\n1\n" \ + "1234123asdfas123123\nabc\n1\nabcde" "" +testing "grep -e -e" "grep -e one -e two -e three input" \ + "two\ntwo\nthree\none\n" "two\ntwo\nthree\nand\none\n" "" +testing "grep -F" "grep -F is input" "this is test\nthis is test2\n" \ + "this is test\nthis is test2\ntest case" "" + +echo -e "this is test\nthis is test2\ntest case" > foo +echo -e "hello this is test" > foo2 +echo -e "hi hello" > foo3 +testing "grep -H" "grep -H is foo foo2 foo3" "foo:this is test\nfoo:this is test2\nfoo2:hello this is test\n" "" "" +rm foo foo2 foo3 + +testing "grep -b" "grep -b is input" "0:this is test\n13:this is test2\n" \ + "this is test\nthis is test2\ntest case" "" +testing "grep -i" "grep -i is input" "thisIs test\nthis is test2\n" \ + "thisIs test\nthis is test2\ntest case" "" +testing "grep -n" "grep -n is input" "1:this is test\n2:this is test2\n" \ + "this is test\nthis is test2\ntest case" "" +testing "grep -o" "grep -o is input" "is\nis\nis\nis\n" \ + "this is test\nthis is test2\ntest case" "" +testing "grep -s" "grep -hs hello asdf input 2>&1" "hello\n" "hello\n" "" +testing "grep -v" "grep -v abc input" "1234123asdfas123123\n1ABa\n" \ + "1234123asdfas123123\n1ABabc\nabc\n1ABa\nabcde" "" +testing "grep -w" "grep -w abc input" "abc\n" \ + "1234123asdfas123123\n1ABabc\nabc\n1ABa\nabcde" "" +testing "grep -x" "grep -x abc input" "abc\n" \ + "aabcc\nabc\n" "" + +testing "grep -H (standard input)" "grep -H abc" "(standard input):abc\n" \ + "" "abc\n" +testing "grep -l (standard input)" "grep -l abc" "(standard input)\n" \ + "" "abc\n" +testing "grep -n two inputs" "grep -hn def - input" "2:def\n2:def\n" \ + "abc\ndef\n" "abc\ndef\n" + +testing "grep pattern with newline" "grep 'abc +def' input" "aabcc\nddeff\n" \ + "aaaa\naabcc\n\dddd\nddeff\nffff\n" "" + +testing "grep -lH" "grep -lH abc input" "input\n" "abc\n" "" +testing "grep -cn" "grep -cn abc input" "1\n" "abc\n" "" +testing "grep -qs" "grep -qs abc none input && echo yes" "yes\n" "abc\n" "" +testing "grep -hl" "grep -hl abc input" "input\n" "abc\n" "" +testing "grep -b stdin" "grep -b one" "0:one\n4:one\n8:one\n" "" "one\none\none\n" +testing "grep -o overlap" "grep -bo aaa" "1:aaa\n" "" "baaaa\n" +# nonobvious: -co counts lines, not matches +testing "grep -co" "grep -co one input" "1\n" "one one one\n" "" +testing "grep -nom" "grep -nom 2 one" "1:one\n1:one\n1:one\n2:one\n2:one\n" \ + "" "one one one\none one\none" +testing "grep -vo" "grep -vo one input" "two\nthree\n" "onetwoonethreeone\n" "" +testing "grep no newline" "grep -h one input -" \ + "hello one\nthere one\n" "hello one" "there one" + +testing "grep -e multi" "grep -e one -ethree input" \ + "three\none\n" "three\ntwo\none\n" "" +# Suppress filenames for recursive test because dunno order they'd occur in +mkdir sub +echo -e "one\ntwo\nthree" > sub/one +echo -e "three\ntwo\none" > sub/two +testing "grep -hr" "grep -hr one sub" "one\none\n" "" "" +testing "grep -r file" "grep -r three sub/two" "three\n" "" "" +testing "grep -r dir" "grep -r one sub | sort" "sub/one:one\nsub/two:one\n" \ + "" "" +rm -rf sub + +# Not sure if -Fx '' should do? Posix is unclear, '' match every line but does +# it match every _byte_ in that line? +testing "grep -Fx ''" "grep -Fx '' input" "one one one\n" "one one one\n" "" +testing "grep -F ''" "grep -F '' input" "one one one\n" "one one one\n" "" +testing "grep -F -e blah -e ''" "grep -F -e blah -e '' input" "one one one\n" \ + "one one one\n" "" +testing "grep -e blah -e ''" "grep -e blah -e '' input" "one one one\n" \ + "one one one\n" "" +testing "grep -w ''" "grep -w '' input" "" "one one one\n" "" +testing "grep -o ''" "grep -o '' input" "" "one one one\n" "" +testing "grep backref" 'grep -e "a\(b\)" -e "b\(c\)\1"' "bcc\nab\n" \ + "" "bcc\nbcb\nab\n" diff --git a/tests/groupadd.test b/tests/groupadd.test new file mode 100644 index 0000000..0395e01 --- /dev/null +++ b/tests/groupadd.test @@ -0,0 +1,56 @@ +#!/bin/bash +# Copyright 2013 Divya Kothari +# Copyright 2013 Robin Mittal + +[ -f testing.sh ] && . testing.sh + +# 70 characters long string; hereafter, we will use it as per our need. +_s70="abcdefghijklmnopqrstuvwxyz123456789abcdefghijklmnopqrstuvwxyz123456789" + +echo "# usage: addgroup [-g GID] [USER] GROUP +# Add a group or add a user to a group." + +# Redirecting all output to /dev/null for grep and delgroup +arg="&>/dev/null" + +#testing "name" "command" "result" "infile" "stdin" + +testing "groupadd group_name (text)" "groupadd toyTestGroup && + grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg && + echo 'yes'" "yes\n" "" "" +testing "groupadd group_name (alphanumeric)" "groupadd toy1Test2Group3 && + grep '^toy1Test2Group3:' /etc/group $arg && groupdel toy1Test2Group3 $arg && + echo 'yes'" "yes\n" "" "" +testing "groupadd group_name (numeric)" "groupadd 987654321 && + grep '^987654321:' /etc/group $arg && groupdel 987654321 $arg && + echo 'yes'" "yes\n" "" "" +testing "groupadd group_name (with ./-)" "groupadd toy.1Test-2Group.3 && + grep '^toy.1Test-2Group.3:' /etc/group $arg && + groupdel toy.1Test-2Group.3 $arg && echo 'yes'" "yes\n" "" "" + +_s210=`echo $_s70$_s70$_s70` +testing "groupadd group_name (long string)" "groupadd $_s210 && + grep '^$_s210:' /etc/group $arg && groupdel $_s210 $arg && echo 'yes'" \ + "yes\n" "" "" +testing "groupadd group_name with group_id" "groupadd -g 49999 toyTestGroup && + grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg && + echo 'yes'" "yes\n" "" "" +testing "groupadd group_name with group_id (system_group)" \ + "groupadd -g 49999 -S toyTestGroup && grep '^toyTestGroup:' /etc/group $arg && + groupdel toyTestGroup $arg && echo 'yes'" "yes\n" "" "" +testing "groupadd group_name (system_group)" "groupadd -S toyTestGroup && + grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg && + echo 'yes'" "yes\n" "" "" +testing "groupadd group_name (add/del user)" "groupadd toyTestGroup && + grep '^toyTestGroup:' /etc/group $arg && groupadd $USER toyTestGroup && + grep '^toyTestGroup:.*:.*:.*$USER.*' /etc/group $arg && + groupdel $USER toyTestGroup $arg || groupdel toyTestGroup && + grep '^toyTestGroup:' /etc/group $arg || echo 'yes'" "yes\n" "" "" + + echo "Testing to add single group multiple times after removing it..." + for each in {01..20} + do + testing "groupadd group_name ($each)" "groupadd toyTestGroup && + grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg && + echo 'yes'" "yes\n" "" "" + done diff --git a/tests/groupdel.test b/tests/groupdel.test new file mode 100644 index 0000000..d46db53 --- /dev/null +++ b/tests/groupdel.test @@ -0,0 +1,27 @@ +#!/bin/bash + +# Copyright 2013 Divya Kothari +# Copyright 2013 Robin Mittal + +[ -f testing.sh ] && . testing.sh + +# Redirecting all output to /dev/null for grep and delgroup +arg="&>/dev/null" + +#testing "name" "command" "result" "infile" "stdin" + +testing "groupadd group_name (text)" "groupadd toyTestGroup && + grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg && + echo 'yes'" "yes\n" "" "" +testing "groupadd group_name (alphanumeric)" "groupadd toy1Test2Group3 && + grep '^toy1Test2Group3:' /etc/group $arg && groupdel toy1Test2Group3 $arg && + echo 'yes'" "yes\n" "" "" +testing "groupadd group_name (numeric)" "groupadd 987654321 && + grep '^987654321:' /etc/group $arg && groupdel 987654321 $arg && + echo 'yes'" "yes\n" "" "" +testing "groupadd group_name (with ./-)" "groupadd toy.1Test-2Group.3 && + grep '^toy.1Test-2Group.3:' /etc/group $arg && + groupdel toy.1Test-2Group.3 $arg && echo 'yes'" "yes\n" "" "" +testing "groupadd group_name with group_id" "groupadd -g 49999 toyTestGroup && + grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg && + echo 'yes'" "yes\n" "" "" diff --git a/tests/head.test b/tests/head.test new file mode 100755 index 0000000..eeb07e0 --- /dev/null +++ b/tests/head.test @@ -0,0 +1,17 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +testing "head, stdin" "head -n 1 && echo yes" "one\nyes\n" "" "one\ntwo" +testing "head, stdin via -" "head -n 1 - && echo yes" "one\nyes\n" "" "one\ntwo" +testing "head, file" "head input -n 1 && echo yes" "one\nyes\n" "one\ntwo" "" +testing "head, default lines" "head" "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" "" "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12" + +echo "foo +bar +baz" > file1 +testing "head, multiple files" "head -n 2 input file1" "==> input <==\none\ntwo\n\n==> file1 <==\nfoo\nbar\n" "one\ntwo\nthree\n" "" +rm file1 + diff --git a/tests/hostname.test b/tests/hostname.test new file mode 100644 index 0000000..1194845 --- /dev/null +++ b/tests/hostname.test @@ -0,0 +1,18 @@ +#!/bin/bash + +# Copyright 2014 Divya Kothari +# Copyright 2014 Naha Maggu + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +# Get system hostname +hostnameExe=`which hostname` +hostnameOut=`$hostnameExe` + +# New hostname +NewHostname="NewHostName.system" + +testing "Hostname - Get" "hostname" "$hostnameOut\n" "" "" +testing "Hostname - Set, Get and then Reset" "hostname $NewHostname; hostname; hostname $hostnameOut; hostname" "$NewHostname\n$hostnameOut\n" "" "" diff --git a/tests/link.test b/tests/link.test new file mode 100755 index 0000000..769a7b6 --- /dev/null +++ b/tests/link.test @@ -0,0 +1,26 @@ +#!/bin/bash + +# Copyright 2014 Divya Kothari +# Copyright 2014 Naha Maggu + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +echo "" >foo +testing "link fails on non-existent file" "link foo/foo baz || echo GOOD" "GOOD\n" "" "" +rm -f foo bar + +echo file1 > file +testing "ln create_hardlink" "link file hlink && [ file -ef hlink ] && + echo 'yes'; rm -rf hlink" "yes\n" "" "" + +echo hlink1 > hlink +set +e +testing "ln preserves_hardlinks" "link file hlink 2>/dev/null || echo 'yes'; rm -rf hlink" \ + "yes\n" "" "" + +echo file1 > file +testing "ln create_hardlink_and_remove_sourcefile" "link file hlink && + [ file -ef hlink ] && rm -rf file && [ -f hlink ] && echo 'yes'; rm -f file hlink" \ + "yes\n" "" "" diff --git a/tests/ln.test b/tests/ln.test new file mode 100644 index 0000000..aea3ab0 --- /dev/null +++ b/tests/ln.test @@ -0,0 +1,70 @@ +#!/bin/bash + +# Copyright 2013 Robin Mittal +# Copyright 2013 Divya Kothari + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" +#set -x + +echo file1 > file +testing "ln create_hardlink" "ln file hlink && [ file -ef hlink ] && + echo 'yes'" "yes\n" "" "" +testing "ln create_softlink" "ln -s file slink && [ -L slink ] && + readlink slink" "file\n" "" "" +rm slink hlink + +echo hlink1 > hlink +testing "ln force_create_hardlink" "ln -f file hlink && + [ file -ef hlink ] && cat hlink 2>/dev/null" "file1\n" "" "" + +echo slink1 > slink +testing "ln force_create_softlink" "ln -f -s file slink && + [ -L slink ] && readlink slink" "file\n" "" "" +rm slink hlink + +echo hlink1 > hlink +set +e +testing "ln preserves_hardlinks" "ln file hlink 2>/dev/null || echo 'yes'" \ + "yes\n" "" "" + +echo slink1 > slink +set +e +testing "ln preserves_softlinks" "ln -s file slink 2>/dev/null || echo 'yes'" \ + "yes\n" "" "" +rm slink hlink + +mkdir dir +testing "ln multilevel_symbolic_links" "ln -s dir slink && + ln -s file slink && [ -L slink -a -L slink/file ] && + readlink slink && readlink slink/file" "dir\nfile\n" "" "" +rm slink + +testing "ln no_dereference" "ln -s dir slink && + ln -n -s file slink 2>/dev/null || [ -L slink ] && readlink slink" \ + "dir\n" "" "" +rm -rf file dir slink + +touch file1 file2 && mkdir dir +testing "ln create_multiple_hardlinks" "ln file* dir/ && + [ file1 -ef dir/file1 -a file2 -ef dir/file2 ] && echo 'yes'" "yes\n" "" "" +rm -rf file* dir + +touch file1 file2 && mkdir dir +testing "ln create_multiple_softlinks" "ln -s file* dir/ && + [ -L dir/file1 -a -L dir/file2 ] && readlink dir/file1 && + readlink dir/file2" "file1\nfile2\n" "" "" +rm -rf file* dir + +echo file1 > file +testing "ln create_softlink_and_remove_sourcefile" "ln -s file slink && + [ -L slink ] && rm file && cat slink 2>/dev/null || echo 'yes' " \ + "yes\n" "" "" +rm -f file slink + +echo file1 > file +testing "ln create_hardlink_and_remove_sourcefile" "ln file hlink && + [ file -ef hlink ] && rm file && [ -f hlink ] && echo 'yes'" \ + "yes\n" "" "" +rm -f file hlink diff --git a/tests/losetup.test b/tests/losetup.test new file mode 100755 index 0000000..fe1e520 --- /dev/null +++ b/tests/losetup.test @@ -0,0 +1,46 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +if [ "$(id -u)" -ne 0 ] +then + echo "SKIPPED: losetup (not root)" + continue 2>/dev/null + exit +fi + +#testing "name" "command" "result" "infile" "stdin" + +truncate -s 1M blah.img && +FILE="$(readlink -f blah.img)" +DEV="$(printf '%04d' $(stat -t blah.img | awk '{print $7}'))" +NODE="$(awk '{print $7}')" + +losetup -f +losetup -f -s +losetup -f file +testing "cat" "cat && echo yes" "oneyes\n" "" "one" +testing "cat -" "cat - && echo yes" "oneyes\n" "" "one" +testing "cat file1 file2" "cat file1 file2" "one\ntwo\n" "" "" +testing "cat - file" "cat - file1" "zero\none\n" "" "zero\n" +testing "cat file -" "cat file1 -" "one\nzero\n" "" "zero\n" + +testing "cat file1 notfound file2" \ + "cat file1 notfound file2 2>stderr && echo ok ; cat stderr; rm stderr" \ + "one\ntwo\ncat: notfound: No such file or directory\n" "" "" + +testing "cat file1" \ + "cat /proc/self/exe > file1 && cmp /proc/self/exe file1 && echo yes" \ + "yes\n" "" "" + +testing "cat - file1" \ + "cat - file1 | diff -a -U 0 - file1 | tail -n 1" \ + "-hello\n" "" "hello\n" + +testing "cat > /dev/full" \ + "cat - > /dev/full 2>stderr && echo ok; cat stderr; rm stderr" \ + "cat: xwrite: No space left on device\n" "" "zero\n" + +losetup -d + +rm blah.img diff --git a/tests/ls.test b/tests/ls.test new file mode 100644 index 0000000..d052f13 --- /dev/null +++ b/tests/ls.test @@ -0,0 +1,49 @@ +#!/bin/bash + +# Copyright 2013 Robin Mittal +# Copyright 2013 Divya Kothari + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" +#set -x + +# Creating test-file/dir for testing ls +mkdir -p lstest/dir1 lstest/dir2 || exit 1 +echo "test file1" > lstest/file1.txt +echo "test file2" > lstest/file2.txt +echo "hidden file1" > lstest/.hfile1 + +IN="cd lstest" +OUT="cd .. " + +testing "ls no argument" "$IN && ls; $OUT" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" "" +testing "ls with wild char" "$IN && ls file*; $OUT" "file1.txt\nfile2.txt\n" "" "" +testing "ls with wild char - long listing" "$IN && ls -1 file*; $OUT" "file1.txt\nfile2.txt\n" "" "" +testing "ls with -p" "$IN && ls -p; $OUT" "dir1/\ndir2/\nfile1.txt\nfile2.txt\n" "" "" +testing "ls with -a" "$IN && ls -a; $OUT" \ + ".\n..\ndir1\ndir2\nfile1.txt\nfile2.txt\n.hfile1\n" "" "" +testing "ls with -A" "$IN && ls -A; $OUT" \ + "dir1\ndir2\nfile1.txt\nfile2.txt\n.hfile1\n" "" "" +testing "ls with -d" "$IN && ls -d; $OUT" ".\n" "" "" +testing "ls with wild char and -d *" "$IN && ls -d *; $OUT" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" "" +testing "ls with -k" "$IN && ls -k; $OUT" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" "" +testing "ls with -m" "$IN && ls -m; $OUT" "dir1, dir2, file1.txt, file2.txt\n" "" "" +testing "ls with -F" "$IN && ls -F; $OUT" "dir1/\ndir2/\nfile1.txt\nfile2.txt\n" "" "" +testing "ls with -dk *" "$IN && ls -dk *; $OUT" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" "" + +ln -s file1.txt lstest/slink +testing "ls softlink - long listing" "$IN && ls -l slink | awk '{ print \$NF }' ; $OUT" \ + "file1.txt\n" "" "" +rm -f lstest/slink + +rm -rf lstest/* && mkdir -p lstest/dir1 && touch lstest/file1.txt +testing "ls nested recursively" "$IN && ls -R; $OUT" \ + ".:\ndir1\nfile1.txt\n\n./dir1:\n" "" "" + +rm -rf lstest/* && touch lstest/file1.txt && INODE=`stat -c %i lstest/file1.txt` +testing "ls with -i" "$IN && ls -i 2>/dev/null; $OUT" "$INODE file1.txt\n" "" "" +unset INODE + +# Removing test dir for cleanup purpose +rm -rf lstest diff --git a/tests/lsattr.test b/tests/lsattr.test new file mode 100644 index 0000000..870b3f6 --- /dev/null +++ b/tests/lsattr.test @@ -0,0 +1,159 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +# chattr - Testcases + +mkdir testattr +IN="cd testattr" +OUT="cd .." +_t="abcdefghijklmnopqrstuvwxyz" + +testing "chattr [-/+]i FILE[write]" "$IN && echo "$_t" > testFile && + chattr +i testFile && lsattr testFile && echo "$_t" > testFile; + chattr -i testFile; rm -rf testFile; $OUT " "----i-------- testFile\n" "" "" +testing "chattr [-/+]i FILE[re-write]" "$IN && echo "$_t" > testFile && + chattr +i testFile && echo \"$_t\" > testFile || chattr -i testFile && + echo \"$_t\" > testFile && lsattr testFile; rm -rf testFile; $OUT" \ + "------------- testFile\n" "" "" +testing "chattr [-/+]i FILE[append]" "$IN && echo "$_t" > testFile && + chattr +i testFile && echo \"$_t\" >> testFile || lsattr testFile && + chattr -i testFile; rm -rf testFile; $OUT" "----i-------- testFile\n" "" "" +testing "chattr [-/+]i FILE[move]" "$IN && echo "$_t" > testFile && + chattr +i testFile && mv testFile testFile1 || lsattr testFile && + chattr -i testFile; rm -rf testFile; $OUT" "----i-------- testFile\n" "" "" +testing "chattr [-/+]i FILE[delete]" "$IN && echo "$_t" > testFile && + chattr +i testFile && rm -f testFile || lsattr testFile && + chattr -i testFile; rm -rf testFile; $OUT" "----i-------- testFile\n" "" "" +testing "chattr [-/+]i FILE[read]" "$IN && echo "$_t" > testFile && + chattr +i testFile && cat testFile && lsattr testFile && + chattr -i testFile; rm -rf testFile; $OUT" "$_t\n----i-------- testFile\n" "" "" +testing "chattr [-/+]a FILE[write]" "$IN && echo "$_t" > testFile && + chattr +a testFile && echo $_t > testFile || lsattr testFile && + chattr -a testFile; rm -rf testFile; $OUT" "-----a------- testFile\n" "" "" +testing "chattr [-/+]a FILE[re-write]" "$IN && echo "$_t" > testFile && + chattr +a testFile && echo $_t > testFile || lsattr testFile && + chattr -a testFile && echo $_t > testFile && cat testFile && + lsattr testFile; rm -rf testFile; + $OUT" "-----a------- testFile\n$_t\n------------- testFile\n" "" "" +testing "chattr [-/+]a FILE[append]" "$IN && echo "$_t" > testFile && + chattr +a testFile && echo $_t >> testFile && cat testFile && + lsattr testFile && chattr -a testFile; rm -rf testFile; $OUT" \ + "$_t\n$_t\n-----a------- testFile\n" "" "" +testing "chattr [-/+]a FILE[move]" "$IN && echo "$_t" > testFile && + chattr +a testFile && mv testFile testFile1 || lsattr testFile && + chattr -a testFile; rm -rf testFile; $OUT" "-----a------- testFile\n" "" "" +testing "chattr [-/+]a FILE[delete]" "$IN && echo "$_t" > testFile && + chattr +a testFile && rm -f testFile || lsattr testFile && + chattr -a testFile; rm -rf testFile; $OUT" "-----a------- testFile\n" "" "" +testing "chattr [-/+]a FILE[read]" "$IN && echo "$_t" > testFile && + chattr +a testFile && cat testFile && lsattr testFile && chattr -a testFile; + rm -rf testFile; $OUT" "$_t\n-----a------- testFile\n" "" "" + +for attr in "A" "a" "c" "D" "d" "i" "j" "s" "S" "t" "T" "u" +do + testing "chattr [-/+]$attr FILE" "$IN && echo "$_t" > testFile && + chattr +$attr testFile && cat testFile && chattr -$attr testFile && + lsattr testFile; rm -rf testFile; $OUT" "$_t\n------------- testFile\n" "" "" +done + +for attr in "A" "a" "c" "D" "d" "i" "j" "s" "S" "t" "T" "u" +do + testing "chattr -$attr FILE" "$IN && echo "$_t" > testFile && chattr -$attr testFile && + cat testFile && lsattr testFile; rm -rf testFile; $OUT" "$_t\n------------- testFile\n" "" "" +done + +testing "chattr [-/+]AacDdijsStTu FILE" "$IN && echo "$_t" > testFile && + chattr +AacDdijsStTu testFile && cat testFile && chattr -AacDdijsStTu testFile && + lsattr testFile; rm -rf testFile; $OUT" "$_t\n------------- testFile\n" "" "" +testing "chattr [-/+]AacDdijsStTu(random) FILE" \ + "$IN && echo "$_t" > testFile && + chattr +AacDdijsStTu testFile && cat testFile && chattr -A testFile && + chattr -a testFile && chattr -c testFile && chattr -D testFile && + chattr -d testFile && chattr -i testFile && chattr -j testFile && + chattr -s testFile && chattr -S testFile && chattr -t testFile && + chattr -T testFile && chattr -u testFile && lsattr testFile && + chattr -AacDdijsStTu testFile; rm -rf testFile; $OUT" \ + "$_t\n------------- testFile\n" "" "" +testing "chattr [-/+]AacDdijsStTu FILE*" "$IN && + echo "$_t" > testFile && echo "$_t" > testFile1 && + echo "$_t" > testFile2 && echo "$_t" > testFile3 && + echo "$_t" > testFile4 && echo "$_t" > testFile5 && + echo "$_t" > testFile6 && echo "$_t" > testFile7 && + echo "$_t" > testFile8 && echo "$_t" > testFile9 && + echo "$_t" > testFile10 && echo "$_t" > testFile11 && + chattr +AacDdijsStTu testFile* && + cat testFile9 && chattr -AacDdijsStTu testFile* && lsattr testFile*; rm -rf testFile*; $OUT" \ + "$_t\n------------- testFile\n------------- testFile1\n------------- testFile10\n------------- testFile11\n------------- testFile2\n------------- testFile3\n------------- testFile4\n------------- testFile5\n------------- testFile6\n------------- testFile7\n------------- testFile8\n------------- testFile9\n" "" "" +testing "chattr [-/+]AacDdijsStTu(random) FILE*" \ + "$IN && echo "$_t" > testFile && + chattr +AacDdijsStTu testFile* && cat testFile && chattr -A testFile* && + chattr -a testFile* && chattr -c testFile* && chattr -D testFile* && + chattr -d testFile* && chattr -i testFile* && chattr -j testFile* && + chattr -s testFile* && chattr -S testFile* && chattr -t testFile* && + chattr -T testFile* && chattr -u testFile* && lsattr testFile; + rm -rf testFile; $OUT" \ + "$_t\n------------- testFile\n" "" "" +testing "chattr [-/+]i FILE[write]" \ + "$IN && echo "$_t" > testFile && + chattr +i testFile && + echo \"$_t\" > testFile || lsattr testFile && chattr -i testFile; + rm -rf testFile; $OUT" "----i-------- testFile\n" "" "" +testing "chattr [-/+]A FILE[write]" \ + "$IN && echo "$_t" > testFile && chattr +A testFile && + echo \"$_t\" > testFile && lsattr testFile && chattr -A testFile; + rm -rf testFile; $OUT" "-------A----- testFile\n" "" "" +testing "chattr [-/+]s FILE[write]" \ + "$IN && echo "$_t" > testFile && chattr +s testFile && + echo \"$_t\" > testFile && lsattr testFile && chattr -s testFile + rm -rf testFile; $OUT" "s------------ testFile\n" "" "" +testing "chattr -v version FILE[write]" \ + "$IN && echo "$_t" > testFile && + chattr -v 1234 testFile && echo \"$_t\" > testFile && + lsattr -v testFile; rm -rf testFile" \ + " 1234 ------------- testFile\n" "" "" + +_a="-------A-----" +testing "chattr -R [-/+]a FILE" "$IN && touch aa && chattr -R +A aa && lsattr aa && + chattr -R -A aa; rm -rf aa; $OUT" "$_a aa\n" "" "" +testing "chattr -R [-/+]a FILE.." "$IN && touch aa bb && + chattr -R +A aa bb && lsattr aa bb && + chattr -R -A aa bb; rm -rf aa bb; $OUT" "$_a aa\n$_a bb\n" "" "" + +# Clean up +rm -rf testattr + +# lsattr - Testcases +mkdir dir && cd dir && touch file +chattr +A file &>/dev/null + +_p=$PWD +_b="-------------" +_A="-------A-----" + +testing "lsattr file" "lsattr file" "$_A file\n" "" "" +testing "lsattr file_path" "lsattr $_p/file" "$_A $_p/file\n" "" "" +testing "lsattr -R file" "lsattr -R file" "$_A file\n" "" "" +testing "lsattr -R file_path" "lsattr -R $_p/file" "$_A $_p/file\n" "" "" +testing "lsattr -a file" "lsattr -a file" "$_A file\n" "" "" +testing "lsattr -a file_path" "lsattr -a $_p/file" "$_A $_p/file\n" "" "" +testing "lsattr -d ." "lsattr -d ." "$_b .\n" "" "" +testing "lsattr -d dir_path" "lsattr -d $_p" "$_b $_p\n" "" "" +testing "lsattr -d file" "lsattr -d file" "$_A file\n" "" "" +testing "lsattr -d file_path" "lsattr -d $_p/file" "$_A $_p/file\n" "" "" +sp_44=" " +testing "lsattr -l file" "lsattr -l file" "file $sp_44 No_Atime\n" "" "" +_v="12345" +testing "lsattr -v file" "chattr -v $_v * && lsattr -v file" \ + "$_v $_A file\n" "" "" +testing "lsattr -v file_path" "chattr -v $_v * && lsattr -v $_p/file" \ + "$_v $_A $_p/file\n" "" "" +testing "lsattr -Radlv file1 file2" "chattr -v $_v * && + lsattr -Radlv file input" \ + "$_v file $sp_44 No_Atime\n$_v input $sp_44 ---\n" "" "" + +# Cleanup +chattr -AacDdijsStTu file && cd .. +rm -rf dir diff --git a/tests/md5sum.test b/tests/md5sum.test new file mode 100755 index 0000000..741ec62 --- /dev/null +++ b/tests/md5sum.test @@ -0,0 +1,22 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +# These tests are from RFC 1321 appendix 5, reshuffled slightly to test +# varying argument numbers + +testing "md5sum ''" "md5sum" "d41d8cd98f00b204e9800998ecf8427e -\n" "" "" +testing "md5sum infile" "md5sum input" \ + "0cc175b9c0f1b6a831c399e269772661 input\n" "a" "" +testing "md5sum two files" "md5sum - input" \ + "900150983cd24fb0d6963f7d28e17f72 -\nf96b697d7cb7938d525a2f31aaf161d0 input\n" \ + "message digest" "abc" +testing "md5sum 4" "md5sum" "c3fcd3d76192e4007dfb496cca67e13b -\n" \ + "" "abcdefghijklmnopqrstuvwxyz" +testing "md5sum 5" "md5sum" "d174ab98d277d9f5a5611c2c9f419d9f -\n" \ + "" "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" +testing "md5sum 6" "md5sum" "57edf4a22be3c955ac49da2e2107b67a -\n" \ + "" "12345678901234567890123456789012345678901234567890123456789012345678901234567890" + diff --git a/tests/mkdir.test b/tests/mkdir.test new file mode 100755 index 0000000..8b2f99f --- /dev/null +++ b/tests/mkdir.test @@ -0,0 +1,73 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +testing "mkdir" "mkdir one && [ -d one ] && echo yes" "yes\n" "" "" +rmdir one + +touch existing +testing "mkdir existing" \ + "mkdir existing 2> /dev/null || [ -f existing ] && echo yes" "yes\n" "" "" +rm existing + +testing "mkdir one two" \ + "mkdir one two && [ -d one ] && [ -d two ] && echo yes" "yes\n" "" "" +rmdir one two + +testing "mkdir missing/one" \ + "mkdir missing/one 2> /dev/null || [ ! -d missing ] && echo yes" "yes\n" "" "" + +testing "mkdir -p" \ + "mkdir -p one/two/three && [ -d one/two/three ] && echo yes" "yes\n" "" "" +rm -rf one + +mkdir existing +testing "mkdir -p existing" "mkdir -p existing && echo yes" "yes\n" "" "" +rmdir existing + +umask 123 +testing "mkdir (default permissions)" \ + "mkdir one && stat -c %a one" "654\n" "" "" +rmdir one + +testing "mkdir -m 124" \ + "mkdir -m 124 one && stat -c %a one" "124\n" "" "" +rmdir one + +umask 000 +testing "mkdir -p -m 653" \ + "mkdir -p -m 653 one/two && stat -c %a one && stat -c %a one/two" \ + "777\n653\n" "" "" +rm -rf one + +testing "mkdir -p one/two/ (trailing slash)" \ + "mkdir -p one/two/ && [ -d one/two ] && echo yes" "yes\n" "" "" +rm -rf one + +umask 022 +testing "mkdir -p -m 777 (022 umask)" \ + "mkdir -p -m 777 one/two && stat -c %a one && stat -c %a one/two" \ + "755\n777\n" "" "" +rm -rf one + +umask 377 +testing "mkdir -p -m 777 (377 umask)" \ + "mkdir -p -m 777 one/two && stat -c %a one && stat -c %a one/two" \ + "700\n777\n" "" "" +umask 002 +rm -rf one + +testing "mkdir -vp" "mkdir -vp walrus 2>&1" \ + "mkdir: created directory 'walrus'\n" "" "" + +testing "mkdir -vp exists" "mkdir -vp walrus 2>&1" \ + "" "" "" +rm -rf walrus + +touch two +testing "mkdir continue after fail" \ + "mkdir -m 777 one two three 2>/dev/null || stat -c %a three" \ + "777\n" "" "" +rm -rf one two three diff --git a/tests/mkfifo.test b/tests/mkfifo.test new file mode 100755 index 0000000..b0253fe --- /dev/null +++ b/tests/mkfifo.test @@ -0,0 +1,28 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +testing "mkfifo" "mkfifo one && [ -p one ] && echo yes" "yes\n" "" "" +rm one + +touch existing +testing "mkfifo existing" \ + "mkfifo existing 2> /dev/null || [ -f existing ] && echo yes" "yes\n" "" "" +rm existing + +testing "mkfifo one two" \ + "mkfifo one two && [ -p one ] && [ -p two ] && echo yes" "yes\n" "" "" +rm one two + +umask 123 +testing "mkfifo (default permissions)" \ + "mkfifo one && stat -c %a one" "644\n" "" "" +rm one + +umask 000 + +testing "mkfifo -m 124" \ + "mkfifo -m 124 one && stat -c %a one" "124\n" "" "" +rm -f one diff --git a/tests/modinfo.test b/tests/modinfo.test new file mode 100755 index 0000000..ac94ce0 --- /dev/null +++ b/tests/modinfo.test @@ -0,0 +1,30 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +[ -e /proc/modules ] || { echo "Skipping test because modules are not supported"; exit 1; } + +# modinfo does not need to output fields in a specified order. +# Instead, there are labelled fields. We can use sort to make up for this. +# Other issues to beware of are the volatile nature of srcversion and vermagic, +# which change from kernel to kernel and can be disabled. +# We grep to remove these. + +#We expect they have ne2k-pci as a module. + +testing "modinfo gets right number of fields" "modinfo ne2k-pci |cut -d: -f1 |grep -v ver|sort" "alias\nalias\nalias\nalias\nalias\nalias\nalias\nalias\nalias\nalias\nalias\nauthor\ndepends\ndescription\nfilename\nlicense\nparm\nparm\nparm\n" "" "" +testing "modinfo treats - and _ as equivalent" "modinfo ne2k_pci |cut -d: -f1 |grep -v ver|sort" "alias\nalias\nalias\nalias\nalias\nalias\nalias\nalias\nalias\nalias\nalias\nauthor\ndepends\ndescription\nfilename\nlicense\nparm\nparm\nparm\n" "" "" + +# Output of -F filename should be an absolute path to the module. +# Otherwise, initrd generating scripts will break. + +testing "modinfo -F filename gets absolute path" "[ -e `modinfo -F filename ne2k-pci` ] && echo ne2k-pci " "ne2k-pci\n" "" "" + +testing "modinfo supports multiple modules" "modinfo -F filename ne2k-pci 8390 | wc -l" "2\n" "" "" + +testing "modinfo does not output filename for bad module" "modinfo -F filename zxcvbnm__9753" "" "" "" + + + diff --git a/tests/mount.test b/tests/mount.test new file mode 100644 index 0000000..1fdc00f --- /dev/null +++ b/tests/mount.test @@ -0,0 +1,87 @@ +#!/bin/bash + +# Copyright 2013 Divya Kothari +# Copyright 2013 Robin Mittal + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +root_fs=`df | grep "\/$" | awk '{print $1}'` +root_fs_type=`file -sL $root_fs | awk '{print $5}'` + +tmp_b_fs="tmp_b_fs" +tmp_b_fs_type="ext3" + +reCreateTmpFs() { + rm -rf $tmp_b_fs + mknod $tmp_b_fs b 1 0 + mkfs.ext3 $tmp_b_fs >/dev/null 2>&1 +} +reCreateTmpFs + +testing "mount $root_fs /mnt" \ + "mount $root_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir && + sleep 1 && umount /mnt && test -e /testDir && rmdir /testDir" "" "" "" +testing "mount $tmp_b_fs /mnt" \ + "mount $tmp_b_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir && + sleep 1 && umount /mnt && ! test -e /mnt/testDir" "" "" "" +reCreateTmpFs + +chmod 444 /mnt +testing "mount $root_fs /mnt (read_only dir)" \ + "mount $root_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir && + sleep 1 && umount /mnt && test -e /testDir && rmdir /testDir" "" "" "" +testing "mount $tmp_b_fs /mnt (read_only dir)" \ + "mount $tmp_b_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir && + sleep 1 && umount /mnt && ! test -e /mnt/testDir" "" "" "" +reCreateTmpFs +chmod 755 /mnt +testing "mount -w $root_fs /mnt (write_only mode)" \ + "mount -w $root_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir && + sleep 1 && umount /mnt && test -e /testDir && rmdir /testDir" "" "" "" +testing "mount -w $tmp_b_fs /mnt (write_only mode)" \ + "mount -w $tmp_b_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir && + sleep 1 && umount /mnt && ! test -e /mnt/testDir" "" "" "" +reCreateTmpFs +testing "mount -rw $tmp_b_fs /mnt (read_write mode)" \ + 'mount -rw $tmp_b_fs /mnt >/dev/null && mkdir /mnt/testDir && \ + sleep 1 && ! test -e /mnt/testDir && umount /mnt' "" "" "" +reCreateTmpFs +testing "mount $tmp_b_fs /mnt -t fs_type" \ + "mount $tmp_b_fs /mnt -t $tmp_b_fs_type >/dev/null 2>&1 && + mkdir /mnt/testDir && sleep 1 && umount /mnt && + ! test -e /mnt/testDir" "" "" "" +reCreateTmpFs +mkdir -p testDir1/testDir2 testDir +echo "abcdefghijklmnopqrstuvwxyz" > testDir1/testDir2/testFile +testing "mount -o bind dir1 dir2" \ + 'mount -o bind testDir1 testDir >/dev/null 2>&1 && \ + cat testDir/testDir2/testFile && sleep 1 && umount testDir' \ + "abcdefghijklmnopqrstuvwxyz\n" "" "" +testing "mount -o rbind dir1 dir2" \ + 'mount -o rbind testDir1 testDir >/dev/null 2>&1 && \ + cat testDir/testDir2/testFile && sleep 1 && umount testDir' \ + "abcdefghijklmnopqrstuvwxyz\n" "" "" +testing "mount -o loop $tmp_b_fs /mnt" \ + "mount -o loop $tmp_b_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDirp && + sleep 1 && umount -d /mnt && ! test -e /mnt/testDirp" "" "" "" +reCreateTmpFs + +mkdir testDir2 +testing "mount -o move mount_1 mount_2" \ + "mount $tmp_b_fs testDir1 && mkdir testDir1/testDirr && + mount -o move testDir1 testDir2 && test -r testDir2/testDirr && + sleep 1 && umount testDir2" "" "" "" +reCreateTmpFs +testing "mount -o rw $tmp_b_fs /mnt" \ + "mount -o rw $tmp_b_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir && + sleep 1 && umount /mnt && ! test -e /mnt/testDir" "" "" "" +reCreateTmpFs +testing "mount -o ro $tmp_b_fs /mnt" \ + "mount -o ro $tmp_b_fs /mnt >/dev/null 2>&1 && + mkdir /mnt/testDir 2>/dev/null || sleep 1 && umount /mnt" "" "" "" +reCreateTmpFs + +umount testDir1 +rm -f $tmp_b_fs diff --git a/tests/mv.test b/tests/mv.test new file mode 100644 index 0000000..53fc999 --- /dev/null +++ b/tests/mv.test @@ -0,0 +1,98 @@ +#!/bin/bash + +# Copyright 2013 Robin Mittal +# Copyright 2013 Divya Kothari + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +touch file +testing "Move old_file to new_file" "mv file file1 && [ ! -e file -a -f file1 ] && + echo 'yes'" "yes\n" "" "" +rm -f file* + +touch file +mkdir dir +testing "Move file to a dir" "mv file dir && [ ! -e file -a -f dir/file ] && + echo 'yes'" "yes\n" "" "" +rm -rf file* dir* + +mkdir dir +testing "Move old_dir to new_dir" "mv dir dir1 && [ ! -e dir -a -d dir1 ] && + echo 'yes'" "yes\n" "" "" +rm -rf dir* + +mkdir dir1 dir2 +touch file1 file2 dir1/file3 +ln -s file1 link1 +testing "Move multiple files/dir to a dir" "mv file1 file2 link1 dir1 dir2 && + [ ! -e file1 -a ! -e file2 -a ! -e link1 -a ! -e dir1 ] && + [ -f dir2/file1 -a -f dir2/file2 -a -L dir2/link1 -a -d dir2/dir1 ] && + [ -f dir2/dir1/file3 ] && readlink dir2/link1" "file1\n" "" "" +rm -rf file* link* dir* + +touch file1 +testing "Move a empty file to new_file" "mv file1 file2 && + [ ! -e file1 -a -f file2 ] && stat -c %s file2" "0\n" "" "" +rm -rf file* + +mkdir dir1 +testing "Move enpty dir to new_dir" "mv dir1 dir2 && + [ ! -d dir1 -a -d dir2 ] && echo 'yes'" "yes\n" "" "" +rm -rf dir* + +dd if=/dev/zero of=file1 seek=10k count=1 >/dev/null 2>&1 +testing "Move file new_file (random file)" "mv file1 file2 && + [ ! -e file1 -a -f file2 ] && stat -c %s file2" "5243392\n" "" "" +rm -f file* + +touch file1 +ln -s file1 link1 +testing "Move link new_link (softlink)" "mv link1 link2 && + [ ! -e link1 -a -L link2 ] && readlink link2" "file1\n" "" "" +unlink tLink2 &>/dev/null +rm -f file* link* + +touch file1 +ln file1 link1 +testing "Move link new_link (hardlink)" "mv link1 link2 && + [ ! -e link1 -a -f link2 -a file1 -ef link2 ] && echo 'yes'" "yes\n" "" "" +unlink link2 &>/dev/null +rm -f file* link* + +touch file1 +chmod a-r file1 +testing "Move file new_file (unreadable)" "mv file1 file2 && + [ ! -e file1 -a -f file2 ] && echo 'yes'" "yes\n" "" "" +rm -f file* + +touch file1 +ln file1 link1 +mkdir dir1 +testing "Move file link dir (hardlink)" "mv file1 link1 dir1 && + [ ! -e file1 -a ! -e link1 -a -f dir1/file1 -a -f dir1/link1 ] && + [ dir1/file1 -ef dir1/link1 ] && echo 'yes'" "yes\n" "" "" +rm -rf file* link* dir* + +mkdir -p dir1/dir2 dir3 +touch dir1/dir2/file1 dir1/dir2/file2 +testing "Move dir1/dir2 dir3/new_dir" "mv dir1/dir2 dir3/dir4 && + [ ! -e dir1/dir2 -a -d dir3/dir4 -a -f dir3/dir4/file1 ] && + [ -f dir3/dir4/file2 ] && echo 'yes'" "yes\n" "" "" +rm -rf file* dir* + +mkdir dir1 dir2 +testing "Move dir new_dir (already exist)" "mv dir1 dir2 && + [ ! -e dir1 -a -d dir2/dir1 ] && echo 'yes'" "yes\n" "" "" +rm -rf dir* + +touch file1 file2 +testing "Move -f file new_file (exist)" "mv -f file1 file2 && + [ ! -e file1 -a -e file2 ] && echo 'yes'" "yes\n" "" "" +rm -f file* + +touch file1 file2 +testing "Move -n file new_file (exist)" "mv -n file1 file2 && + [ -e file1 -a -e file2 ] && echo 'yes'" "yes\n" "" "" +rm -f file* diff --git a/tests/nl.test b/tests/nl.test new file mode 100644 index 0000000..958cb41 --- /dev/null +++ b/tests/nl.test @@ -0,0 +1,50 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +testing "nl" "nl" " 1\tone\n 2\ttwo\n 3\tthree\n" \ + "" "one\ntwo\nthree\n" + +testing "nl explicit defaults" "nl -nrn -b a" \ + " 1\tone\n 2\ttwo\n 3\tthree\n" "" "one\ntwo\nthree\n" + +# -n ln rn rz + +testing "nl -nln" "nl -nln" "1 \tone\n2 \ttwo\n3 \tthree\n" \ + "" "one\ntwo\nthree\n" +testing "nl -nln -w" "nl -nln -w 8" \ + "1 \tone\n2 \ttwo\n3 \tthree\n" "" "one\ntwo\nthree\n" + +testing "nl -nrz" "nl -nrz" "000001\tone\n000002\ttwo\n000003\tthree\n" \ + "" "one\ntwo\nthree\n" + +testing "nl -nrz -w" "nl -w3 -nrz" "001\tone\n002\ttwo\n003\tthree\n" \ + "" "one\ntwo\nthree\n" + + +# For non-matching lines the separator is "suppressed" meaning it... +# turns into spaces! And the tab turns into one space, and -d boom turns +# into 4 spaces, but these: +# nl -s"$(echo -e 'bo\tom')" -bpand README +# nl -w 3 -bpthe README +# Yeah. And I doubt utf8 fontmetrics are used either. + +testing "nl -b t" "nl -b t" " \n 1\tone\n \n 2\ttwo\n" \ + "" "\none\n\ntwo\n" +testing "nl -b n" "nl -b n" " one\n two\n three\n" \ + "" "one\ntwo\nthree\n" +testing "nl -sook -b p" "nl -sook -bpoing" \ + " one\n 1ookboing\n 2ooksproingy\n" \ + "" "one\nboing\nsproingy\n" + +testing "nl -v" "nl -v 42" " 42\tone\n 43\ttwo\n 44\tthree\n" \ + "" "one\ntwo\nthree\n" +testing "nl -l" "nl -ba -l2 -w2 - input" \ + " 1\tone\n \n 2\t\n 3\ttwo\n \n 4\t\n \n 5\tthree\n 6\tfour\n \n 7\t\n \n 8\tbang\n \n" \ + "\n\nbang\n\n" "one\n\n\ntwo\n\n\n\nthree\nfour\n\n" +testing "nl no space" "nl -w 1 -v 42" "42\tline\n" "" "line\n" + +# Should test for -E but no other implementation seems to have it? +#testing "nl -E" "nl -w2 -sx -Ebp'(one|two)'" " 1x" "one\nand\ntwo\n" diff --git a/tests/pgrep.test b/tests/pgrep.test new file mode 100644 index 0000000..36df573 --- /dev/null +++ b/tests/pgrep.test @@ -0,0 +1,122 @@ +#!/bin/bash + +# Copyright 2013 Divya Kothari +# Copyright 2013 Robin Mittal + +#cleaning 'yes' processes +killall yes >/dev/null 2>&1 + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +# Starting processes to test pgrep command +yes >/dev/null & +proc=$! +echo "# Process created with id: $proc" +sleep 1 +session_id=0 +proc_parent=`cat /proc/${proc}/stat | awk '{ print $4 }'` +echo "# Parent Process id of $proc is $proc_parent" + +# Testcases for pgrep command +testing "pgrep pattern" "pgrep yes" "$proc\n" "" "" +testing "pgrep wildCardPattern" "pgrep ^y.*s$" "$proc\n" "" "" +testing "pgrep -l pattern" "pgrep -l yes" "$proc yes\n" "" "" +testing "pgrep -f pattern" "pgrep -f yes" "$proc\n" "" "" +testing "pgrep -n pattern" "pgrep -n yes" "$proc\n" "" "" +testing "pgrep -o pattern" "pgrep -o yes" "$proc\n" "" "" +testing "pgrep -s" "pgrep -s $session_id yes" "$proc\n" "" "" +testing "pgrep -P" "pgrep -P $proc_parent yes" "$proc\n" "" "" + +#Clean-up +killall yes >/dev/null 2>&1 + +# Testcases for pkill command + +yes >/dev/null & +sleep 1 +testing "pkill pattern" "pkill yes && sleep 1 && (pgrep yes || echo 'yes')" \ + "yes\n" "" "" +killall yes >/dev/null 2>&1 + +yes >/dev/null & +yes print1 >/dev/null & +yes print2 >/dev/null & +sleep 1 +testing "pkill pattern (multiple)" "pkill yes && sleep 1 && + (pgrep yes || echo 'yes')" "yes\n" "" "" +killall yes >/dev/null 2>&1 + +yes >/dev/null & +sleep 1 +testing "pkill -f pattern (one)" "pkill -f yes && sleep 1 && + (pgrep yes || echo 'yes')" "yes\n" "" "" +killall yes >/dev/null 2>&1 + +yes print1 >/dev/null & +sleep 1 +testing "pkill -f pattern args" "pkill -f \"yes print1\" && sleep 1 && + (pgrep yes || echo 'yes')" "yes\n" "" "" +killall yes >/dev/null 2>&1 + +yes >/dev/null & +yes print1 >/dev/null & +yes print2 >/dev/null & +sleep 1 +testing "pkill -f pattern (multiple)" "pkill -f yes && sleep 1 && + (pgrep yes || echo 'yes')" "yes\n" "" "" +killall yes >/dev/null 2>&1 + +yes >/dev/null & +sleep 1 +testing "pkill -s 0 -f pattern (regexp)" "pkill -s 0 -f ye* && sleep 1 && + (pgrep yes || echo 'yes')" "yes\n" "" "" +killall yes >/dev/null 2>&1 + +yes >/dev/null & +proc1=$! +yes >/dev/null & +proc2=$! +sleep 1 +testing "pkill -n pattern" "pkill -n yes && sleep 1 && pgrep yes" \ + "$proc1\n" "" "" +killall yes >/dev/null 2>&1 + +yes >/dev/null & +proc1=$! +yes >/dev/null & +proc2=$! +sleep 1 +testing "pkill -o pattern" "pkill -o yes && sleep 1 && pgrep yes" \ + "$proc2\n" "" "" +killall yes >/dev/null 2>&1 + +yes >/dev/null & +sleep 1 +testing "pkill -s (blank) pattern" "pkill -s '' yes && sleep 1 && + (pgrep yes || echo 'yes')" "yes\n" "" "" +killall yes >/dev/null 2>&1 + +yes >/dev/null & +sleep 1 +testing "pkill -s 0 pattern" "pkill -s 0 yes && sleep 1 && + (pgrep yes || echo 'yes')" "yes\n" "" "" +killall yes >/dev/null 2>&1 + +yes >/dev/null & +proc=$! +proc_p=`cat /proc/${proc}/stat | awk '{ print $4 }'` +sleep 1 +testing "pkill -P parent_prodId pattern" "pkill -P $proc_p yes && sleep 1 && + (pgrep yes || echo 'yes')" "yes\n" "" "" +killall yes >/dev/null 2>&1 + +yes >/dev/null & +proc=$! +proc_parent=`cat /proc/${proc}/stat | awk '{ print $4 }'` +sleep 1 +testing "pkill -9 pattern" "pkill -9 yes && sleep 1 && + (pgrep yes || echo 'yes')" "yes\n" "" "" +killall yes >/dev/null 2>&1 + diff --git a/tests/printf.test b/tests/printf.test new file mode 100644 index 0000000..96789bd --- /dev/null +++ b/tests/printf.test @@ -0,0 +1,29 @@ +#!/bin/bash + +# Copyright 2013 Robin Mittal +# Copyright 2013 Divya Kothari + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" +#set -x + +testing "printf TEXT" "printf toyTestText" "toyTestText" "" "" +testing "printf MULTILINE_TEXT" \ + "printf 'Testing\nmultiline\ntext\nfrom\ntoybox\tcommand.\b'" \ + "Testing\nmultiline\ntext\nfrom\ntoybox\tcommand.\b" "" "" +testing "printf '%5d%4d' 1 21 321 4321 54321" \ + "printf '%5d%4d' 1 21 321 4321 54321" " 1 21 321432154321 0" "" "" +testing "printf '%c %c' 78 79" "printf '%c %c' 78 79" "7 7" "" "" +testing "printf '%d %d' 78 79" "printf '%d %d' 78 79" "78 79" "" "" +testing "printf '%f %f' 78 79" "printf '%f %f' 78 79" \ + "78.000000 79.000000" "" "" +testing "printf 'f f' 78 79" "printf 'f f' 78 79" "f f" "" "" +testing "printf '%i %i' 78 79" "printf '%i %i' 78 79" "78 79" "" "" +testing "printf '%o %o' 78 79" "printf '%o %o' 78 79" "116 117" "" "" +testing "printf '%u %u' 78 79" "printf '%u %u' 78 79" "78 79" "" "" +testing "printf '%u %u' -1 -2" "printf '%u %u' -1 -2" \ + "18446744073709551615 18446744073709551614" "" "" +testing "printf '%x %X' 78 79" "printf '%x %X' 78 79" "4e 4F" "" "" +testing "printf '%g %G' 78 79" "printf '%g %G' 78 79" "78 79" "" "" +testing "printf '%s %s' 78 79" "printf '%s %s' 78 79" "78 79" "" "" diff --git a/tests/pwd.test b/tests/pwd.test new file mode 100755 index 0000000..b02055b --- /dev/null +++ b/tests/pwd.test @@ -0,0 +1,26 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +#TODO: Find better tests + +testing "pwd" "[ $(stat -c %i "$(pwd)") = $(stat -c %i .) ] && echo yes" \ + "yes\n" "" "" +testing "pwd -P" "[ $(stat -c %i "$(pwd -P)") = $(stat -c %i .) ] && echo yes" \ + "yes\n" "" "" + + +ln -s . sym +cd sym +testing "pwd" "[ $(stat -c %i "$(pwd)") = $(stat -c %i "$PWD") ] && echo yes" \ + "yes\n" "" "" +testing "pwd -P" "[ $(stat -c %i "$(pwd -P)") = $(stat -c %i "$PWD") ] || echo yes" \ + "yes\n" "" "" +cd .. +rm sym + +export PWD=walrus +testing "pwd (bad PWD)" "[ "$(pwd)" = "$(cd . ; pwd)" ] && echo yes" \ + "yes\n" "" "" diff --git a/tests/readlink.test b/tests/readlink.test new file mode 100755 index 0000000..6c7b147 --- /dev/null +++ b/tests/readlink.test @@ -0,0 +1,67 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +APWD="$(pwd -P)" + +testing "readlink missing" "readlink notfound || echo yes" "yes\n" "" "" + +# simple tests on a file + +touch file +testing "readlink file" "readlink file || echo yes" "yes\n" "" "" +testing "readlink -f dir" "readlink -f ." "$APWD\n" "" "" +testing "readlink -f missing" "readlink -f notfound" "$APWD/notfound\n" "" "" + +ln -sf notfound link +testing "readlink link" "readlink link" "notfound\n" "" "" +testing "readlink link->missing" "readlink -f link" "$APWD/notfound\n" "" "" +ln -sf ../../ link +testing "readlink stays relative" "readlink link" "../../\n" "" "" +rm link +ln -sf file link +testing "readlink -f link->file" "readlink -f link" "$APWD/file\n" "" "" +ln -sf . link +testing "readlink -f link->dir" "readlink -f link" "$APWD\n" "" "" +ln -snf link link +testing "readlink link->link (recursive)" "readlink link" "link\n" "" "" +testing "readlink -f link->link (recursive)" \ + "readlink -f link 2>/dev/null || echo yes" "yes\n" "" "" + +testing "readlink -q notlink" "readlink -q file || echo yes" "yes\n" "" "" +testing "readlink -q link" "readlink -q link && echo yes" "yes\n" "" "" +testing "readlink -q notfound" "readlink -q notfound || echo yes" "yes\n" "" "" +testing "readlink -e found" "readlink -e file" "$APWD/file\n" "" "" +testing "readlink -e notfound" \ + "readlink -e notfound 2>/dev/null || echo yes" "yes\n" "" "" +testing "readlink -nf ." "readlink -nf ." "$APWD" "" "" + +mkdir sub && +ln -s . here && +ln -s ./sub dir && +touch sub/bang || exit 1 +testing "readlink -f multi" "readlink -f dir/../here/dir/bang" \ + "$APWD/sub/bang\n" "" "" +testing "readlink -f link/missing" "readlink -f dir/boing" \ + "$APWD/sub/boing\n" "" "" +testing "readlink -f /dev/null/file" \ + "readlink -f /dev/null/file 2>/dev/null || echo yes" "yes\n" "" "" +ln -sf / link || exit 1 +testing "readlink -f link->/" "readlink -e link/dev" "/dev\n" "" "" +testing "readlink -f /dev/null/.." \ + "readlink -f link/null/.. 2>/dev/null || echo yes" "yes\n" "" "" +rm -f link && ln -sf link link || exit 1 +testing "readlink recurse" "readlink link" "link\n" "" "" + +rm file link sub/bang dir here +rmdir sub + +# Make sure circular links don't run away. + +ln -s link1 link2 +ln -s link2 link1 +testing "readlink follow recursive2" "readlink -f link1 || echo yes" \ + "yes\n" "" "" +rm link1 link2 diff --git a/tests/renice.test b/tests/renice.test new file mode 100644 index 0000000..e87111c --- /dev/null +++ b/tests/renice.test @@ -0,0 +1,110 @@ +#!/bin/bash + +# Copyright 2013 Robin Mittal +# Copyright 2013 Divya Kothari + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +fun_nice_val() +{ + for each_proc in $@ + do + echo `awk '{ print $18 }' /proc/${each_proc}/stat` + done +} + +# creating processes as a test data +yes >/dev/null & +proc1=$! +yes >/dev/null & +proc2=$! +yes >/dev/null & +proc3=$! +yes >/dev/null & +proc4=$! +yes >/dev/null & +proc5=$! + +n_val1=`fun_nice_val $proc1` +n_val2=`fun_nice_val $proc2` +n_val3=`fun_nice_val $proc3` +n_val4=`fun_nice_val $proc4` +n_val5=`fun_nice_val $proc5` + +# Redirecting errors to /dev/null +arg="2>/dev/null" + +for n_v in "-1" "1" +do + for n_o in "" " -p" + do + nice_val1=$((`fun_nice_val $proc1` + $n_v)) + nice_val2=$((`fun_nice_val $proc2` + $n_v)) + nice_val3=$((`fun_nice_val $proc3` + $n_v)) + nice_val4=$((`fun_nice_val $proc4` + $n_v)) + nice_val5=$((`fun_nice_val $proc5` + $n_v)) + testing "renice with -n=$n_v and with$n_o multiple_pids" \ + "renice -n $n_v$n_o $proc1 $proc2 $proc3 $proc4 $proc5 && + fun_nice_val $proc1 $proc2 $proc3 $proc4 $proc5" \ + "$nice_val1\n$nice_val2\n$nice_val3\n$nice_val4\n$nice_val5\n" "" "" + + nice_val1=$((`fun_nice_val $proc1` + $n_v)) + nice_val2=$((`fun_nice_val $proc2` + $n_v)) + nice_val3=$((`fun_nice_val $proc3` + $n_v)) + nice_val4=$((`fun_nice_val $proc4` + $n_v)) + nice_val5=$((`fun_nice_val $proc5` + $n_v)) + testing "renice with -n=$n_v and with$n_o multiple_pids (some invalid)" \ + "renice -n $n_v$n_o $proc1 $proc2 88888 99999 $proc3 $proc4 $proc5 $arg || + fun_nice_val $proc1 $proc2 $proc3 $proc4 $proc5" \ + "$nice_val1\n$nice_val2\n$nice_val3\n$nice_val4\n$nice_val5\n" "" "" + done +done + +# Starting Boundary Test Here .. +loop_cnt=2 +echo -n "TEST: Boundary value test for Id($proc1)..[old_nice_val/new_nice_val]:" +cnt=0 +n_val=1 +while [ $cnt -gt -1 ] +do + old_nice_val=`fun_nice_val $proc1` + new_nice_val=`renice -n $n_val $proc1 >/dev/null 2>&1 && fun_nice_val $proc1` + echo -n "[$old_nice_val/$new_nice_val]," + if [ $old_nice_val -eq 39 -a $old_nice_val -eq $new_nice_val ] + then + echo -n " [Equals 39,doing -1] " + n_val="-1" + elif [ $old_nice_val -eq 0 -a $old_nice_val -eq $new_nice_val ] + then + echo -n " [Equals 0,doing +1] " + n_val="1" + elif [ $new_nice_val -gt 39 -o $new_nice_val -lt 0 ] + then + echo " [Test Fail] " + echo "FAIL: renice with step 1 ($proc1) (boundary value)" + cnt="-1" + elif [ $new_nice_val -eq $n_val1 -a $new_nice_val -eq $(($old_nice_val+1)) ] + then + cnt=$(($cnt + 1)) + if [ $cnt -eq $loop_cnt ] + then + echo " [Test Pass] " + echo "PASS: renice with step 1 ($proc1) (boundary value)" + cnt="-1" + fi + else + dif=`echo $(($new_nice_val-$old_nice_val))` + dif=`echo ${dif/-}` + if [ $dif -ne 1 ] + then + echo " [Test Fail] " + echo "FAIL: renice with step 1 ($proc1) (boundary value)" + cnt="-1" + fi + fi +done +# Boundary test End + +killall yes >/dev/null 2>&1 diff --git a/tests/rev.test b/tests/rev.test new file mode 100644 index 0000000..c7622b9 --- /dev/null +++ b/tests/rev.test @@ -0,0 +1,25 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +echo -e "one" > file1 +echo -e "two" > file2 +testing "rev" "rev && echo yes" "orez\nyes\n" "" "zero\n" +testing "rev -" "rev - && echo yes" "orez\nyes\n" "" "zero\n" +testing "rev file1 file2" "rev file1 file2" "eno\nowt\n" "" "" +testing "rev - file" "rev - file1" "orez\neno\n" "" "zero\n" +testing "rev file -" "rev file1 -" "eno\norez\n" "" "zero\n" +testing "rev no trailing newline" "rev -" "cba\nfed\n" "" "abc\ndef" + +testing "rev file1 notfound file2" \ + "rev file1 notfound file2 2>stderr && echo ok ; cat stderr; rm stderr" \ + "eno\nowt\nrev: notfound: No such file or directory\n" "" "" + +testing "rev different input sizes"\ + "rev"\ + "\n1\n21\n321\n4321\n54321\n4321\n321\n21\n1\n\n"\ + "" "\n1\n12\n123\n1234\n12345\n1234\n123\n12\n1\n\n" + +rm file1 file2 \ No newline at end of file diff --git a/tests/rm.test b/tests/rm.test new file mode 100644 index 0000000..0dca853 --- /dev/null +++ b/tests/rm.test @@ -0,0 +1,46 @@ +#!/bin/bash + +# Copyright 2013 Robin Mittal +# Copyright 2013 Divya Kothari + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +echo "abcdefghijklmnopqrstuvwxyz" > file.txt +testing "Remove text-file" "rm file.txt && [ ! -e file.txt ] && echo 'yes'" "yes\n" "" "" +rm -f file* + +mkdir dir +testing "Remove empty directory" "rm -r dir && [ ! -d dir ] && echo 'yes'" "yes\n" "" "" +rm -rf dir + +echo "abcdefghijklmnopqrstuvwxyz" > file.txt && chmod 000 file.txt +testing "Remove text file(mode 000)" "rm -f file.txt && [ ! -e file.txt ] && echo 'yes'" \ + "yes\n" "" "" +rm -f file* + +touch file1.txt file2.txt +mkdir dir1 dir2 +testing "rm -r (multiple files and dirs)" \ + "rm -r file1.txt file2.txt dir1 dir2 2>/dev/null && + [ ! -e file1.txt -a ! -e file2.txt -a ! -d dir1 -a ! -d dir2 ] && echo 'yes'" \ + "yes\n" "" "" +rm -rf file* dir* + +touch file1.txt file2.txt +mkdir dir1 dir2 +testing "rm -rf (present + missing files and dirs)" \ + "rm -rf file1.txt file2.txt file3.txt dir1 dir2 dir3 2>/dev/null && + [ ! -e file1.txt -a ! -e file2.txt -a ! -d dir1 -a ! -d dir2 ] && echo 'yes'" \ + "yes\n" "" "" +rm -rf file* dir* + +# testing with nested dirs. +mkdir -p dir1/dir2/dir3 dir1/dir2/dir4 +touch dir1/file1.txt dir1/dir2/file2.txt dir1/dir2/dir3/file3.txt +testing "rm -r nested_dir" "rm -r dir1/dir2/ 2>/dev/null && + [ -d dir1 -a -f dir1/file1.txt -a ! -d dir1/dir2 ] && echo 'yes'" \ + "yes\n" "" "" +rm -rf dir* + diff --git a/tests/rmdir.test b/tests/rmdir.test new file mode 100755 index 0000000..a7b027e --- /dev/null +++ b/tests/rmdir.test @@ -0,0 +1,55 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +mkdir one +testing "rmdir" "rmdir one && [ ! -d one ] && echo yes" "yes\n" "" "" + +touch walrus +testing "rmdir file" \ + "rmdir walrus 2> /dev/null || [ -f walrus ] && echo yes" "yes\n" "" "" + +mkdir one two +testing "rmdir one two" \ + "rmdir one two 2> /dev/null && [ ! -d one ] && [ ! -d two ] && echo yes" \ + "yes\n" "" "" + +mkdir one two three +testing "rmdir one missing two file three" \ + "rmdir one missing two walrus three 2> /dev/null || [ ! -d three ] && echo yes" \ + "yes\n" "" "" +rm walrus + +mkdir one +chmod 000 one +testing "rmdir mode 000" "rmdir one && [ ! -d one ] && echo yes" "yes\n" "" "" + +mkdir temp +touch temp/thing +testing "rmdir non-empty" \ + "rmdir temp 2>/dev/null || [ -d temp ] && echo yes" "yes\n" "" "" +testing "rmdir -p dir/file" \ + "rmdir -p temp/thing 2>/dev/null || [ -f temp/thing ] && echo yes" \ + "yes\n" "" "" + +mkdir -p temp/one/two/three +testing "rmdir -p part of path" \ + "rmdir -p temp/one/two/three 2>/dev/null || [ -d temp ] && [ ! -e temp/one ] && echo yes" \ + "yes\n" "" "" +rm -rf temp + + +mkdir -p one/two/three +testing "rmdir -p one/two/three" \ + "rmdir -p one/two/three && [ ! -e one ] && echo yes" "yes\n" "" "" + +mkdir -p one/two/three +testing "rmdir -p one/two/three/" \ + "rmdir -p one/two/three/ && [ ! -e one ] && echo yes" "yes\n" "" "" + +#mkdir -p one/two/three +#chmod 000 one/two/three one/two one +#testing "rmdir -p one/two/three" \ +# "rmdir -p one/two/three && [ ! -e one ] && echo yes" "yes\n" "" "" diff --git a/tests/seq.test b/tests/seq.test new file mode 100755 index 0000000..3f3b409 --- /dev/null +++ b/tests/seq.test @@ -0,0 +1,28 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +testing "seq (exit with error)" "seq 2> /dev/null || echo yes" "yes\n" "" "" +testing "seq (exit with error)" "seq 1 2 3 4 2> /dev/null || echo yes" \ + "yes\n" "" "" +testing "seq one argument" "seq 3" "1\n2\n3\n" "" "" +testing "seq two arguments" "seq 5 7" "5\n6\n7\n" "" "" +testing "seq two arguments reversed" "seq 7 5" "" "" "" +testing "seq two arguments equal" "seq 3 3" "3\n" "" "" +testing "seq two arguments equal, arbitrary negative step" "seq 1 -15 1" \ + "1\n" "" "" +testing "seq two arguments equal, arbitrary positive step" "seq 1 +15 1" \ + "1\n" "" "" +testing "seq count up by 2" "seq 4 2 8" "4\n6\n8\n" "" "" +testing "seq count down by 2" "seq 8 -2 4" "8\n6\n4\n" "" "" +testing "seq count wrong way #1" "seq 4 -2 8" "" "" "" +testing "seq count wrong way #2" "seq 8 2 4" "" "" "" +testing "seq count by .3" "seq 3 .3 4" "3\n3.3\n3.6\n3.9\n" "" "" +testing "seq count by -.9" "seq .7 -.9 -2.2" "0.7\n-0.2\n-1.1\n-2\n" "" "" +testing "seq count by zero" "seq 4 0 8 | head -n 10" "" "" "" +testing "seq separator -" "seq -s - 1 3" "1-2-3\n" "" "" +testing "seq format string" 'seq -f %+01g -10 5 10' "-10\n-5\n+0\n+5\n+10\n" "" "" +testing "seq separator and format string" "seq -f \%03g -s \; 5 -1 0" "005;004;003;002;001;000\n" "" "" + diff --git a/tests/sha1sum.test b/tests/sha1sum.test new file mode 100755 index 0000000..cd621fd --- /dev/null +++ b/tests/sha1sum.test @@ -0,0 +1,57 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +# These tests are based on RFC3174 which were based on FIPS PUB 180-1 + +testing "sha1sum TEST1" \ + "sha1sum" \ + "a9993e364706816aba3e25717850c26c9cd0d89d -\n" \ + "" "abc" + +testing "sha1sum TEST2" \ + "sha1sum" \ + "84983e441c3bd26ebaae4aa1f95129e5e54670f1 -\n" \ + "" "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" + +testing "sha1sum TEST3" \ + 'dd if=/dev/zero bs=1000 count=1000 2>/dev/null | tr \\0 a | sha1sum' \ + "34aa973cd4c4daa4f61eeb2bdbad27316534016f -\n" \ + "" "" + +testing "sha1sum TEST4" \ + 'for i in `seq 1 10`; do echo -n 0123456701234567012345670123456701234567012345670123456701234567 ; done | sha1sum' \ + "dea356a2cddd90c7a7ecedc5ebb563934f460452 -\n" \ + "" "" + +echo -n "abc" > file1 +echo -n "def" > file2 +testing "sha1sum" \ + "sha1sum" \ + "a9993e364706816aba3e25717850c26c9cd0d89d -\n" \ + "" "abc" + +testing "sha1sum -" \ + "sha1sum -" \ + "a9993e364706816aba3e25717850c26c9cd0d89d -\n" \ + "" "abc" + +testing "sha1sum file" \ + "sha1sum file1" \ + "a9993e364706816aba3e25717850c26c9cd0d89d file1\n" \ + "" "" + +testing "sha1sum file1 file2" \ + "sha1sum file1 file2" \ + "a9993e364706816aba3e25717850c26c9cd0d89d file1\n589c22335a381f122d129225f5c0ba3056ed5811 file2\n" \ + "" "" + +testing "sha1sum file1 file2 -" \ + "sha1sum file1 file2 -" \ + "a9993e364706816aba3e25717850c26c9cd0d89d file1\n589c22335a381f122d129225f5c0ba3056ed5811 file2\na9993e364706816aba3e25717850c26c9cd0d89d -\n" \ + "" "abc" + +rm -f file1 file2 + diff --git a/tests/sort.test b/tests/sort.test new file mode 100755 index 0000000..7bd413f --- /dev/null +++ b/tests/sort.test @@ -0,0 +1,100 @@ +#!/bin/bash + +# SUSv4 compliant sort tests. +# Copyright 2005, 2012 by Rob Landley + +[ -f testing.sh ] && . testing.sh + +# The basic tests. These should work even with the small config. + +testing "sort" "sort input" "a\nb\nc\n" "c\na\nb\n" "" +testing "sort #2" "sort input" "010\n1\n3\n" "3\n1\n010\n" "" +testing "sort stdin" "sort" "a\nb\nc\n" "" "b\na\nc\n" +testing "sort numeric" "sort -n input" "1\n3\n010\n" "3\n1\n010\n" "" +testing "sort reverse" "sort -r input" "wook\nwalrus\npoint\npabst\naargh\n" \ + "point\nwook\npabst\naargh\nwalrus\n" "" + +# These tests require the full option set. + +optional SORT_BIG +# Longish chunk of data re-used by the next few tests. The expected output +# varies, but the input (this) is the same. + +data="42 1 3 woot +42 1 010 zoology +egg 1 2 papyrus +7 3 42 soup +999 3 0 algebra +" + +# Sorting with keys + +testing "sort one key" "sort -k4,4 input" \ +"999 3 0 algebra +egg 1 2 papyrus +7 3 42 soup +42 1 3 woot +42 1 010 zoology +" "$data" "" + +# The numeric sort orders field 2, ignores field 3 (because numeric sort stops +# at the whitespace), then the global fallback sort does an alpha sort on +# the whole string (starting at the beginning of the line). + +testing "sort key range with numeric option" "sort -k2,3n input" \ +"42 1 010 zoology +42 1 3 woot +egg 1 2 papyrus +7 3 42 soup +999 3 0 algebra +" "$data" "" + +# Numeric sort on field 2 (again, ignore field 3 because it's numeric), +# then do a _reversed_ alpha sort on the whole line as a tiebreaker. + +testing "sort key range with numeric option and global reverse" \ +"sort -k2,3n -r input" \ +"egg 1 2 papyrus +42 1 3 woot +42 1 010 zoology +999 3 0 algebra +7 3 42 soup +" "$data" "" + +# Reversed numeric sort on field 2 (numeric ignores field 3), then +# break ties with alpha sort on whole line. + +testing "sort key range with multiple options" "sort -k2,3rn input" \ +"7 3 42 soup +999 3 0 algebra +42 1 010 zoology +42 1 3 woot +egg 1 2 papyrus +" "$data" "" + +testing "sort key doesn't strip leading blanks, disables fallback global sort" \ +"sort -n -k2 -t ' '" " a \n 1 \n 2 \n" "" " 2 \n 1 \n a \n" + +# Test case contributed by Joey Hess: + +testing "sort key edge case with -t" "sort -n -k4 -t/" \ +"/usr/lib/finish-install.d/1 +/usr/lib/finish-install.d/4 +/usr/lib/prebaseconfig.d/2 +/usr/lib/prebaseconfig.d/6 +" "" "/usr/lib/finish-install.d/1 +/usr/lib/prebaseconfig.d/2 +/usr/lib/finish-install.d/4 +/usr/lib/prebaseconfig.d/6 +" + +testing "sort -x" "sort -x" "010\na0\n 0c0\n" "" "a0\n010\n 0c0\n" + +optional SORT_FLOAT + +# not numbers < NaN < -infinity < numbers < +infinity +testing "sort -g" "sort -g" \ + "bork\nNaN\n-inf\n0.4\n1.222\n01.37\n2.1\n+infinity\n" "" \ + "01.37\n1.222\n2.1\n0.4\nNaN\nbork\n-inf\n+infinity\n" + + diff --git a/tests/split.test b/tests/split.test new file mode 100755 index 0000000..d86b025 --- /dev/null +++ b/tests/split.test @@ -0,0 +1,31 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +testing "split" "seq 1 12345 | split && ls xa[a-z] | wc -l" "13\n" "" "" +rm xa[a-z] + +testing "split -" "seq 1 12345 | split - && ls xa[a-z] | wc -l" "13\n" "" "" +rm xa[a-z] + +seq 1 12345 > file +testing "split file" "split file && ls xa[a-z] | wc -l" "13\n" "" "" +rm xa[a-z] + +testing "split -l" "split file -l 10k && wc -l xab" "2105 xab\n" "" "" +rm xa[ab] + +testing "split suffix exhaustion" \ + "split file -l 10 -a 1 walrus 2>/dev/null || ls walrus* | wc -l" "26\n" "" "" +rm walrus* + +testing "split bytes" \ + "toybox seq 1 20000 | split -b 100 -a 3 - whang && ls whang* | wc -l && wc -c whangbpw" "1089\n94 whangbpw\n" "" "" + +testing "split reassembly" \ + 'diff -u <(ls whang* | sort | xargs cat) <(seq 1 20000) && echo yes' \ + "yes\n" "" "" + +rm file whang* diff --git a/tests/tac.test b/tests/tac.test new file mode 100644 index 0000000..96f2531 --- /dev/null +++ b/tests/tac.test @@ -0,0 +1,29 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + + +echo -e "one-A\none-B" > file1 +echo -e "two-A\ntwo-B" > file2 +testing "tac" "tac && echo yes" "one-B\none-A\nyes\n" "" "one-A\none-B\n" +testing "tac -" "tac - && echo yes" "one-B\none-A\nyes\n" "" "one-A\none-B\n" +testing "tac file1 file2" "tac file1 file2" "one-B\none-A\ntwo-B\ntwo-A\n" "" "" +testing "tac - file" "tac - file1" "zero-B\nzero-A\none-B\none-A\n" "" "zero-A\nzero-B\n" +testing "tac file -" "tac file1 -" "one-B\none-A\nzero-B\nzero-A\n" "" "zero-A\nzero-B\n" + +testing "tac file1 notfound file2" \ + "tac file1 notfound file2 2>stderr && echo ok ; tac stderr; rm stderr" \ + "one-B\none-A\ntwo-B\ntwo-A\ntac: notfound: No such file or directory\n" "" "" + +testing "tac no trailing newline" "tac -" "defabc\n" "" "abc\ndef" + +# xputs used by tac does not propagate this error condition properly. +#testing "tac > /dev/full" \ +# "tac - > /dev/full 2>stderr && echo ok; cat stderr; rm stderr" \ +# "tac: write: No space left on device\n" "" "zero\n" + +# + +rm file1 file2 \ No newline at end of file diff --git a/tests/tail.test b/tests/tail.test new file mode 100755 index 0000000..f4b8667 --- /dev/null +++ b/tests/tail.test @@ -0,0 +1,61 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +BIGTEST="one\ntwo\nthree\nfour\nfive\nsix\nseven\neight\nnine\nten\neleven\n" +echo -ne "$BIGTEST" > file1 +testing "tail" "tail && echo yes" "oneyes\n" "" "one" +testing "tail file" "tail file1" \ + "two\nthree\nfour\nfive\nsix\nseven\neight\nnine\nten\neleven\n" "" "" +testing "tail -n in bounds" "tail -n 3 file1" "nine\nten\neleven\n" "" "" +testing "tail -n out of bounds" "tail -n 999 file1" "$BIGTEST" "" "" +testing "tail -n+ in bounds" "tail -n +3 file1" \ + "three\nfour\nfive\nsix\nseven\neight\nnine\nten\neleven\n" "" "" +testing "tail -n+ outof bounds" "tail -n +999 file1" "" "" "" +testing "tail -c in bounds" "tail -c 27 file1" \ + "even\neight\nnine\nten\neleven\n" "" "" +testing "tail -c out of bounds" "tail -c 999 file1" "$BIGTEST" "" "" +testing "tail -c+ in bounds" "tail -c +27 file1" \ + "x\nseven\neight\nnine\nten\neleven\n" "" "" +testing "tail -c+ out of bonds" "tail -c +999 file1" "" "" "" +rm file1 + +testing "tail stdin no trailing newline" "tail -n 1 - " "c" "" "a\nb\nc" +testing "tail file no trailing newline" "tail -n 1 input" "c" "a\nb\nc" "" + +optional TAIL_SEEK +testing "tail noseek -n in bounds" "tail -n 3" "nine\nten\neleven\n" \ + "" "$BIGTEST" +testing "tail noseek -n out of bounds" "tail -n 999" "$BIGTEST" "" "$BIGTEST" +testing "tail noseek -n+ in bounds" "tail -n +3" \ + "three\nfour\nfive\nsix\nseven\neight\nnine\nten\neleven\n" "" \ + "$BIGTEST" +testing "tail noseek -n+ outof bounds" "tail -n +999" "" "" "$BIGTEST" +testing "tail noseek -c in bounds" "tail -c 27" \ + "even\neight\nnine\nten\neleven\n" "" "$BIGTEST" +testing "tail noseek -c out of bounds" "tail -c 999" "$BIGTEST" "" "$BIGTEST" +testing "tail noseek -c+ in bounds" "tail -c +27" \ + "x\nseven\neight\nnine\nten\neleven\n" "" "$BIGTEST" +testing "tail noseek -c+ out of bonds" "tail -c +999" "" "" "$BIGTEST" + +makebigfile() +{ + + for j in $(seq 1 100) + do + printf "%s " $j + for i in $(seq 1 100) + do + printf %s 123456789abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ + done + echo + done +} +makebigfile > bigfile + +testing "tail -c 12345 -n 3 bigfile" "tail -c 12345 -n 3 bigfile | md5sum" \ + "347bbdcbad8a313f4dc7bd558c5bfcb8 -\n" "" "" +testing "tail -n 3 -c 12345 bigfile" "tail -n 3 -c 12345 bigfile | md5sum" \ + "1698825a750288284ec3ba7d8a59f302 -\n" "" "" diff --git a/tests/tar.test b/tests/tar.test new file mode 100644 index 0000000..187186a --- /dev/null +++ b/tests/tar.test @@ -0,0 +1,73 @@ +#!/bin/bash + +# Copyright 2014 Divya Kothari +# Copyright 2014 Naha Maggu + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +#Creating dir +mkdir dir/dir1 -p +echo "This is testdata" > dir/dir1/file +testing "tar tgz - compession, extraction and data validation" "tar -czf dir.tgz dir/ && [ -e dir.tgz ] && echo 'yes'; rm -rf dir; tar -xf dir.tgz && [ -f dir/dir1/file ] && cat dir/dir1/file; rm -rf dir.tgz" "yes\nThis is testdata\n" "" "" + +#Creating dir +mkdir dir/dir1 -p +echo "This is testdata" > dir/dir1/file +testing "tar tar.gz - compession, extraction and data validation" "tar -czf dir.tar.gz dir/ && [ -e dir.tar.gz ] && echo 'yes'; rm -rf dir; tar -xf dir.tar.gz && [ -f dir/dir1/file ] && cat dir/dir1/file; rm -rf dir.tar.gz" "yes\nThis is testdata\n" "" "" + +#Creating dir +mkdir dir/dir1 -p +echo "This is testdata" > dir/dir1/file +testing "tar verbose compression" "tar -cvzf dir.tgz dir/; rm -rf dir.tgz" "dir/\ndir/dir1/\ndir/dir1/file\n" "" "" +rm -rf dir/ + +#creating test file +dd if=/dev/zero of=testFile ibs=4096 obs=4096 count=1000 2>/dev/null +testing "tar - compession and extraction of a file" "tar -czf testFile.tgz testFile && [ -e testFile.tgz ] && echo 'yes'; rm -rf testFile; tar -xf testFile.tgz && [ -f testFile ] && echo 'yes'; rm -rf testFile.tgz" "yes\nyes\n" "" "" + +#creating empty test file +touch testFile +testing "tar - compession and extraction of a empty file" "tar -czf testFile.tgz testFile && [ -e testFile.tgz ] && echo 'yes'; rm -rf testFile; tar -xf testFile.tgz && [ -f testFile ] && echo 'yes'; rm -rf testFile.tgz" "yes\nyes\n" "" "" + +#Creating dir +mkdir dir/dir1 -p +touch dir/dir1/file1 dir/dir1/file2 dir/dir1/file3 dir/dir1/file4 +testing "tar -t option" "tar -czf dir.tar.gz dir/; rm -rf dir; tar -tf dir.tar.gz; rm -rf dir.tar.gz" "dir/\ndir/dir1/\ndir/dir1/file2\ndir/dir1/file4\ndir/dir1/file3\ndir/dir1/file1\n" "" "" +rm -rf dir/ + +#Creating nested directory +mkdir -p dir/dir1 dir/dir2 dir/dir3 dir/dir4 +echo "This is testdata" > dir/dir1/file; echo "Dont exclude me" > dir/dir3/file1 ; +echo "Exclude me" > dir/dir3/file2 ; echo "YO" > dir/dir4/file1 ; echo "Hello" >dir/dir4/file2; echo "Dont" > dir/dir2/file1 +echo "dir/dir4\ndir/dir3/file2" > exclude_file +testing "Creating tar with files excluded : -X" "tar -cvzf dir.tgz dir/ -X exclude_file ; rm -rf dir ; tar -tf dir.tgz; rm -rf dir.tgz " "dir/\ndir/dir2/\ndir/dir2/file1\ndir/dir1/\ndir/dir1/file\ndir/dir3/\ndir/dir3/file1\ndir/\ndir/dir2/\ndir/dir2/file1\ndir/dir1/\ndir/dir1/file\ndir/dir3/\ndir/dir3/file1\n" "" "" +rm -rf exclude_file + +#Creating nested directory +mkdir dir/dir1 -p ; mkdir dir/dir2 ; mkdir dir/dir3 ; mkdir dir/dir4 +echo "This is testdata" > dir/dir1/file +echo "Dont exclude me" > dir/dir3/file1 ; echo "Exclude me" > dir/dir3/file2 ; echo "YO" > dir/dir4/file1 ; echo "Hello" >dir/dir4/file2; echo "Dont" > dir/dir2/file1 +testing "tar with pattern --exclude" "tar --exclude=dir/dir3/* -cvzf dir.tgz dir/ ; rm -rf dir ; tar -tf dir.tgz; rm -rf dir.tgz " "dir/\ndir/dir2/\ndir/dir2/file1\ndir/dir1/\ndir/dir1/file\ndir/dir3/\ndir/dir4/\ndir/dir4/file2\ndir/dir4/file1\ndir/\ndir/dir2/\ndir/dir2/file1\ndir/dir1/\ndir/dir1/file\ndir/dir3/\ndir/dir4/\ndir/dir4/file2\ndir/dir4/file1\n" "" "" + +#Creating directory to be compressed +mkdir dir/dir1 -p +echo "This is testdata" > dir/dir1/file +mkdir temp +testing "Extraction with -C Dir" "tar -czf dir.tgz dir/ ;rm -rf dir ;tar -xf dir.tgz -C temp/ ; [ -e temp/dir ] && echo 'yes' ; rm -rf dir dir.tgz" "yes\n" "" "" +rm -rf temp + +#Creating nested directory +mkdir dir/dir1 -p ; mkdir dir/dir2 ; mkdir dir/dir3 ; mkdir dir/dir4 ; mkdir temp_dir +echo "dir1/file" > dir/dir1/file ; echo "temp_dir/file" > temp_dir/file +echo "dir3/file1" > dir/dir3/file1 ; echo "dir3/file2" > dir/dir3/file2 ; echo "YO" > dir/dir4/file1 ; echo "Hello" >dir/dir4/file2; echo "dir2/file1" > dir/dir2/file1 +echo "temp_dir/file" > exclude_file +testing "Creating tar extra files/directory included : -T" "tar -czf dir.tgz dir/ -T exclude_file ; rm -rf dir ; tar -tf dir.tgz; rm -rf dir.tgz " "dir/\ndir/dir2/\ndir/dir2/file1\ndir/dir1/\ndir/dir1/file\ndir/dir3/\ndir/dir3/file2\ndir/dir3/file1\ndir/dir4/\ndir/dir4/file2\ndir/dir4/file1\ntemp_dir/file\n" "" "" +rm -rf exclude_file +rm -rf temp_dir + +#Creating dir +mkdir dir/dir1 -p +echo "Inside dir/dir1" > dir/dir1/file ; echo "Hello Inside dir" > dir/file +testing "Exctraction on STDOUT : -O" " tar -czf dir.tgz dir/ ; rm -rf dir ; tar -xf dir.tgz -O ; [ -e 'Inside dir/dir1/\nHello Inside dir\n' ] && echo 'yes'; rm -rf dir.tgz " "" "" "" diff --git a/tests/test.test b/tests/test.test new file mode 100755 index 0000000..f501157 --- /dev/null +++ b/tests/test.test @@ -0,0 +1,67 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +# TODO: Should also have device and socket files + +mkdir d +touch f +ln -s /dev/null L +echo nonempty > s +mkfifo p + +type_test() +{ + result="" + for i in d f L s p n + do + if test $* $i + then + result=$result$i + fi + done + printf "%s" $result +} + +testing "test -b" "type_test -b" "" "" "" +testing "test -c" "type_test -c" "L" "" "" +testing "test -d" "type_test -d" "d" "" "" +testing "test -f" "type_test -f" "fs" "" "" +testing "test -h" "type_test -h" "L" "" "" +testing "test -L" "type_test -L" "L" "" "" +testing "test -s" "type_test -s" "ds" "" "" +testing "test -S" "type_test -S" "" "" "" +testing "test -p" "type_test -p" "p" "" "" +testing "test -e" "type_test -e" "dfLsp" "" "" +testing "test ! -e" "type_test ! -e" "n" "" "" + +rm f L s p +rmdir d + +# TODO: Test rwx gu t + +testing "test" "test "" || test a && echo yes" "yes\n" "" "" +testing "test -n" "test -n "" || test -n a && echo yes" "yes\n" "" "" +testing "test -z" "test -n a || test -n "" && echo yes" "yes\n" "" "" +testing "test a = b" "test a = b || test "" = "" && echo yes" "yes\n" "" "" +testing "test a != b" "test "" != "" || test a = b && echo yes" "yes\n" "" "" + +arith_test() +{ + test -1 $1 1 && echo l + test 0 $1 0 && echo e + test -3 $1 -5 && echo g +} + +testing "test -eq" "arith_test -eq" "e\n" "" "" +testing "test -ne" "arith_test -ne" "l\ng\n" "" "" +testing "test -gt" "arith_test -gt" "g\n" "" "" +testing "test -ge" "arith_test -ge" "e\ng\n" "" "" +testing "test -lt" "arith_test -lt" "l\n" "" "" +testing "test -le" "arith_test -le" "l\ne\n" "" "" + +# test ! = -o a +# test ! \( = -o a \) +# test \( ! = \) -o a diff --git a/tests/touch.test b/tests/touch.test new file mode 100755 index 0000000..03ab8ce --- /dev/null +++ b/tests/touch.test @@ -0,0 +1,24 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +testing "touch" "touch walrus && [ -e walrus ] && echo yes" "yes\n" "" "" +testing "touch 1 2 3" "touch one two three && rm one two three && echo yes" "yes\n" \ + "" "" +testing "touch -c" "touch -c walrus && [ -e walrus ] && echo yes" "yes\n" "" "" +testing "touch -c missing" "touch -c warrus && [ ! -e warrus ] && echo yes" \ + "yes\n" "" "" + +# This isn't testing fraction of a second because I dunno how to read it back + +testing "touch -d" \ + "touch -d 2009-02-13T23:31:30.12Z walrus && date -r walrus +%s.%N" "1234567890\n" \ + "" "" +#testing "touch -t" "touch -t 200902132331.42 +#testing "touch -r" +#testing "touch -a" +#testing "touch -m" +#testing "touch -am" +rm walrus diff --git a/tests/useradd.test b/tests/useradd.test new file mode 100644 index 0000000..a87da07 --- /dev/null +++ b/tests/useradd.test @@ -0,0 +1,90 @@ +#!/bin/bash + +# Copyright 2013 Divya Kothari +# Copyright 2013 Robin Mittal + +[ -f testing.sh ] && . testing.sh + +# 70 characters long string; hereafter, we will use it as per our need. +_s70="abcdefghijklmnopqrstuvwxyz123456789abcdefghijklmnopqrstuvwxyz123456789" + +# Redirecting all output to /dev/null for grep, adduser and deluser +arg="&>/dev/null" + +#testing "name" "command" "result" "infile" "stdin" + +# Default password for adding user is: 'password' +pass=`echo -ne 'password\npassword\n'` + +testing "adduser user_name (text)" "useradd toyTestUser $arg || + grep '^toyTestUser:' /etc/passwd $arg && test -d /home/toyTestUser && + userdel toyTestUser $arg && rm -rf /home/toyTestUser && echo 'yes'" \ + "yes\n" "" "$pass" + +testing "adduser user_name (alphanumeric)" "useradd toy1Test2User3 $arg || + grep '^toy1Test2User3:' /etc/passwd $arg && test -d /home/toy1Test2User3 && + userdel toy1Test2User3 $arg && rm -rf /home/toy1Test2User3 && echo 'yes'" \ + "yes\n" "" "$pass" + +testing "adduser user_name (numeric)" "useradd 987654321 $arg || + grep '^987654321:' /etc/passwd $arg && test -d /home/987654321 && + userdel 987654321 $arg && rm -rf /home/987654321 && echo 'yes'" \ + "yes\n" "" "$pass" + +testing "adduser user_name (with ./-/_)" "useradd toy.1Test-2User_3 $arg || + grep '^toy.1Test-2User_3:' /etc/passwd $arg && + test -d /home/toy.1Test-2User_3 && userdel toy.1Test-2User_3 $arg && + rm -rf /home/toy.1Test-2User_3 && echo 'yes'" "yes\n" "" "$pass" + +testing "adduser user_name (long string)" "useradd $_s70 $arg || + grep '^$_s70:' /etc/passwd $arg && test -d /home/$_s70 && + userdel $_s70 $arg && rm -rf /home/$_s70 && echo 'yes'" "yes\n" "" "$pass" + +testing "adduser user_name with dir" "useradd -h $PWD/dir toyTestUser $arg || + grep '^toyTestUser:.*dir' /etc/passwd $arg && test -d $PWD/dir && + userdel toyTestUser $arg && rm -rf $PWD/dir && echo 'yes'" "yes\n" "" "$pass" + +gecos="aaa,bbb,ccc,ddd,eee" +testing "adduser user_name with gecos" "useradd -g '$gecos' toyTestUser $arg || + grep '^toyTestUser:.*$gecos' /etc/passwd $arg && test -d /home/toyTestUser && + userdel toyTestUser $arg && rm -rf /home/toyTestUser && echo 'yes'" \ + "yes\n" "" "$pass" + +shl="/bin/sh" +testing "adduser user_name with shell" "useradd -s $shl toyTestUser $arg || + grep '^toyTestUser:.*$shl$' /etc/passwd $arg && test -d /home/toyTestUser && + userdel toyTestUser $arg && rm -rf /home/toyTestUser && echo 'yes'" \ + "yes\n" "" "$pass" + +g_name="root" +g_id=`grep $g_name /etc/group | cut -d : -f 3` +testing "adduser user_name with group" "useradd -G $g_name toyTestUser $arg || + grep '^toyTestUser:.*:.*:$g_id:.*' /etc/passwd $arg && + test -d /home/toyTestUser && userdel toyTestUser $arg && + rm -rf /home/toyTestUser && echo 'yes'" "yes\n" "" "$pass" + +testing "adduser user_name (system user)" "useradd -S toyTestUser $arg || + grep '^toyTestUser:.*:.*:.*' /etc/passwd $arg && + test ! -e /home/toyTestUser && userdel toyTestUser $arg && echo 'yes'" \ + "yes\n" "" "$pass" + +testing "adduser user_name with -D" "useradd -D toyTestUser $arg || + grep '^toyTestUser:.*:.*:.*' /etc/passwd $arg && test -d /home/toyTestUser && + userdel toyTestUser $arg && rm -rf /home/toyTestUser && echo 'yes'" \ + "yes\n" "" "$pass" + +testing "adduser user_name with -H" "useradd -H toyTestUser $arg || + grep '^toyTestUser:.*:.*:.*' /etc/passwd $arg && + test ! -e /home/toyTestUser && userdel toyTestUser $arg && echo 'yes'" \ + "yes\n" "" "$pass" + +testing "adduser user_name with dir and -H" \ + "useradd -H -h $PWD/dir toyTestUser $arg || + grep '^toyTestUser:.*dir' /etc/passwd $arg && test ! -e $PWD/dir && + userdel toyTestUser $arg && echo 'yes'" "yes\n" "" "$pass" + +testing "adduser user_name with user_id" "useradd -u 49999 toyTestUser $arg || + grep '^toyTestUser:x:49999:.*' /etc/passwd $arg && + test -d /home/toyTestUser && userdel toyTestUser $arg && + rm -rf /home/toyTestUser && echo 'yes'" "yes\n" "" "$pass" + diff --git a/tests/uudecode.test b/tests/uudecode.test new file mode 100644 index 0000000..b9d7d01 --- /dev/null +++ b/tests/uudecode.test @@ -0,0 +1,27 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +testing "uudecode uu empty file" "uudecode -o /dev/stdout && echo yes" \ + "yes\n" "" "begin 744 test\n\`\nend\n" +testing "uudecode uu 1-char" "uudecode -o /dev/stdout" "a" "" \ + "begin 744 test\n!80 \n\`\nend\n" +testing "uudecode uu 2-char" "uudecode -o /dev/stdout" "ab" "" \ + "begin 744 test\n\"86( \n\`\nend\n" +testing "uudecode uu 3-char" "uudecode -o /dev/stdout" "abc" "" \ + "begin 744 test\n#86)C\n\`\nend\n" + +testing "uudecode b64 empty file" "uudecode -o /dev/stdout && echo yes" \ + "yes\n" "" "begin-base64 744 test\n====\n" +testing "uudecode b64 1-char" "uudecode -o /dev/stdout" "a" "" \ + "begin-base64 744 test\nYQ==\n====\n" +testing "uudecode b64 2-char" "uudecode -o /dev/stdout" "ab" "" \ + "begin-base64 744 test\nYWI=\n====\n" +testing "uudecode b64 3-char" "uudecode -o /dev/stdout" "abc" "" \ + "begin-base64 744 test\nYWJj\n====\n" + +testing "uudecode filename" "uudecode && echo -ne 'abc' | cmp uudecode-fn-test /dev/stdin && echo -ne yes && rm uudecode-fn-test" \ + "yes" "" "begin-base64 744 uudecode-fn-test\nYWJj\n====\n" + diff --git a/tests/uuencode.test b/tests/uuencode.test new file mode 100644 index 0000000..7c19faa --- /dev/null +++ b/tests/uuencode.test @@ -0,0 +1,26 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +testing "uuencode not enough args [fail]" "uuencode 2>/dev/null" "" "" "" + +testing "uuencode uu empty file" "uuencode test" \ + "begin 744 test\nend\n" "" "" +testing "uuencode uu 1-char" "uuencode test" \ + "begin 744 test\n!80\`\`\nend\n" "" "a" +testing "uuencode uu 2-char" "uuencode test" \ + "begin 744 test\n\"86(\`\nend\n" "" "ab" +testing "uuencode uu 3-char" "uuencode test" \ + "begin 744 test\n#86)C\nend\n" "" "abc" + +testing "uuencode b64 empty file" "uuencode -m test" \ + "begin-base64 744 test\n====\n" "" "" +testing "uuencode b64 1-char" "uuencode -m test" \ + "begin-base64 744 test\nYQ==\n====\n" "" "a" +testing "uuencode b64 2-char" "uuencode -m test" \ + "begin-base64 744 test\nYWI=\n====\n" "" "ab" +testing "uuencode b64 3-char" "uuencode -m test" \ + "begin-base64 744 test\nYWJj\n====\n" "" "abc" + diff --git a/tests/wc.test b/tests/wc.test new file mode 100755 index 0000000..4089132 --- /dev/null +++ b/tests/wc.test @@ -0,0 +1,48 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +cat >file1 </dev/null && echo yes" "yes\n" "" "" +testing "wc empty file" "wc" "0 0 0\n" "" "" +testing "wc standard input" "wc" "1 3 5\n" "" "a b\nc" +testing "wc -c" "wc -c file1" "26 file1\n" "" "" +testing "wc -l" "wc -l file1" "4 file1\n" "" "" +testing "wc -w" "wc -w file1" "5 file1\n" "" "" +testing "wc format" "wc file1" "4 5 26 file1\n" "" "" +testing "wc multiple files" "wc input - file1" \ + "1 2 3 input\n0 2 3 -\n4 5 26 file1\n5 9 32 total\n" "a\nb" "a b" + +optional TOYBOX_I18N + +#Tests for wc -m +if printf "%s" "$LANG" | grep -q UTF-8 +then + +printf " " > file1 +for i in $(seq 1 8192) +do + printf "ü" >> file1 +done +testing "wc -m" "wc -m file1" "8193 file1\n" "" "" +printf " " > file1 +for i in $(seq 1 8192) +do + printf "ü" >> file1 +done +testing "wc -m (invalid chars)" "wc -m file1" "8193 file1\n" "" "" +testing "wc -mlw" "wc -mlw input" "1 2 11 input\n" "hello, 世界!\n" "" + +else +printf "skipping tests for wc -m" +fi + +rm file1 diff --git a/tests/xargs.test b/tests/xargs.test new file mode 100755 index 0000000..e49445d --- /dev/null +++ b/tests/xargs.test @@ -0,0 +1,35 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +testing "xargs" "xargs && echo yes" "hello\nyes\n" "" "hello" +testing "xargs spaces" "xargs" \ + "one two three four\n" "" "one two\tthree \nfour\n\n" + +testing "xargs -n 0" "xargs -n 0 2>/dev/null || echo ok" "ok\n" \ + "" "one \ntwo\n three" +testing "xargs -n 2" "xargs -n 2" "one two\nthree\n" "" "one \ntwo\n three" +testing "xargs -n exact match" "xargs -n 3" "one two three\n" "" "one two three" +testing "xargs2" "xargs -n2" "one two\nthree four\nfive\n" "" \ + "one two three four five" +testing "xargs -s too long" "xargs -s 9 echo 2>/dev/null || echo ok" \ + "one\ntwo\nok\n" "" "one two three" +testing "xargs -s 13" "xargs -s 13 echo" "one two\nthree\n" "" "one \ntwo\n three" +testing "xargs -s 12" "xargs -s 12 echo" "one\ntwo\nthree\n" "" "one \ntwo\n three" + +touch one two three +testing "xargs command -opt" "xargs -n2 ls -1" "one\ntwo\nthree\n" "" \ + "one two three" +rm one two three + +exit + +testing "xargs -n exact match" +testing "xargs -s exact match" +testing "xargs -s 0" +testing "xargs -s impossible" + +# xargs command_not_found - returns 127 +# xargs false - returns 1 diff --git a/tests/xzcat.test b/tests/xzcat.test new file mode 100644 index 0000000..e82ca88 --- /dev/null +++ b/tests/xzcat.test @@ -0,0 +1,26 @@ +#!/bin/bash + +# Copyright 2014 Divya Kothari +# Copyright 2014 Naha Maggu + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" +echo "hello" > file +tar -cJf file.xz file +# Get system xzcat +xzcatExe=`which xzcat` +$xzcatExe file.xz > xzcatOut +testing "xzcat - decompresses a single file" "xzcat file.xz > Tempfile && echo "yes"; diff Tempfile xzcatOut && echo "yes"; rm -rf file* xzcatOut Tempfile" "yes\nyes\n" "" "" + +#testing "name" "command" "result" "infile" "stdin" +echo "hello" > file1 +echo "hi" > file2 +echo "Hi, Good morning !! I am a xzcat tester" > file3 +tar -cJf file1.xz file1 +tar -cJf file2.xz file2 +tar -cJf file3.xz file3 +# Get system xzcat +xzcatExe=`which xzcat` +$xzcatExe file1.xz file2.xz file3.xz > xzcatOut +testing "xzcat - decompresses multiple files" "xzcat file1.xz file2.xz file3.xz > Tempfile && echo "yes" ; diff Tempfile xzcatOut && echo "yes"; rm -rf file* xzcatOut Tempfile " "yes\nyes\n" "" "" diff --git a/tests/zcat.test b/tests/zcat.test new file mode 100644 index 0000000..c1297c9 --- /dev/null +++ b/tests/zcat.test @@ -0,0 +1,26 @@ +#!/bin/bash + +# Copyright 2014 Divya Kothari +# Copyright 2014 Naha Maggu + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" +echo "hello" > file +tar -czf file.gz file +# Get system zcat +zcatExe=`which zcat` +$zcatExe file.gz > zcatOut +testing "zcat - decompresses a single file" "zcat file.gz > Tempfile && echo "yes"; diff Tempfile zcatOut && echo "yes"; rm -rf file* zcatOut Tempfile" "yes\nyes\n" "" "" + +#testing "name" "command" "result" "infile" "stdin" +echo "hello" > file1 +echo "hi" > file2 +echo "Hi, Good morning !! I am a bzcat tester" > file3 +tar -czf file1.gz file1 +tar -czf file2.gz file2 +tar -czf file3.gz file3 +# Get system zcat +zcatExe=`which zcat` +$zcatExe file1.gz file2.gz file3.gz > zcatOut +testing "zcat - decompresses multiple files" "zcat file1.gz file2.gz file3.gz > Tempfile && echo "yes" ; diff Tempfile zcatOut && echo "yes"; rm -rf file* zcatOut Tempfile " "yes\nyes\n" "" "" -- cgit v1.2.3