Ashwini Sharma | 577377c | 2013-08-01 01:52:32 -0500 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | [ -f testing.sh ] && . testing.sh |
| 4 | |
| 5 | # Copyright 2013 by Kyungsu Kim <kaspyx@gmail.com> |
| 6 | # Copyright 2013 by Kyungwan Han <asura321@gmail.com> |
| 7 | |
| 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. |
| 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. |
| 12 | |
| 13 | CMD="$(which grep)" |
| 14 | |
| 15 | #testing "name" "command" "result" "infile" "stdin" |
| 16 | |
| 17 | # test case 1 |
| 18 | echo -e "123\ncount 123\n123\nfasdfasdf" > foo |
| 19 | testing "grep -c" "$CMD -c 123 foo" "3\n" "" "" |
| 20 | rm foo |
| 21 | |
| 22 | # test case 2 |
| 23 | echo -e "this is test" > foo |
| 24 | echo -e "this is test2" > foo2 |
| 25 | echo -e "this is foo3" > foo3 |
| 26 | |
| 27 | testing "grep -l" "$CMD -l test foo foo2 foo3" "foo\nfoo2\n" "" "" |
| 28 | |
| 29 | rm foo foo2 foo3 |
| 30 | |
| 31 | # test case 3 |
| 32 | |
| 33 | echo "this is test" > foo |
| 34 | $CMD -q test foo > res |
| 35 | |
| 36 | testing "grep -q" "cat res && echo yes" "yes\n" "" "" |
| 37 | |
| 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 | |
| 55 | echo -e "this is test\nthis is test2\ntest case" > foo |
| 56 | echo -e "hello this is test" > foo2 |
| 57 | echo -e "hi hello" > foo3 |
| 58 | |
| 59 | testing "grep -H" "$CMD -H is foo foo2 foo3" "foo:this is test\nfoo:this is test2\nfoo2:hello this is test\n" "" "" |
| 60 | |
| 61 | |
| 62 | # test case 8 |
| 63 | |
| 64 | echo -e "this is test\nthis is test2\ntest case" > foo |
| 65 | testing "grep -b" "$CMD -b is foo" "0:this is test\n13:this is test2\n" "" "" |
| 66 | |
| 67 | |
| 68 | # test case 9 |
| 69 | |
| 70 | echo -e "thisIs test\nthis is test2\ntest case" > foo |
| 71 | testing "grep -i" "$CMD -i is foo" "thisIs test\nthis is test2\n" "" "" |
| 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" "" "" |