blob: dde3d5c304f58e13dd87f4829ab543476c75887a [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" ""
45testing "grep -s" "grep -s hello asdf 2>&1" "" "" ""
46testing "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" ""