view scripts/test/test.test @ 1087:b73a61542297 draft

I've finally gotten 'cpio' into a shape where it could be useable. This version can archive and extract directories, sockets, FIFOs, devices, symlinks, and regular files. Supported options are -iot, -H FMT (which is a dummy right now). It only writes newc, and could read newc or newcrc. This does NOT implement -d, which essentially is equivalent to mkdir -p $(dirname $FILE) for every file that needs it. Hard links are not supported, though it would be easy to add them given a hash table or something like that. I also have not implemented the "<n> blocks" output on stderr. If desired, I can add it pretty simply. There is one assumption this makes: that the mode of a file, as mode_t, is bitwise equivalent to the mode as defined for the cpio format. This is true of Linux, but is not mandated by POSIX. If it is compiled for a system where that is false, the archives will not be portable.
author Isaac Dunham <ibid.ag@gmail.com>
date Mon, 14 Oct 2013 11:15:22 -0500
parents c2663b7eca78
children
line wrap: on
line source

#!/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