comparison scripts/test/grep.test @ 981:a1a04ea38db2

Clean up grep.test to use "infile" properly, and not try to work around the $PATH behavior of scripts/test.sh. Tested with both TEST_HOST=1 and normal.
author Rob Landley <rob@landley.net>
date Thu, 01 Aug 2013 15:22:52 -0500
parents ba241693c282
children 77cba4e36d48
comparison
equal deleted inserted replaced
980:ba241693c282 981:a1a04ea38db2
8 # This one's tricky both because echo is a shell builtin (so $PATH is 8 # This one's tricky both because echo is a shell builtin (so $PATH is
9 # irrelevant) and because the "result" field is parsed with echo -e. 9 # irrelevant) and because the "result" field is parsed with echo -e.
10 # To make it work, "$CMD" is an explicit path to the command being tested, 10 # To make it work, "$CMD" is an explicit path to the command being tested,
11 # so "result" keeps using the shell builtin but we test the one in toybox. 11 # so "result" keeps using the shell builtin but we test the one in toybox.
12 12
13 CMD="$(which grep)"
14
15 #testing "name" "command" "result" "infile" "stdin" 13 #testing "name" "command" "result" "infile" "stdin"
16 14
17 # test case 1 15 testing "grep -c" "grep -c 123 input" "3\n" "123\ncount 123\n123\nfasdfasdf" ""
18 echo -e "123\ncount 123\n123\nfasdfasdf" > foo
19 testing "grep -c" "$CMD -c 123 foo" "3\n" "" ""
20 rm foo
21 16
22 # test case 2
23 echo -e "this is test" > foo 17 echo -e "this is test" > foo
24 echo -e "this is test2" > foo2 18 echo -e "this is test2" > foo2
25 echo -e "this is foo3" > foo3 19 echo -e "this is foo3" > foo3
26 20 testing "grep -l" "grep -l test foo foo2 foo3" "foo\nfoo2\n" "" ""
27 testing "grep -l" "$CMD -l test foo foo2 foo3" "foo\nfoo2\n" "" ""
28
29 rm foo foo2 foo3 21 rm foo foo2 foo3
30 22
31 # test case 3 23 testing "grep -q" "grep -q test input && echo yes" "yes\n" "this is a test\n" ""
32 24 testing "grep -E" "grep -E [0-9] input" "1234123asdfas123123\n1\n" \
33 echo "this is test" > foo 25 "1234123asdfas123123\nabc\n1\nabcde" ""
34 $CMD -q test foo > res 26 testing "grep -e" "grep -e [0-9] input" "1234123asdfas123123\n1\n" \
35 27 "1234123asdfas123123\nabc\n1\nabcde" ""
36 testing "grep -q" "cat res && echo yes" "yes\n" "" "" 28 testing "grep -F" "grep -F is input" "this is test\nthis is test2\n" \
37 29 "this is test\nthis is test2\ntest case" ""
38 # test case 4
39
40 echo -e "1234123asdfas123123\nabc\n1\nabcde" > foo
41 testing "grep -E" "$CMD -E [0-9] foo" "1234123asdfas123123\n1\n" "" ""
42
43 # test case 5
44
45 echo -e "1234123asdfas123123\nabc\n1\nabcde" > foo
46 testing "grep -e" "$CMD -e [0-9] foo" "1234123asdfas123123\n1\n" "" ""
47
48 # test case 6
49
50 echo -e "this is test\nthis is test2\ntest case" > foo
51 testing "grep -F" "$CMD -F is foo" "this is test\nthis is test2\n" "" ""
52
53 # test case 7
54 30
55 echo -e "this is test\nthis is test2\ntest case" > foo 31 echo -e "this is test\nthis is test2\ntest case" > foo
56 echo -e "hello this is test" > foo2 32 echo -e "hello this is test" > foo2
57 echo -e "hi hello" > foo3 33 echo -e "hi hello" > foo3
34 testing "grep -H" "grep -H is foo foo2 foo3" "foo:this is test\nfoo:this is test2\nfoo2:hello this is test\n" "" ""
35 rm foo foo2 foo3
58 36
59 testing "grep -H" "$CMD -H is foo foo2 foo3" "foo:this is test\nfoo:this is test2\nfoo2:hello this is test\n" "" "" 37 testing "grep -b" "grep -b is input" "0:this is test\n13:this is test2\n" \
60 38 "this is test\nthis is test2\ntest case" ""
61 39 testing "grep -i" "grep -i is input" "thisIs test\nthis is test2\n" \
62 # test case 8 40 "thisIs test\nthis is test2\ntest case" ""
63 41 testing "grep -n" "grep -n is input" "1:this is test\n2:this is test2\n" \
64 echo -e "this is test\nthis is test2\ntest case" > foo 42 "this is test\nthis is test2\ntest case" ""
65 testing "grep -b" "$CMD -b is foo" "0:this is test\n13:this is test2\n" "" "" 43 testing "grep -o" "grep -o is input" "is\nis\nis\nis\n" \
66 44 "this is test\nthis is test2\ntest case" ""
67 45 testing "grep -s" "grep -s hello asdf 2>&1" "" "" ""
68 # test case 9 46 testing "grep -v" "grep -v abc input" "1234123asdfas123123\n1ABa\n" \
69 47 "1234123asdfas123123\n1ABabc\nabc\n1ABa\nabcde" ""
70 echo -e "thisIs test\nthis is test2\ntest case" > foo 48 testing "grep -w" "grep -w abc input" "abc\n" \
71 testing "grep -i" "$CMD -i is foo" "thisIs test\nthis is test2\n" "" "" 49 "1234123asdfas123123\n1ABabc\nabc\n1ABa\nabcde" ""
72
73 # test case 10
74
75 echo -e "this is test\nthis is test2\ntest case" > foo
76
77 testing "grep -n" "$CMD -n is foo" "1:this is test\n2:this is test2\n" "" ""
78
79 # test case 11
80
81 echo -e "this is test\nthis is test2\ntest case" > foo
82 testing "grep -o" "$CMD -o is foo" "is\nis\nis\nis\n" "" ""
83
84 # test case 12
85
86 $CMD -s hello asdf >res1
87 testing "grep -s" "cat res1 && echo yes" "yes\n" "" ""
88
89
90 # test case 13
91
92 echo -e "1234123asdfas123123\n1ABabc\nabc\n1ABa\nabcde" > foo
93 testing "grep -v" "$CMD -v abc foo" "1234123asdfas123123\n1ABa\n" "" ""
94
95 # test case 14
96
97 echo -e "1234123asdfas123123\n1ABabc\nabc\n1ABa\nabcde" > foo
98 testing "grep -w" "$CMD -w abc foo" "abc\n" "" ""