#!/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 dir1 dir2 || exit 1 echo "test file1" > file1.txt echo "test file2" > file2.txt echo "hidden file1" > .hfile1 testcmd "no argument" "" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" "" testcmd "-C column spacing equals 2" "-C" "dir1 dir2 file1.txt file2.txt\n" \ "" "" testcmd "-x column spacing equals 2" "-x" "dir1 dir2 file1.txt file2.txt\n" \ "" "" testcmd "explicit files" "file*" "file1.txt\nfile2.txt\n" "" "" testcmd "explicit -1" "-1 file*" "file1.txt\nfile2.txt\n" "" "" testcmd "" "-p" "dir1/\ndir2/\nfile1.txt\nfile2.txt\n" "" "" testcmd "" "-a" ".\n..\n.hfile1\ndir1\ndir2\nfile1.txt\nfile2.txt\n" "" "" testcmd "" "-A" ".hfile1\ndir1\ndir2\nfile1.txt\nfile2.txt\n" "" "" testcmd "" "-d" ".\n" "" "" testcmd "" "-d *" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" "" testcmd "" "-k" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" "" testcmd "-m" "-m" "dir1, dir2, file1.txt, file2.txt\n" "" "" testcmd "-F" "-F" "dir1/\ndir2/\nfile1.txt\nfile2.txt\n" "" "" testcmd "-dk *" "-dk *" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" "" testcmd "-Z" "-Z file1.txt | egrep -q '^[^ ]+ file1.txt' || echo fail" "" "" "" testcmd "-lZ" "--full-time -lZ file1.txt | egrep -q '^-[rwx-]+ +[0-9]+ +[^ ]+ +[^ ]+ +[^ ]+ +[0-9]+ [0-9][0-9][0-9][0-9]-[0-9][0-9]-.* file1.txt' || echo fail" "" "" "" ln -s file1.txt slink testcmd "-l symlink" "-l slink | grep -q -- ' slink -> file1.txt' && echo ok" \ "ok\n" "" "" rm -f slink ln -s /dev/null/nosuchfile nosuchfile testcmd "-d broken symlink" "-d nosuchfile" "nosuchfile\n" "" "" rm -f nosuchfile rm -rf file{1,2}.txt .hfile dir1 dir2 mkdir -p dir1 && touch file1.txt dir1/file2 testcmd "" "-R" ".:\ndir1\nfile1.txt\n\n./dir1:\nfile2\n" "" "" rm -rf dir1 file1.txt touch file1.txt testcmd "-i" "-i" "$(stat -c %i file1.txt) file1.txt\n" "" "" testcmd "missing" "does-not-exist 2>&1 >/dev/null | grep -o does-not-exist" \ "does-not-exist\n" "" "" rm -f file1.txt # sort tests TIME=1234567890 for i in one two three four five six seven eight nine ten do touch -d @$((TIME++)) $i done testcmd "" "-r" "two\nthree\nten\nsix\nseven\none\nnine\nfour\nfive\neight\n" \ "" "" testcmd "-w test 1" "-Cw 20" \ "eight one three\nfive seven two\nfour six\nnine ten\n" "" "" testcmd "-w test 2" "-Cw 19" \ "eight seven\nfive six\nfour ten\nnine three\none two\n" "" "" rm -f one two three four five six seven eight nine ten touch a b c d e f testcmd "-w test 3" "-Cw 3" "a\nb\nc\nd\ne\nf\n" "" "" testcmd "-w test 4" "-Cw 4" "a d\nb e\nc f\n" "" "" rm -f a b c d e f touch 'hello world' testcmd "default escaping" "" "hello world\n" "" "" testcmd "-b" "-b" 'hello\\ \\rworld\n' "" "" testcmd "-q" "-q" 'hello ?world\n' "" "" testcmd "-N" "-N" 'hello world\n' "" "" rm hello*