blob: 13b8e0bb5895dd898748794ad382b539387f0e2c [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
Ashwini Sharma577377c2013-08-01 01:52:32 -050013#testing "name" "command" "result" "infile" "stdin"
14
Rob Landley3595eff2013-08-01 15:22:52 -050015testing "grep -c" "grep -c 123 input" "3\n" "123\ncount 123\n123\nfasdfasdf" ""
Ashwini Sharma577377c2013-08-01 01:52:32 -050016
Ashwini Sharma577377c2013-08-01 01:52:32 -050017echo -e "this is test" > foo
18echo -e "this is test2" > foo2
19echo -e "this is foo3" > foo3
Rob Landley3595eff2013-08-01 15:22:52 -050020testing "grep -l" "grep -l test foo foo2 foo3" "foo\nfoo2\n" "" ""
Ashwini Sharma577377c2013-08-01 01:52:32 -050021rm foo foo2 foo3
22
Rob Landley3595eff2013-08-01 15:22:52 -050023testing "grep -q" "grep -q test input && echo yes" "yes\n" "this is a test\n" ""
24testing "grep -E" "grep -E [0-9] input" "1234123asdfas123123\n1\n" \
25 "1234123asdfas123123\nabc\n1\nabcde" ""
26testing "grep -e" "grep -e [0-9] input" "1234123asdfas123123\n1\n" \
27 "1234123asdfas123123\nabc\n1\nabcde" ""
28testing "grep -F" "grep -F is input" "this is test\nthis is test2\n" \
29 "this is test\nthis is test2\ntest case" ""
Ashwini Sharma577377c2013-08-01 01:52:32 -050030
31echo -e "this is test\nthis is test2\ntest case" > foo
32echo -e "hello this is test" > foo2
33echo -e "hi hello" > foo3
Rob Landley3595eff2013-08-01 15:22:52 -050034testing "grep -H" "grep -H is foo foo2 foo3" "foo:this is test\nfoo:this is test2\nfoo2:hello this is test\n" "" ""
35rm foo foo2 foo3
Ashwini Sharma577377c2013-08-01 01:52:32 -050036
Rob Landley3595eff2013-08-01 15:22:52 -050037testing "grep -b" "grep -b is input" "0:this is test\n13:this is test2\n" \
38 "this is test\nthis is test2\ntest case" ""
39testing "grep -i" "grep -i is input" "thisIs test\nthis is test2\n" \
40 "thisIs test\nthis is test2\ntest case" ""
41testing "grep -n" "grep -n is input" "1:this is test\n2:this is test2\n" \
42 "this is test\nthis is test2\ntest case" ""
43testing "grep -o" "grep -o is input" "is\nis\nis\nis\n" \
44 "this is test\nthis is test2\ntest case" ""
Rob Landley7b72ab42013-08-04 15:04:08 -050045testing "grep -s" "grep -hs hello asdf input 2>&1" "hello\n" "hello\n" ""
Rob Landley3595eff2013-08-01 15:22:52 -050046testing "grep -v" "grep -v abc input" "1234123asdfas123123\n1ABa\n" \
47 "1234123asdfas123123\n1ABabc\nabc\n1ABa\nabcde" ""
48testing "grep -w" "grep -w abc input" "abc\n" \
49 "1234123asdfas123123\n1ABabc\nabc\n1ABa\nabcde" ""
Rob Landley7b72ab42013-08-04 15:04:08 -050050testing "grep -x" "grep -x abc input" "abc\n" \
51 "aabcc\nabc\n" ""
52
53testing "grep -H (standard input)" "grep -H abc" "(standard input):abc\n" \
54 "" "abc\n"
55testing "grep -l (standard input)" "grep -l abc" "(standard input)\n" \
56 "" "abc\n"
57testing "grep -n two inputs" "grep -hn def - input" "2:def\n2:def\n" \
58 "abc\ndef\n" "abc\ndef\n"
59
60testing "grep pattern with newline" "grep 'abc
61def' input" "aabcc\nddeff\n" \
62 "aaaa\naabcc\n\dddd\nddeff\nffff\n" ""
63
64testing "grep -lH" "grep -lH abc input" "input\n" "abc\n" ""
65testing "grep -cn" "grep -cn abc input" "1\n" "abc\n" ""
66testing "grep -qs" "grep -qs abc none input && echo yes" "yes\n" "abc\n" ""
67testing "grep -hl" "grep -hl abc input" "input\n" "abc\n" ""
68testing "grep -b stdin" "grep -b one" "0:one\n4:one\n8:one\n" "" "one\none\none\n"
69testing "grep -o overlap" "grep -bo aaa" "1:aaa\n" "" "baaaa\n"
70testing "grep -co" "grep -co one input" "3\n" "one one one\n" ""
71testing "grep -nom" "grep -nom 2 one" "1:one\n1:one\n1:one\n2:one\n2:one\n" \
72 "" "one one one\none one\none"
73testing "grep -vo" "grep -vo one input" "twothree\n" "onetwoonethreeone\n" ""
74testing "grep no newline" "grep -h one input -" \
75 "hello one\nthere one\n" "hello one" "there one"