blob: 4f4a9e30b2569cec8af0ffdfeee70ae608638dd6 [file] [log] [blame]
Roger Knecht20a4f702022-04-18 12:54:20 +00001#!/bin/sh
2
3# Copyright 2022 by Roger Knecht <rknecht@pm.me>
4# Licensed under GPLv2, see file LICENSE in this source tree.
5
6. ./testing.sh -v
7
8# testing "description" "command" "result" "infile" "stdin"
9
10testing "tree error opening dir" \
11 "tree tree.tempdir" \
12 "\
13tree.tempdir [error opening dir]\n\
14\n\
150 directories, 0 files\n" \
16 "" ""
17
18mkdir -p tree2.tempdir
19touch tree2.tempdir/testfile
20
21testing "tree single file" \
22 "cd tree2.tempdir && tree" \
23 "\
24.\n\
25└── testfile\n\
26\n\
270 directories, 1 files\n" \
28 "" ""
29
30mkdir -p tree3.tempdir/test1 \
31 tree3.tempdir/test2/a \
32 tree3.tempdir/test2/b \
33 tree3.tempdir/test3/c \
34 tree3.tempdir/test3/d
35
36touch tree3.tempdir/test2/a/testfile1 \
37 tree3.tempdir/test2/a/testfile2 \
38 tree3.tempdir/test2/a/testfile3 \
39 tree3.tempdir/test2/b/testfile4 \
40 tree3.tempdir/test3/c/testfile5 \
41 tree3.tempdir/test3/d/testfile6 \
42 tree3.tempdir/test3/d/.testfile7
43
44(cd tree3.tempdir/test2/a && ln -s ../b/testfile4 .)
45(cd tree3.tempdir/test2/b && ln -s ../../test3 .)
46
47testing "tree nested directories and files" \
48 "cd tree3.tempdir && tree" \
49 "\
50.\n\
51├── test1\n\
52├── test2\n\
53│   ├── a\n\
54│   │   ├── testfile1\n\
55│   │   ├── testfile2\n\
56│   │   ├── testfile3\n\
57│   │   └── testfile4 -> ../b/testfile4\n\
58│   └── b\n\
59│   ├── test3 -> ../../test3\n\
60│   └── testfile4\n\
61└── test3\n\
62 ├── c\n\
63 │   └── testfile5\n\
64 └── d\n\
65 └── testfile6\n\
66\n\
677 directories, 8 files\n" \
68 "" ""
69#note: tree v2.0.1 says "8 directories, 7 files":
70#it counts "test3 -> ../../test3" as a directory, even though it does not follow this symlink
71
72testing "tree multiple directories" \
73 "tree tree2.tempdir tree3.tempdir" \
74 "\
75tree2.tempdir\n\
76└── testfile\n\
77tree3.tempdir\n\
78├── test1\n\
79├── test2\n\
80│   ├── a\n\
81│   │   ├── testfile1\n\
82│   │   ├── testfile2\n\
83│   │   ├── testfile3\n\
84│   │   └── testfile4 -> ../b/testfile4\n\
85│   └── b\n\
86│   ├── test3 -> ../../test3\n\
87│   └── testfile4\n\
88└── test3\n\
89 ├── c\n\
90 │   └── testfile5\n\
91 └── d\n\
92 └── testfile6\n\
93\n\
947 directories, 9 files\n" \
95 "" ""
96#note: tree v2.0.1 says "8 directories, 7 files" (not "8 files", probably a/testfile4 -> ../b/testfile4 and b/testfile4 are counted as one file, not 2?)
97
98rm -rf tree.tempdir tree2.tempdir tree3.tempdir
99
100exit $FAILCOUNT