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" "" |
| 45 | testing "grep -s" "grep -s hello asdf 2>&1" "" "" "" |
| 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" "" |