xref: /aosp_15_r20/external/toybox/tests/rev.test (revision cf5a6c84e2b8763fc1a7db14496fd4742913b199)
1*cf5a6c84SAndroid Build Coastguard Worker#!/bin/bash
2*cf5a6c84SAndroid Build Coastguard Worker
3*cf5a6c84SAndroid Build Coastguard Worker[ -f testing.sh ] && . testing.sh
4*cf5a6c84SAndroid Build Coastguard Worker
5*cf5a6c84SAndroid Build Coastguard Worker#testing "name" "command" "result" "infile" "stdin"
6*cf5a6c84SAndroid Build Coastguard Worker
7*cf5a6c84SAndroid Build Coastguard Workerecho -e "one" > file1
8*cf5a6c84SAndroid Build Coastguard Workerecho -e "two" > file2
9*cf5a6c84SAndroid Build Coastguard Workertesting "rev" "rev && echo yes" "orez\nyes\n" "" "zero\n"
10*cf5a6c84SAndroid Build Coastguard Workertoyonly testing "-" "rev - && echo yes" "orez\nyes\n" "" "zero\n"
11*cf5a6c84SAndroid Build Coastguard Workertesting "file1 file2" "rev file1 file2" "eno\nowt\n" "" ""
12*cf5a6c84SAndroid Build Coastguard Workertoyonly testing "- file"      "rev - file1"     "orez\neno\n" "" "zero\n"
13*cf5a6c84SAndroid Build Coastguard Workertoyonly testing "file -"      "rev file1 -"     "eno\norez\n" "" "zero\n"
14*cf5a6c84SAndroid Build Coastguard Workertoyonly testing "no trailing newline" "rev input" "cba\nfed\n" "abc\ndef" ""
15*cf5a6c84SAndroid Build Coastguard Worker
16*cf5a6c84SAndroid Build Coastguard Workertesting "file1 notfound file2" \
17*cf5a6c84SAndroid Build Coastguard Worker        "rev file1 notfound file2 2>stderr && echo ok ; grep -o 'notfound: No such file or directory' stderr; rm stderr" \
18*cf5a6c84SAndroid Build Coastguard Worker        "eno\nowt\nnotfound: No such file or directory\n" "" ""
19*cf5a6c84SAndroid Build Coastguard Worker
20*cf5a6c84SAndroid Build Coastguard Workertesting "different input sizes"\
21*cf5a6c84SAndroid Build Coastguard Worker        "rev"\
22*cf5a6c84SAndroid Build Coastguard Worker        "\n1\n21\n321\n4321\n54321\n4321\n321\n21\n1\n\n"\
23*cf5a6c84SAndroid Build Coastguard Worker        "" "\n1\n12\n123\n1234\n12345\n1234\n123\n12\n1\n\n"
24*cf5a6c84SAndroid Build Coastguard Worker
25*cf5a6c84SAndroid Build Coastguard Workerrm file1 file2
26