busybox/testsuite/find.tests
David Leonard d8a3360380 find: implement -ok
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html

  -ok  utility_name  [argument ...] ;
    The -ok primary shall be equivalent to -exec, except that the use
    of a <plus-sign> to punctuate the end of the primary expression
    need not be supported, and find shall request affirmation of the
    invocation of utility_name using the current file as an argument
    by writing to standard error as described in the STDERR section. If
    the response on standard input is affirmative, the utility shall be
    invoked. Otherwise, the command shall not be invoked and the value
    of the -ok operand shall be false.

function                                             old     new   delta
do_exec                                              438     517     +79
parse_params                                        1833    1845     +12
static.params                                        288     292      +4
.rodata                                           100771  100775      +4
packed_usage                                       34543   34541      -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/1 up/down: 99/-2)              Total: 97 bytes

Signed-off-by: David Leonard <d+busybox@adaptive-enterprises.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-03-28 18:08:02 +02:00

82 lines
1.8 KiB
Bash
Executable file

#!/bin/sh
# Copyright 2014 by Denys Vlasenko <vda.linux@googlemail.com>
# Licensed under GPLv2, see file LICENSE in this source tree.
. ./testing.sh
# testing "description" "command" "result" "infile" "stdin"
mkdir -p find.tempdir
touch find.tempdir/testfile
optional FEATURE_FIND_TYPE
testing "find -type f" \
"cd find.tempdir && find -type f 2>&1" \
"./testfile\n" \
"" ""
SKIP=
optional FEATURE_FIND_EXEC
testing "find -exec exitcode 1" \
"cd find.tempdir && find testfile -exec true {} \; 2>&1; echo \$?" \
"0\n" \
"" ""
SKIP=
optional FEATURE_FIND_EXEC_PLUS
testing "find -exec exitcode 2" \
"cd find.tempdir && find testfile -exec true {} + 2>&1; echo \$?" \
"0\n" \
"" ""
SKIP=
optional FEATURE_FIND_EXEC_OK
testing "find -ok" \
"cd find.tempdir && find testfile -ok true {} ';' 2>&1; echo \$?" \
"true testfile ?0\n" \
"" "y"
SKIP=
# Surprisingly, "-exec false ;" results in exitcode 0! "-exec false +" is different!!!
optional FEATURE_FIND_EXEC
testing "find -exec exitcode 3" \
"cd find.tempdir && find testfile -exec false {} \; 2>&1; echo \$?" \
"0\n" \
"" ""
SKIP=
optional FEATURE_FIND_EXEC_PLUS
testing "find -exec exitcode 4" \
"cd find.tempdir && find testfile -exec false {} + 2>&1; echo \$?" \
"1\n" \
"" ""
SKIP=
optional FEATURE_FIND_MAXDEPTH
testing "find / -maxdepth 0 -name /" \
"find / -maxdepth 0 -name /" \
"/\n" \
"" ""
testing "find // -maxdepth 0 -name /" \
"find // -maxdepth 0 -name /" \
"//\n" \
"" ""
testing "find / -maxdepth 0 -name //" \
"find / -maxdepth 0 -name //" \
"" \
"" ""
testing "find // -maxdepth 0 -name //" \
"find // -maxdepth 0 -name //" \
"" \
"" ""
SKIP=
testing "find ./// -name ." \
"find ./// -name ." \
".///\n" \
"" ""
testing "find ./// -name .///" \
"find ./// -name .///" \
"" \
"" ""
# testing "description" "command" "result" "infile" "stdin"
rm -rf find.tempdir
exit $FAILCOUNT