blob: 993d7c89d9df320f13a15d18b7472d939347c8ed [file] [log] [blame]
Ashwini Sharma577377c2013-08-01 01:52:32 -05001#!/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
13CMD="$(which grep)"
14
15#testing "name" "command" "result" "infile" "stdin"
16
17# test case 1
18echo -e "123\ncount 123\n123\nfasdfasdf" > foo
19testing "grep -c" "$CMD -c 123 foo" "3\n" "" ""
20rm foo
21
22# test case 2
23echo -e "this is test" > foo
24echo -e "this is test2" > foo2
25echo -e "this is foo3" > foo3
26
27testing "grep -l" "$CMD -l test foo foo2 foo3" "foo\nfoo2\n" "" ""
28
29rm foo foo2 foo3
30
31# test case 3
32
33echo "this is test" > foo
34$CMD -q test foo > res
35
36testing "grep -q" "cat res && echo yes" "yes\n" "" ""
37
38# test case 4
39
40echo -e "1234123asdfas123123\nabc\n1\nabcde" > foo
41testing "grep -E" "$CMD -E [0-9] foo" "1234123asdfas123123\n1\n" "" ""
42
43# test case 5
44
45echo -e "1234123asdfas123123\nabc\n1\nabcde" > foo
46testing "grep -e" "$CMD -e [0-9] foo" "1234123asdfas123123\n1\n" "" ""
47
48# test case 6
49
50echo -e "this is test\nthis is test2\ntest case" > foo
51testing "grep -F" "$CMD -F is foo" "this is test\nthis is test2\n" "" ""
52
53# test case 7
54
55echo -e "this is test\nthis is test2\ntest case" > foo
56echo -e "hello this is test" > foo2
57echo -e "hi hello" > foo3
58
59testing "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
64echo -e "this is test\nthis is test2\ntest case" > foo
65testing "grep -b" "$CMD -b is foo" "0:this is test\n13:this is test2\n" "" ""
66
67
68# test case 9
69
70echo -e "thisIs test\nthis is test2\ntest case" > foo
71testing "grep -i" "$CMD -i is foo" "thisIs test\nthis is test2\n" "" ""
72
73# test case 10
74
75echo -e "this is test\nthis is test2\ntest case" > foo
76
77testing "grep -n" "$CMD -n is foo" "1:this is test\n2:this is test2\n" "" ""
78
79# test case 11
80
81echo -e "this is test\nthis is test2\ntest case" > foo
82testing "grep -o" "$CMD -o is foo" "is\nis\nis\nis\n" "" ""
83
84# test case 12
85
86$CMD -s hello asdf >res1
87testing "grep -s" "cat res1 && echo yes" "yes\n" "" ""
88
89
90# test case 13
91
92echo -e "1234123asdfas123123\n1ABabc\nabc\n1ABa\nabcde" > foo
93testing "grep -v" "$CMD -v abc foo" "1234123asdfas123123\n1ABa\n" "" ""
94
95# test case 14
96
97echo -e "1234123asdfas123123\n1ABabc\nabc\n1ABa\nabcde" > foo
98testing "grep -w" "$CMD -w abc foo" "abc\n" "" ""