OSDN Git Service

Merge remote-tracking branch 'toybox/master' into HEAD
[android-x86/external-toybox.git] / tests / ls.test
1 #!/bin/bash
2
3 # Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>
4 # Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>
5
6 [ -f testing.sh ] && . testing.sh
7
8 #testing "name" "command" "result" "infile" "stdin"
9 #set -x
10
11 # Creating test-file/dir for testing ls
12 mkdir -p lstest/dir1 lstest/dir2 || exit 1
13 echo "test file1" > lstest/file1.txt
14 echo "test file2" > lstest/file2.txt
15 echo "hidden file1" > lstest/.hfile1
16
17 IN="cd lstest"
18 OUT="cd .. "
19
20 testing "no argument" "$IN && ls; $OUT" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" ""
21 testing "with wild char" "$IN && ls file*; $OUT" "file1.txt\nfile2.txt\n" "" ""
22 testing "with wild char - long listing" "$IN && ls -1 file*; $OUT" "file1.txt\nfile2.txt\n" "" ""
23 testing "with -p" "$IN && ls -p; $OUT" "dir1/\ndir2/\nfile1.txt\nfile2.txt\n" "" ""
24 testing "with -a" "$IN && ls -a; $OUT" \
25         ".\n..\ndir1\ndir2\nfile1.txt\nfile2.txt\n.hfile1\n" "" ""
26 testing "with -A" "$IN && ls -A; $OUT" \
27         "dir1\ndir2\nfile1.txt\nfile2.txt\n.hfile1\n" "" ""
28 testing "with -d" "$IN && ls -d; $OUT" ".\n" "" ""
29 testing "with wild char and -d *" "$IN && ls -d *; $OUT" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" ""
30 testing "with -k" "$IN && ls -k; $OUT" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" ""
31 testing "with -m" "$IN && ls -m; $OUT" "dir1, dir2, file1.txt, file2.txt\n" "" ""
32 testing "with -F" "$IN && ls -F; $OUT" "dir1/\ndir2/\nfile1.txt\nfile2.txt\n" "" ""
33 testing "with -dk *" "$IN && ls -dk *; $OUT" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" ""
34
35 ln -s file1.txt lstest/slink
36 testing "softlink - long listing" "$IN && ls -l slink | awk '{ print \$NF }' ; $OUT" \
37           "file1.txt\n" "" ""
38 rm -f lstest/slink
39
40 ln -s /dev/null/nosuchfile lstest/nosuchfile
41 testing "with -d - broken softlink" "$IN && ls -d nosuchfile; $OUT" "nosuchfile\n" "" ""
42 rm -f lstest/nosuchfile
43
44 rm -rf lstest/* && mkdir -p lstest/dir1 && touch lstest/file1.txt
45 testing "nested recursively" "$IN && ls -R; $OUT" \
46           ".:\ndir1\nfile1.txt\n\n./dir1:\n" "" ""
47
48 rm -rf lstest/* && touch lstest/file1.txt && INODE=`stat -c %i lstest/file1.txt`
49 testing "with -i" "$IN && ls -i 2>/dev/null; $OUT" "$INODE file1.txt\n" "" ""
50 unset INODE
51
52 # Removing test dir for cleanup purpose
53 rm -rf lstest