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 | |
Ashwini Sharma | 577377c | 2013-08-01 01:52:32 -0500 | [diff] [blame] | 13 | #testing "name" "command" "result" "infile" "stdin" |
| 14 | |
Rob Landley | 3595eff | 2013-08-01 15:22:52 -0500 | [diff] [blame] | 15 | testing "grep -c" "grep -c 123 input" "3\n" "123\ncount 123\n123\nfasdfasdf" "" |
Ashwini Sharma | 577377c | 2013-08-01 01:52:32 -0500 | [diff] [blame] | 16 | |
Ashwini Sharma | 577377c | 2013-08-01 01:52:32 -0500 | [diff] [blame] | 17 | echo -e "this is test" > foo |
| 18 | echo -e "this is test2" > foo2 |
| 19 | echo -e "this is foo3" > foo3 |
Rob Landley | 3595eff | 2013-08-01 15:22:52 -0500 | [diff] [blame] | 20 | testing "grep -l" "grep -l test foo foo2 foo3" "foo\nfoo2\n" "" "" |
Ashwini Sharma | 577377c | 2013-08-01 01:52:32 -0500 | [diff] [blame] | 21 | rm foo foo2 foo3 |
| 22 | |
Rob Landley | 3595eff | 2013-08-01 15:22:52 -0500 | [diff] [blame] | 23 | testing "grep -q" "grep -q test input && echo yes" "yes\n" "this is a test\n" "" |
| 24 | testing "grep -E" "grep -E [0-9] input" "1234123asdfas123123\n1\n" \ |
| 25 | "1234123asdfas123123\nabc\n1\nabcde" "" |
| 26 | testing "grep -e" "grep -e [0-9] input" "1234123asdfas123123\n1\n" \ |
| 27 | "1234123asdfas123123\nabc\n1\nabcde" "" |
| 28 | testing "grep -F" "grep -F is input" "this is test\nthis is test2\n" \ |
| 29 | "this is test\nthis is test2\ntest case" "" |
Ashwini Sharma | 577377c | 2013-08-01 01:52:32 -0500 | [diff] [blame] | 30 | |
| 31 | echo -e "this is test\nthis is test2\ntest case" > foo |
| 32 | echo -e "hello this is test" > foo2 |
| 33 | echo -e "hi hello" > foo3 |
Rob Landley | 3595eff | 2013-08-01 15:22:52 -0500 | [diff] [blame] | 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 |
Ashwini Sharma | 577377c | 2013-08-01 01:52:32 -0500 | [diff] [blame] | 36 | |
Rob Landley | 3595eff | 2013-08-01 15:22:52 -0500 | [diff] [blame] | 37 | testing "grep -b" "grep -b is input" "0:this is test\n13:this is test2\n" \ |
| 38 | "this is test\nthis is test2\ntest case" "" |
| 39 | testing "grep -i" "grep -i is input" "thisIs test\nthis is test2\n" \ |
| 40 | "thisIs test\nthis is test2\ntest case" "" |
| 41 | testing "grep -n" "grep -n is input" "1:this is test\n2:this is test2\n" \ |
| 42 | "this is test\nthis is test2\ntest case" "" |
| 43 | testing "grep -o" "grep -o is input" "is\nis\nis\nis\n" \ |
| 44 | "this is test\nthis is test2\ntest case" "" |
Rob Landley | 7b72ab4 | 2013-08-04 15:04:08 -0500 | [diff] [blame] | 45 | testing "grep -s" "grep -hs hello asdf input 2>&1" "hello\n" "hello\n" "" |
Rob Landley | 3595eff | 2013-08-01 15:22:52 -0500 | [diff] [blame] | 46 | testing "grep -v" "grep -v abc input" "1234123asdfas123123\n1ABa\n" \ |
| 47 | "1234123asdfas123123\n1ABabc\nabc\n1ABa\nabcde" "" |
| 48 | testing "grep -w" "grep -w abc input" "abc\n" \ |
| 49 | "1234123asdfas123123\n1ABabc\nabc\n1ABa\nabcde" "" |
Rob Landley | 7b72ab4 | 2013-08-04 15:04:08 -0500 | [diff] [blame] | 50 | testing "grep -x" "grep -x abc input" "abc\n" \ |
| 51 | "aabcc\nabc\n" "" |
| 52 | |
| 53 | testing "grep -H (standard input)" "grep -H abc" "(standard input):abc\n" \ |
| 54 | "" "abc\n" |
| 55 | testing "grep -l (standard input)" "grep -l abc" "(standard input)\n" \ |
| 56 | "" "abc\n" |
| 57 | testing "grep -n two inputs" "grep -hn def - input" "2:def\n2:def\n" \ |
| 58 | "abc\ndef\n" "abc\ndef\n" |
| 59 | |
| 60 | testing "grep pattern with newline" "grep 'abc |
| 61 | def' input" "aabcc\nddeff\n" \ |
| 62 | "aaaa\naabcc\n\dddd\nddeff\nffff\n" "" |
| 63 | |
| 64 | testing "grep -lH" "grep -lH abc input" "input\n" "abc\n" "" |
| 65 | testing "grep -cn" "grep -cn abc input" "1\n" "abc\n" "" |
| 66 | testing "grep -qs" "grep -qs abc none input && echo yes" "yes\n" "abc\n" "" |
| 67 | testing "grep -hl" "grep -hl abc input" "input\n" "abc\n" "" |
| 68 | testing "grep -b stdin" "grep -b one" "0:one\n4:one\n8:one\n" "" "one\none\none\n" |
| 69 | testing "grep -o overlap" "grep -bo aaa" "1:aaa\n" "" "baaaa\n" |
| 70 | testing "grep -co" "grep -co one input" "3\n" "one one one\n" "" |
| 71 | testing "grep -nom" "grep -nom 2 one" "1:one\n1:one\n1:one\n2:one\n2:one\n" \ |
| 72 | "" "one one one\none one\none" |
| 73 | testing "grep -vo" "grep -vo one input" "twothree\n" "onetwoonethreeone\n" "" |
| 74 | testing "grep no newline" "grep -h one input -" \ |
| 75 | "hello one\nthere one\n" "hello one" "there one" |
Rob Landley | 133cc5b | 2013-08-11 01:03:26 -0500 | [diff] [blame^] | 76 | |
| 77 | testing "grep -e multi" "grep -e one -ethree input" \ |
| 78 | "three\none\n" "three\ntwo\none\n" "" |
| 79 | # Suppress filenames for recursive test because dunno order they'd occur in |
| 80 | mkdir sub |
| 81 | echo -e "one\ntwo\nthree" > sub/one |
| 82 | echo -e "three\ntwo\none" > sub/two |
| 83 | testing "grep -r" "grep -hr one sub" "one\none\n" "" "" |
| 84 | rm -rf sub |
| 85 | |
| 86 | testing "grep -Fx ''" "grep -Fx '' input" "" "one one one\n" "" |
| 87 | testing "grep -F ''" "grep -F '' input" "one one one\n" "one one one\n" "" |
| 88 | testing "grep -w ''" "grep -w '' input" "" "one one one\n" "" |
| 89 | testing "grep -o ''" "grep -o '' input" "" "one one one\n" "" |