mirror of
https://github.com/openharmony/third_party_toybox.git
synced 2026-06-30 21:37:54 -04:00
@@ -13,19 +13,14 @@ config TOYBOX
|
||||
bool
|
||||
default y
|
||||
help
|
||||
usage: toybox [--long | --help | --version | [command] [arguments...]]
|
||||
usage: toybox [--long | --help | --version | [COMMAND] [ARGUMENTS...]]
|
||||
|
||||
With no arguments, shows available commands. First argument is
|
||||
name of a command to run, followed by any arguments to that command.
|
||||
With no arguments, "toybox" shows available COMMAND names. Add --long
|
||||
to include suggested install path for each command, see
|
||||
https://landley.net/toybox/faq.html#install for details.
|
||||
|
||||
--long Show path to each command
|
||||
|
||||
To install command symlinks with paths, try:
|
||||
for i in $(/bin/toybox --long); do ln -s /bin/toybox $i; done
|
||||
or all in one directory:
|
||||
for i in $(./toybox); do ln -s toybox $i; done; PATH=$PWD:$PATH
|
||||
|
||||
Most toybox commands also understand the following arguments:
|
||||
First argument is name of a COMMAND to run, followed by any ARGUMENTS
|
||||
to that command. Most toybox commands also understand:
|
||||
|
||||
--help Show command help (only)
|
||||
--version Show toybox version (only)
|
||||
@@ -111,11 +106,13 @@ config TOYBOX_HELP_DASHDASH
|
||||
optstring. (Use TOYFLAG_NOHELP to disable.) Produces the same output
|
||||
as "help command". --version shows toybox version.
|
||||
|
||||
config TOYBOX_I18N
|
||||
bool "Internationalization support"
|
||||
config TOYBOX_ZHELP
|
||||
bool "compress help text"
|
||||
default y
|
||||
depends on TOYBOX_HELP
|
||||
help
|
||||
Support for UTF-8 character sets, and some locale support.
|
||||
Compress help with gzip -9, deflating when displayed. This makes the
|
||||
binary smaller but can increase runtime memory usage.
|
||||
|
||||
config TOYBOX_FREE
|
||||
bool "Free memory unnecessarily"
|
||||
@@ -147,12 +144,6 @@ config TOYBOX_DEBUG
|
||||
Enable extra checks for debugging purposes. All of them catch
|
||||
things that can only go wrong at development time, not runtime.
|
||||
|
||||
config TOYBOX_PEDANTIC_ARGS
|
||||
bool "Pedantic argument checking"
|
||||
default n
|
||||
help
|
||||
Check arguments for commands that have no arguments.
|
||||
|
||||
config TOYBOX_UID_SYS
|
||||
int "First system UID"
|
||||
default 100
|
||||
@@ -165,22 +156,34 @@ config TOYBOX_UID_USR
|
||||
help
|
||||
When commands like useradd/groupadd allocate user IDs, start here.
|
||||
|
||||
config TOYBOX_MUSL_NOMMU_IS_BROKEN
|
||||
bool "Workaround for musl-libc breakage on nommu systems."
|
||||
config TOYBOX_FORCE_NOMMU
|
||||
bool "Enable nommu support when the build can't detect it."
|
||||
default n
|
||||
help
|
||||
When using musl-libc on a nommu system, you'll need to say "y" here.
|
||||
When using musl-libc on a nommu system, you'll need to say "y" here
|
||||
unless you used the patch in the mcm-buildall.sh script. You can also
|
||||
say "y" here to test the nommu codepaths on an mmu system.
|
||||
|
||||
Although uclibc lets you detect support for things like fork() and
|
||||
daemon() at compile time, musl intentionally includes broken versions
|
||||
that always return -ENOSYS on nommu systems, and goes out of its way
|
||||
to prevent any cross-compile compatible compile-time probes for a
|
||||
nommu system. (It doesn't even #define __MUSL__ in features.h.)
|
||||
A nommu system can't use fork(), it can only vfork() which suspends
|
||||
the parent until the child calls exec() or exits. When a program
|
||||
needs a second instance of itself to run specific code at the same
|
||||
time as the parent, it must use a more complicated approach (such as
|
||||
exec("/proc/self/exe") then pass data to the new child through a pipe)
|
||||
which is larger and slower, especially for things like toysh subshells
|
||||
that need to duplicate a lot of internal state in the child process
|
||||
fork() gives you for free.
|
||||
|
||||
Musl does this despite the fact that a nommu system can't even run
|
||||
standard ELF binaries, and requires specially packaged executables.
|
||||
So our only choice is to manually provide a musl nommu bug workaround
|
||||
you can manually select to enable (larger, slower) nommu support with
|
||||
musl.
|
||||
Libraries like uclibc omit fork() on nommu systems, allowing
|
||||
compile-time probes to select which codepath to use. But musl
|
||||
intentionally includes a broken version of fork() that always returns
|
||||
-ENOSYS on nommu systems, and goes out of its way to prevent any
|
||||
cross-compile compatible compile-time probes for a nommu system.
|
||||
(It doesn't even #define __MUSL__ in features.h.) Musl does this
|
||||
despite the fact that a nommu system can't even run standard ELF
|
||||
binaries (requiring specially packaged executables) because it wants
|
||||
to force every program to either include all nommu code in every
|
||||
instance ever built, or drop nommu support altogether.
|
||||
|
||||
Building a scripts/mcm-buildall.sh toolchain patches musl to fix this.
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -3,31 +3,30 @@
|
||||
|
||||
# If people set these on the make command line, use 'em
|
||||
# Note that CC defaults to "cc" so the one in configure doesn't get
|
||||
# used when scripts/make.sh and care called through "make".
|
||||
# used when scripts/make.sh and such called through "make".
|
||||
|
||||
HOSTCC?=cc
|
||||
|
||||
export CROSS_COMPILE CFLAGS OPTIMIZE LDOPTIMIZE CC HOSTCC V STRIP
|
||||
export CROSS_COMPILE CFLAGS OPTIMIZE LDOPTIMIZE CC HOSTCC V STRIP ASAN
|
||||
|
||||
all: toybox
|
||||
|
||||
KCONFIG_CONFIG ?= .config
|
||||
|
||||
toybox_stuff: $(KCONFIG_CONFIG) *.[ch] lib/*.[ch] toys/*/*.c scripts/*.sh
|
||||
|
||||
toybox generated/unstripped/toybox: toybox_stuff
|
||||
toybox generated/unstripped/toybox: $(KCONFIG_CONFIG) *.[ch] lib/*.[ch] toys/*/*.c scripts/*.sh Config.in
|
||||
scripts/make.sh
|
||||
|
||||
.PHONY: clean distclean baseline bloatcheck install install_flat \
|
||||
uinstall uninstall_flat tests help toybox_stuff change \
|
||||
list list_working list_pending root run_root
|
||||
uninstall uninstall_flat tests help change \
|
||||
list list_example list_pending root run_root
|
||||
.SUFFIXES: # Disable legacy behavior
|
||||
|
||||
include kconfig/Makefile
|
||||
-include .singlemake
|
||||
|
||||
$(KCONFIG_CONFIG): $(KCONFIG_TOP)
|
||||
@if [ -e "$(KCONFIG_CONFIG)" ]; then make silentoldconfig; \
|
||||
else echo "Not configured (run 'make defconfig' or 'make menuconfig')";\
|
||||
@if [ -e "$(KCONFIG_CONFIG)" ]; then $(MAKE) silentoldconfig; \
|
||||
else echo "Not configured (run '$(MAKE) defconfig' or '$(MAKE) menuconfig')";\
|
||||
exit 1; fi
|
||||
|
||||
$(KCONFIG_TOP): generated/Config.in generated/Config.probed
|
||||
@@ -40,15 +39,15 @@ baseline: generated/unstripped/toybox
|
||||
@cp generated/unstripped/toybox generated/unstripped/toybox_old
|
||||
|
||||
bloatcheck: generated/unstripped/toybox_old generated/unstripped/toybox
|
||||
@scripts/bloatcheck generated/unstripped/toybox_old generated/unstripped/toybox
|
||||
@scripts/probes/bloatcheck generated/unstripped/toybox_old generated/unstripped/toybox
|
||||
|
||||
install_flat:
|
||||
install_flat: toybox
|
||||
scripts/install.sh --symlink --force
|
||||
|
||||
install_airlock:
|
||||
install_airlock: toybox
|
||||
scripts/install.sh --symlink --force --airlock
|
||||
|
||||
install:
|
||||
install: toybox
|
||||
scripts/install.sh --long --symlink --force
|
||||
|
||||
uninstall_flat:
|
||||
@@ -65,7 +64,8 @@ root_clean:
|
||||
@echo root cleaned
|
||||
|
||||
clean::
|
||||
@rm -rf toybox generated change .singleconfig* cross-log-*.*
|
||||
@chmod -fR 700 generated 2>/dev/null || true
|
||||
@rm -rf toybox generated change install .singleconfig*
|
||||
@echo cleaned
|
||||
|
||||
# If singlemake was in generated/ "make clean; make test_ls" wouldn't work.
|
||||
@@ -73,15 +73,15 @@ distclean: clean root_clean
|
||||
@rm -f toybox* .config* .singlemake
|
||||
@echo removed .config
|
||||
|
||||
tests:
|
||||
tests: ASAN=1
|
||||
tests: toybox
|
||||
scripts/test.sh
|
||||
|
||||
root:
|
||||
scripts/mkroot.sh $(MAKEFLAGS)
|
||||
mkroot/mkroot.sh $(MAKEFLAGS)
|
||||
|
||||
run_root:
|
||||
C=$$(basename "$$CROSS_COMPILE" | sed 's/-.*//'); \
|
||||
cd root/"$${C:-host}" && ./qemu-*.sh $(MAKEFLAGS) || exit 1
|
||||
cd root/"$${CROSS:-host}" && ./run-qemu.sh
|
||||
|
||||
help::
|
||||
@cat scripts/help.txt
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This sets environment variables used by scripts/make.sh
|
||||
# set environment variables used by scripts/make.sh
|
||||
|
||||
# People run ./configure out of habit, so do "defconfig" for them.
|
||||
|
||||
@@ -11,33 +11,13 @@ then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
# A synonym.
|
||||
[ -z "$CROSS_COMPILE" ] && CROSS_COMPILE="$CROSS"
|
||||
# Warn about stuff, disable stupid warnings, be 8-bit clean for utf8.
|
||||
[ "${CFLAGS/-funsigned-char//}" == "$CFLAGS" ] &&
|
||||
CFLAGS+=" -Wall -Wundef -Werror=implicit-function-declaration -Wno-char-subscripts -Wno-pointer-sign -funsigned-char"
|
||||
|
||||
# CFLAGS and OPTIMIZE are different so you can add extra CFLAGS without
|
||||
# disabling default optimizations
|
||||
[ -z "$CFLAGS" ] && CFLAGS="-Wall -Wundef -Wno-char-subscripts -Werror=implicit-function-declaration"
|
||||
# Required for our expected ABI. we're 8-bit clean thus "char" must be unsigned.
|
||||
CFLAGS="$CFLAGS -funsigned-char"
|
||||
[ -z "$OPTIMIZE" ] && OPTIMIZE="-Os -ffunction-sections -fdata-sections -fno-asynchronous-unwind-tables -fno-strict-aliasing"
|
||||
# set ASAN=1 to enable "address sanitizer" and debuggable backtraces
|
||||
[ -z "$ASAN" ] || { CFLAGS="$CFLAGS -O1 -g -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize=address"; NOSTRIP=1; }
|
||||
# Set default values if variable not already set
|
||||
: ${CC:=cc} ${HOSTCC:=cc} ${GENDIR:=generated} ${KCONFIG_CONFIG:=.config}
|
||||
: ${UNSTRIPPED:=$GENDIR/unstripped} ${OUTNAME:=toybox${TARGET:+-$TARGET}}
|
||||
: ${OPTIMIZE:=-Os -ffunction-sections -fdata-sections -fno-asynchronous-unwind-tables -fno-strict-aliasing}
|
||||
|
||||
# We accept LDFLAGS, but by default don't have anything in it
|
||||
if [ "$(uname)" != "Darwin" ]
|
||||
then
|
||||
[ -z "$LDOPTIMIZE" ] && LDOPTIMIZE="-Wl,--gc-sections"
|
||||
LDASNEEDED="-Wl,--as-needed"
|
||||
fi
|
||||
|
||||
# The makefile provides defaults for these, so this only gets used if
|
||||
# you call scripts/make.sh and friends directly.
|
||||
|
||||
[ -z "$CC" ] && CC=cc
|
||||
[ -z "$STRIP" ] && STRIP=strip
|
||||
|
||||
# If HOSTCC needs CFLAGS or LDFLAGS, just add them to the variable
|
||||
# ala HOSTCC="blah-cc --static"
|
||||
[ -z "$HOSTCC" ] && HOSTCC=cc
|
||||
|
||||
[ -z "$GENERATED" ] && GENERATED=generated
|
||||
|
||||
+6
-2
@@ -18,7 +18,7 @@ oldconfig: $(obj)/conf $(KCONFIG_TOP)
|
||||
$< -o $(KCONFIG_TOP)
|
||||
|
||||
silentoldconfig: $(obj)/conf $(KCONFIG_TOP)
|
||||
yes | $< -o $(KCONFIG_TOP) > /dev/null
|
||||
yes '' | $< -o $(KCONFIG_TOP) > /dev/null
|
||||
|
||||
randconfig: $(obj)/conf $(KCONFIG_TOP)
|
||||
$< -r $(KCONFIG_TOP) > /dev/null
|
||||
@@ -29,8 +29,9 @@ allyesconfig: $(obj)/conf $(KCONFIG_TOP)
|
||||
allnoconfig: $(obj)/conf $(KCONFIG_TOP)
|
||||
$< -n $(KCONFIG_TOP) > /dev/null
|
||||
|
||||
KCONFIG_ALLCONFIG ?= /dev/null
|
||||
defconfig: $(obj)/conf $(KCONFIG_TOP)
|
||||
$< -D /dev/null $(KCONFIG_TOP) > /dev/null
|
||||
$< -D $(KCONFIG_ALLCONFIG) $(KCONFIG_TOP) > /dev/null
|
||||
|
||||
macos_defconfig: $(obj)/conf $(KCONFIG_TOP)
|
||||
KCONFIG_ALLCONFIG=$(obj)/macos_miniconfig $< -n $(KCONFIG_TOP) > /dev/null
|
||||
@@ -38,6 +39,8 @@ macos_defconfig: $(obj)/conf $(KCONFIG_TOP)
|
||||
bsd_defconfig: $(obj)/conf $(KCONFIG_TOP)
|
||||
KCONFIG_ALLCONFIG=$(obj)/freebsd_miniconfig $< -n $(KCONFIG_TOP) > /dev/null
|
||||
|
||||
android_defconfig: $(obj)/conf $(KCONFIG_TOP)
|
||||
KCONFIG_ALLCONFIG=$(obj)/android_miniconfig $< -n $(KCONFIG_TOP) > /dev/null
|
||||
# Help text used by make help
|
||||
help::
|
||||
@echo ' config - Update current config utilising a line-oriented program'
|
||||
@@ -54,6 +57,7 @@ help::
|
||||
@echo ' (NOP binary, starting point for further configuration)'
|
||||
@echo ' macos_defconfig - Select commands known to build on macosx'
|
||||
@echo ' bsd_defconfig - Select commands known to build on freebsd'
|
||||
@echo ' android_defconfig - Select commands available on android'
|
||||
|
||||
# Cheesy build
|
||||
|
||||
|
||||
@@ -11,13 +11,17 @@ CONFIG_COMM=y
|
||||
CONFIG_CPIO=y
|
||||
CONFIG_CUT=y
|
||||
CONFIG_DATE=y
|
||||
CONFIG_DD=y
|
||||
CONFIG_DF=y
|
||||
CONFIG_DIRNAME=y
|
||||
CONFIG_DU=y
|
||||
CONFIG_ECHO=y
|
||||
CONFIG_ENV=y
|
||||
CONFIG_EXPAND=y
|
||||
CONFIG_FALSE=y
|
||||
CONFIG_FILE=y
|
||||
CONFIG_FIND=y
|
||||
CONFIG_FOLD=y
|
||||
CONFIG_GREP=y
|
||||
CONFIG_HEAD=y
|
||||
CONFIG_ICONV=y
|
||||
@@ -49,11 +53,13 @@ CONFIG_SLEEP=y
|
||||
CONFIG_SORT=y
|
||||
CONFIG_SPLIT=y
|
||||
CONFIG_STRINGS=y
|
||||
CONFIG_TAIL=y
|
||||
CONFIG_TEE=y
|
||||
CONFIG_TEST=y
|
||||
CONFIG_TIME=y
|
||||
CONFIG_TOUCH=y
|
||||
CONFIG_TRUE=y
|
||||
CONFIG_TSORT=y
|
||||
CONFIG_TTY=y
|
||||
CONFIG_UNAME=y
|
||||
CONFIG_UNIQ=y
|
||||
@@ -65,14 +71,16 @@ CONFIG_WHO=y
|
||||
CONFIG_XARGS=y
|
||||
CONFIG_ACPI=y
|
||||
CONFIG_ASCII=y
|
||||
CONFIG_UNICODE=y
|
||||
CONFIG_BASE64=y
|
||||
CONFIG_BASE32=y
|
||||
CONFIG_BUNZIP2=y
|
||||
CONFIG_BZCAT=y
|
||||
CONFIG_CHROOT=y
|
||||
CONFIG_CHRT=y
|
||||
CONFIG_CHVT=y
|
||||
CONFIG_CLEAR=y
|
||||
CONFIG_COUNT=y
|
||||
CONFIG_DEVMEM=y
|
||||
CONFIG_DOS2UNIX=y
|
||||
CONFIG_UNIX2DOS=y
|
||||
CONFIG_FACTOR=y
|
||||
@@ -81,47 +89,69 @@ CONFIG_FLOCK=y
|
||||
CONFIG_FMT=y
|
||||
CONFIG_FSYNC=y
|
||||
CONFIG_HELP=y
|
||||
CONFIG_HELP_EXTRAS=y
|
||||
CONFIG_HEXEDIT=y
|
||||
CONFIG_LSMOD=y
|
||||
CONFIG_LSPCI=y
|
||||
CONFIG_LSPCI_TEXT=y
|
||||
CONFIG_LSUSB=y
|
||||
CONFIG_MAKEDEVS=y
|
||||
CONFIG_MCOOKIE=y
|
||||
CONFIG_MKPASSWD=y
|
||||
CONFIG_MKSWAP=y
|
||||
CONFIG_MODINFO=y
|
||||
CONFIG_MOUNTPOINT=y
|
||||
CONFIG_NBD_SERVER=y
|
||||
CONFIG_PMAP=y
|
||||
CONFIG_PRINTENV=y
|
||||
CONFIG_PWDX=y
|
||||
CONFIG_PWGEN=y
|
||||
CONFIG_READELF=y
|
||||
CONFIG_READLINK=y
|
||||
CONFIG_REALPATH=y
|
||||
CONFIG_RESET=y
|
||||
CONFIG_REV=y
|
||||
CONFIG_SETSID=y
|
||||
CONFIG_SHA3SUM=y
|
||||
CONFIG_SHRED=y
|
||||
CONFIG_SHUF=y
|
||||
CONFIG_STAT=y
|
||||
CONFIG_SYSCTL=y
|
||||
CONFIG_TAC=y
|
||||
CONFIG_TIMEOUT=y
|
||||
CONFIG_TRUNCATE=y
|
||||
CONFIG_TS=y
|
||||
CONFIG_USLEEP=y
|
||||
CONFIG_UUIDGEN=y
|
||||
CONFIG_VMSTAT=y
|
||||
CONFIG_WATCH=y
|
||||
CONFIG_W=y
|
||||
CONFIG_WATCH=y
|
||||
CONFIG_WHICH=y
|
||||
CONFIG_XXD=y
|
||||
CONFIG_YES=y
|
||||
CONFIG_FTPGET=y
|
||||
CONFIG_FTPPUT=y
|
||||
CONFIG_HOST=y
|
||||
CONFIG_HTTPD=y
|
||||
CONFIG_MICROCOM=y
|
||||
CONFIG_NETCAT=y
|
||||
CONFIG_WGET=y
|
||||
CONFIG_GUNZIP=y
|
||||
CONFIG_ZCAT=y
|
||||
CONFIG_HOSTNAME=y
|
||||
CONFIG_DNSDOMAINNAME=y
|
||||
CONFIG_KILLALL=y
|
||||
CONFIG_MD5SUM=y
|
||||
CONFIG_SHA1SUM=y
|
||||
CONFIG_SHA224SUM=y
|
||||
CONFIG_SHA256SUM=y
|
||||
CONFIG_SHA384SUM=y
|
||||
CONFIG_SHA512SUM=y
|
||||
CONFIG_MKNOD=y
|
||||
CONFIG_MKTEMP=y
|
||||
CONFIG_PIDOF=y
|
||||
CONFIG_SEQ=y
|
||||
CONFIG_SU=y
|
||||
CONFIG_SYNC=y
|
||||
CONFIG_TOYBOX_SUID=y
|
||||
CONFIG_TOYBOX_FLOAT=y
|
||||
CONFIG_TOYBOX_HELP=y
|
||||
CONFIG_TOYBOX_HELP_DASHDASH=y
|
||||
CONFIG_TOYBOX_I18N=y
|
||||
|
||||
@@ -152,4 +152,8 @@ static inline bool sym_has_value(struct symbol *sym)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 4096
|
||||
#endif
|
||||
|
||||
#endif /* LKC_H */
|
||||
|
||||
+74
-55
@@ -1,111 +1,130 @@
|
||||
CONFIG_ASCII=y
|
||||
CONFIG_BASE32=y
|
||||
CONFIG_BASE64=y
|
||||
CONFIG_BASENAME=y
|
||||
CONFIG_BZCAT=y
|
||||
CONFIG_CAL=y
|
||||
CONFIG_CAT=y
|
||||
CONFIG_CHGRP=y
|
||||
CONFIG_CHOWN=y
|
||||
CONFIG_CHMOD=y
|
||||
CONFIG_CHOWN=y
|
||||
CONFIG_CKSUM=y
|
||||
CONFIG_CRC32=y
|
||||
CONFIG_CLEAR=y
|
||||
CONFIG_CMP=y
|
||||
CONFIG_COMM=y
|
||||
CONFIG_COUNT=y
|
||||
CONFIG_CP=y
|
||||
CONFIG_CPIO=y
|
||||
CONFIG_CRC32=y
|
||||
CONFIG_CUT=y
|
||||
CONFIG_DATE=y
|
||||
CONFIG_DF=y
|
||||
CONFIG_DIRNAME=y
|
||||
CONFIG_DOS2UNIX=y
|
||||
CONFIG_DU=y
|
||||
CONFIG_ECHO=y
|
||||
CONFIG_ENV=y
|
||||
CONFIG_EXPAND=y
|
||||
CONFIG_FACTOR=y
|
||||
CONFIG_FALLOCATE=y
|
||||
CONFIG_FALSE=y
|
||||
CONFIG_FILE=y
|
||||
CONFIG_FIND=y
|
||||
CONFIG_FLOCK=y
|
||||
CONFIG_FMT=y
|
||||
CONFIG_FOLD=y
|
||||
CONFIG_FTPGET=y
|
||||
CONFIG_FTPPUT=y
|
||||
CONFIG_GETCONF=y
|
||||
CONFIG_GREP=y
|
||||
CONFIG_GROUPS=y
|
||||
CONFIG_HEAD=y
|
||||
CONFIG_HELP=y
|
||||
CONFIG_HEXEDIT=y
|
||||
CONFIG_HOSTNAME=y
|
||||
CONFIG_HTTPD=y
|
||||
CONFIG_ICONV=y
|
||||
CONFIG_ID=y
|
||||
CONFIG_GROUPS=y
|
||||
CONFIG_LOGNAME=y
|
||||
CONFIG_WHOAMI=y
|
||||
CONFIG_INSTALL=y
|
||||
CONFIG_KILL=y
|
||||
CONFIG_KILLALL5=y
|
||||
CONFIG_LINK=y
|
||||
CONFIG_LN=y
|
||||
CONFIG_LOGGER=y
|
||||
CONFIG_LOGNAME=y
|
||||
CONFIG_LS=y
|
||||
CONFIG_MCOOKIE=y
|
||||
CONFIG_MD5SUM=y
|
||||
CONFIG_MICROCOM=y
|
||||
CONFIG_MKDIR=y
|
||||
CONFIG_MKFIFO=y
|
||||
CONFIG_MKTEMP=y
|
||||
CONFIG_MV=y
|
||||
CONFIG_NETCAT=y
|
||||
CONFIG_NICE=y
|
||||
CONFIG_NL=y
|
||||
CONFIG_NOHUP=y
|
||||
CONFIG_OD=y
|
||||
CONFIG_PASTE=y
|
||||
CONFIG_PATCH=y
|
||||
CONFIG_PRINTENV=y
|
||||
CONFIG_PRINTF=y
|
||||
CONFIG_PWD=y
|
||||
CONFIG_PWDX=y
|
||||
CONFIG_PWGEN=y
|
||||
CONFIG_READELF=y
|
||||
CONFIG_READLINK=y
|
||||
CONFIG_REALPATH=y
|
||||
CONFIG_RENICE=y
|
||||
CONFIG_REV=y
|
||||
CONFIG_RM=y
|
||||
CONFIG_RMDIR=y
|
||||
CONFIG_SED=y
|
||||
CONFIG_SEQ=y
|
||||
CONFIG_SETSID=y
|
||||
CONFIG_SHA1SUM=y
|
||||
CONFIG_SHA224SUM=y
|
||||
CONFIG_SHA256SUM=y
|
||||
CONFIG_SHA384SUM=y
|
||||
CONFIG_SHA3SUM=y
|
||||
CONFIG_SHA512SUM=y
|
||||
CONFIG_SHRED=y
|
||||
CONFIG_SLEEP=y
|
||||
CONFIG_SORT=y
|
||||
CONFIG_SPLIT=y
|
||||
CONFIG_STAT=y
|
||||
CONFIG_STRINGS=y
|
||||
CONFIG_TAC=y
|
||||
CONFIG_TAIL=y
|
||||
CONFIG_TAR=y
|
||||
CONFIG_TEE=y
|
||||
CONFIG_TEST=y
|
||||
CONFIG_TIME=y
|
||||
CONFIG_TOUCH=y
|
||||
CONFIG_TRUE=y
|
||||
CONFIG_TTY=y
|
||||
CONFIG_UNAME=y
|
||||
CONFIG_UNIQ=y
|
||||
CONFIG_UNLINK=y
|
||||
CONFIG_UUDECODE=y
|
||||
CONFIG_UUENCODE=y
|
||||
CONFIG_WC=y
|
||||
CONFIG_WHO=y
|
||||
CONFIG_XARGS=y
|
||||
CONFIG_ASCII=y
|
||||
CONFIG_BASE64=y
|
||||
CONFIG_CLEAR=y
|
||||
CONFIG_COUNT=y
|
||||
CONFIG_DOS2UNIX=y
|
||||
CONFIG_UNIX2DOS=y
|
||||
CONFIG_FACTOR=y
|
||||
CONFIG_FLOCK=y
|
||||
CONFIG_FMT=y
|
||||
CONFIG_HELP=y
|
||||
CONFIG_HELP_EXTRAS=y
|
||||
CONFIG_HEXEDIT=y
|
||||
CONFIG_PRINTENV=y
|
||||
CONFIG_PWDX=y
|
||||
CONFIG_READLINK=y
|
||||
CONFIG_REALPATH=y
|
||||
CONFIG_REV=y
|
||||
CONFIG_SETSID=y
|
||||
CONFIG_TAC=y
|
||||
CONFIG_TIMEOUT=y
|
||||
CONFIG_TRUNCATE=y
|
||||
CONFIG_USLEEP=y
|
||||
CONFIG_UUIDGEN=y
|
||||
CONFIG_WATCH=y
|
||||
CONFIG_W=y
|
||||
CONFIG_WHICH=y
|
||||
CONFIG_XXD=y
|
||||
CONFIG_YES=y
|
||||
CONFIG_FTPGET=y
|
||||
CONFIG_FTPPUT=y
|
||||
CONFIG_MICROCOM=y
|
||||
CONFIG_NETCAT=y
|
||||
CONFIG_NETCAT_LISTEN=y
|
||||
CONFIG_HOSTNAME=y
|
||||
CONFIG_MD5SUM=y
|
||||
CONFIG_SHA1SUM=y
|
||||
CONFIG_SEQ=y
|
||||
CONFIG_TAIL=y
|
||||
CONFIG_TOYBOX_SUID=y
|
||||
CONFIG_TOUCH=y
|
||||
CONFIG_TOYBOX_FLOAT=y
|
||||
CONFIG_TOYBOX_HELP=y
|
||||
CONFIG_TOYBOX_HELP_DASHDASH=y
|
||||
CONFIG_TOYBOX_I18N=y
|
||||
CONFIG_TOYBOX_SUID=y
|
||||
CONFIG_TRUE=y
|
||||
CONFIG_TRUNCATE=y
|
||||
CONFIG_TTY=y
|
||||
CONFIG_UNAME=y
|
||||
CONFIG_UNICODE=y
|
||||
CONFIG_UNIQ=y
|
||||
CONFIG_UNIX2DOS=y
|
||||
CONFIG_UNLINK=y
|
||||
CONFIG_USLEEP=y
|
||||
CONFIG_UUDECODE=y
|
||||
CONFIG_UUENCODE=y
|
||||
CONFIG_UUIDGEN=y
|
||||
CONFIG_W=y
|
||||
CONFIG_WATCH=y
|
||||
CONFIG_WC=y
|
||||
CONFIG_WHICH=y
|
||||
CONFIG_WHO=y
|
||||
CONFIG_WHOAMI=y
|
||||
CONFIG_XARGS=y
|
||||
CONFIG_XXD=y
|
||||
CONFIG_YES=y
|
||||
CONFIG_ZCAT=y
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
mainmenu "Toybox Configuration"
|
||||
|
||||
|
||||
source generated/Config.probed
|
||||
source generated/Config.in
|
||||
|
||||
comment ""
|
||||
|
||||
menu "Toybox global settings"
|
||||
|
||||
# This entry controls the multiplexer, disabled for single command builds
|
||||
config TOYBOX
|
||||
bool
|
||||
default y
|
||||
help
|
||||
usage: toybox [--long | --help | --version | [command] [arguments...]]
|
||||
|
||||
With no arguments, shows available commands. First argument is
|
||||
name of a command to run, followed by any arguments to that command.
|
||||
|
||||
--long Show path to each command
|
||||
|
||||
To install command symlinks with paths, try:
|
||||
for i in $(/bin/toybox --long); do ln -s /bin/toybox $i; done
|
||||
or all in one directory:
|
||||
for i in $(./toybox); do ln -s toybox $i; done; PATH=$PWD:$PATH
|
||||
|
||||
Most toybox commands also understand the following arguments:
|
||||
|
||||
--help Show command help (only)
|
||||
--version Show toybox version (only)
|
||||
|
||||
The filename "-" means stdin/stdout, and "--" stops argument parsing.
|
||||
|
||||
Numerical arguments accept a single letter suffix for
|
||||
kilo, mega, giga, tera, peta, and exabytes, plus an additional
|
||||
"d" to indicate decimal 1000's instead of 1024.
|
||||
|
||||
Durations can be decimal fractions and accept minute ("m"), hour ("h"),
|
||||
or day ("d") suffixes (so 0.1m = 6s).
|
||||
|
||||
config TOYBOX_SUID
|
||||
bool "SUID support"
|
||||
default y
|
||||
help
|
||||
Support for the Set User ID bit, to install toybox suid root and drop
|
||||
permissions for commands which do not require root access. To use
|
||||
this change ownership of the file to the root user and set the suid
|
||||
bit in the file permissions:
|
||||
|
||||
chown root:root toybox; chmod +s toybox
|
||||
|
||||
choice
|
||||
prompt "Security Blanket"
|
||||
default TOYBOX_LSM_NONE
|
||||
help
|
||||
Select a Linux Security Module to complicate your system
|
||||
until you can't find holes in it.
|
||||
|
||||
config TOYBOX_LSM_NONE
|
||||
bool "None"
|
||||
help
|
||||
Don't try to achieve "watertight" by plugging the holes in a
|
||||
collander, instead use conventional unix security (and possibly
|
||||
Linux Containers) for a simple straightforward system.
|
||||
|
||||
config TOYBOX_SELINUX
|
||||
bool "SELinux support"
|
||||
help
|
||||
Include SELinux options in commands such as ls, and add
|
||||
SELinux-specific commands such as chcon to the Android menu.
|
||||
|
||||
config TOYBOX_SMACK
|
||||
bool "SMACK support"
|
||||
help
|
||||
Include SMACK options in commands like ls for systems like Tizen.
|
||||
|
||||
endchoice
|
||||
|
||||
config TOYBOX_LIBCRYPTO
|
||||
bool "Use libcrypto (OpenSSL/BoringSSL)"
|
||||
default n
|
||||
help
|
||||
Use faster hash functions out of external -lcrypto library.
|
||||
|
||||
config TOYBOX_LIBZ
|
||||
bool "Use libz (zlib)"
|
||||
default n
|
||||
help
|
||||
Use libz for gz support.
|
||||
|
||||
config TOYBOX_FLOAT
|
||||
bool "Floating point support"
|
||||
default y
|
||||
help
|
||||
Include floating point support infrastructure and commands that
|
||||
require it.
|
||||
|
||||
config TOYBOX_HELP
|
||||
bool "Help messages"
|
||||
default y
|
||||
help
|
||||
Include help text for each command.
|
||||
|
||||
config TOYBOX_HELP_DASHDASH
|
||||
bool "--help and --version"
|
||||
default y
|
||||
depends on TOYBOX_HELP
|
||||
help
|
||||
Support --help argument in all commands, even ones with a NULL
|
||||
optstring. (Use TOYFLAG_NOHELP to disable.) Produces the same output
|
||||
as "help command". --version shows toybox version.
|
||||
|
||||
config TOYBOX_I18N
|
||||
bool "Internationalization support"
|
||||
default y
|
||||
help
|
||||
Support for UTF-8 character sets, and some locale support.
|
||||
|
||||
config TOYBOX_FREE
|
||||
bool "Free memory unnecessarily"
|
||||
default n
|
||||
help
|
||||
When a program exits, the operating system will clean up after it
|
||||
(free memory, close files, etc). To save size, toybox usually relies
|
||||
on this behavior. If you're running toybox under a debugger or
|
||||
without a real OS (ala newlib+libgloss), enable this to make toybox
|
||||
clean up after itself.
|
||||
|
||||
config TOYBOX_NORECURSE
|
||||
bool "Disable recursive execution"
|
||||
default n
|
||||
help
|
||||
When one toybox command calls another, usually it just calls the new
|
||||
command's main() function rather than searching the $PATH and calling
|
||||
exec on another file (which is much slower).
|
||||
|
||||
This disables that optimization, so toybox will run external commands
|
||||
even when it has a built-in version of that command. This requires
|
||||
toybox symlinks to be installed in the $PATH, or re-invoking the
|
||||
"toybox" multiplexer command by name.
|
||||
|
||||
config TOYBOX_DEBUG
|
||||
bool "Debugging tests"
|
||||
default n
|
||||
help
|
||||
Enable extra checks for debugging purposes. All of them catch
|
||||
things that can only go wrong at development time, not runtime.
|
||||
|
||||
config TOYBOX_PEDANTIC_ARGS
|
||||
bool "Pedantic argument checking"
|
||||
default n
|
||||
help
|
||||
Check arguments for commands that have no arguments.
|
||||
|
||||
config TOYBOX_UID_SYS
|
||||
int "First system UID"
|
||||
default 100
|
||||
help
|
||||
When commands like useradd/groupadd allocate system IDs, start here.
|
||||
|
||||
config TOYBOX_UID_USR
|
||||
int "First user UID"
|
||||
default 500
|
||||
help
|
||||
When commands like useradd/groupadd allocate user IDs, start here.
|
||||
|
||||
config TOYBOX_MUSL_NOMMU_IS_BROKEN
|
||||
bool "Workaround for musl-libc breakage on nommu systems."
|
||||
default n
|
||||
help
|
||||
When using musl-libc on a nommu system, you'll need to say "y" here.
|
||||
|
||||
Although uclibc lets you detect support for things like fork() and
|
||||
daemon() at compile time, musl intentionally includes broken versions
|
||||
that always return -ENOSYS on nommu systems, and goes out of its way
|
||||
to prevent any cross-compile compatible compile-time probes for a
|
||||
nommu system. (It doesn't even #define __MUSL__ in features.h.)
|
||||
|
||||
Musl does this despite the fact that a nommu system can't even run
|
||||
standard ELF binaries, and requires specially packaged executables.
|
||||
So our only choice is to manually provide a musl nommu bug workaround
|
||||
you can manually select to enable (larger, slower) nommu support with
|
||||
musl.
|
||||
|
||||
endmenu
|
||||
Vendored
+43
@@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This sets environment variables used by scripts/make.sh
|
||||
|
||||
# People run ./configure out of habit, so do "defconfig" for them.
|
||||
|
||||
if [ "$(basename "$0")" == configure ]
|
||||
then
|
||||
echo "Assuming you want 'make defconfig', but you should probably check the README."
|
||||
make defconfig
|
||||
exit $?
|
||||
fi
|
||||
|
||||
# A synonym.
|
||||
[ -z "$CROSS_COMPILE" ] && CROSS_COMPILE="$CROSS"
|
||||
|
||||
# CFLAGS and OPTIMIZE are different so you can add extra CFLAGS without
|
||||
# disabling default optimizations
|
||||
[ -z "$CFLAGS" ] && CFLAGS="-Wall -Wundef -Wno-char-subscripts -Werror=implicit-function-declaration"
|
||||
# Required for our expected ABI. we're 8-bit clean thus "char" must be unsigned.
|
||||
CFLAGS="$CFLAGS -funsigned-char"
|
||||
[ -z "$OPTIMIZE" ] && OPTIMIZE="-Os -ffunction-sections -fdata-sections -fno-asynchronous-unwind-tables -fno-strict-aliasing"
|
||||
# set ASAN=1 to enable "address sanitizer" and debuggable backtraces
|
||||
[ -z "$ASAN" ] || { CFLAGS="$CFLAGS -O1 -g -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize=address"; NOSTRIP=1; }
|
||||
|
||||
# We accept LDFLAGS, but by default don't have anything in it
|
||||
if [ "$(uname)" != "Darwin" ]
|
||||
then
|
||||
[ -z "$LDOPTIMIZE" ] && LDOPTIMIZE="-Wl,--gc-sections"
|
||||
LDASNEEDED="-Wl,--as-needed"
|
||||
fi
|
||||
|
||||
# The makefile provides defaults for these, so this only gets used if
|
||||
# you call scripts/make.sh and friends directly.
|
||||
|
||||
[ -z "$CC" ] && CC=cc
|
||||
[ -z "$STRIP" ] && STRIP=strip
|
||||
|
||||
# If HOSTCC needs CFLAGS or LDFLAGS, just add them to the variable
|
||||
# ala HOSTCC="blah-cc --static"
|
||||
[ -z "$HOSTCC" ] && HOSTCC=cc
|
||||
|
||||
[ -z "$GENERATED" ] && GENERATED=generated
|
||||
+496
@@ -0,0 +1,496 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Original found at http://lists.landley.net/pipermail/toybox-landley.net/2015-March/015201.html
|
||||
|
||||
# Copyright 2015 Divya Kothari <divya.s.kothari@gmail.com>
|
||||
|
||||
# 2023: A few mods by Ray Gardner <raygard@gmail.com>
|
||||
# See "awk -f test04.awk" near line 170
|
||||
# and "awk -e ..." tests near line 415
|
||||
# 2024: Mods to use testcmd instead of testing for most tests
|
||||
# Added new tests (after line 420)
|
||||
|
||||
[ -f testing.sh ] && . testing.sh
|
||||
|
||||
#testcmd "name" "command" "result" "infile" "stdin"
|
||||
#testing "name" "progname command" "result" "infile" "stdin"
|
||||
|
||||
FILE1="abc def ghi 5\nghi jkl mno 10\nmno pqr stu 15\nstu vwx abc 20\n"
|
||||
FILE2="abc,def,ghi,5\nghi,jkl,mno,10\nmno,pqr,stu,15\nstu,vwx,abc,20\n"
|
||||
FILE3="abc:def:ghi:5\nghi:jkl:mno:10\nmno:pqr:stu:15\nstu:vwx:abc:20\n"
|
||||
FILE4="abc def ghi -5\nghi jkl mno -10\nmno pqr stu -15\nstu vwx abc -20\n"
|
||||
|
||||
testcmd "awk PATTERN input" "'/abc/' input" \
|
||||
"abc def ghi 5\nstu vwx abc 20\n" "$FILE1" ""
|
||||
|
||||
testcmd "awk SUBPATTERN input" "'/ab/' input" \
|
||||
"abc def ghi 5\nstu vwx abc 20\n" "$FILE1" ""
|
||||
|
||||
testcmd "awk FIELD input" "'{print \$2,\$3}' input" \
|
||||
"def ghi\njkl mno\npqr stu\nvwx abc\n" "$FILE1" ""
|
||||
|
||||
testcmd "awk FIELD input (out range)" "'{print \$2,\$8}' input" \
|
||||
"def \njkl \npqr \nvwx \n" "$FILE1" ""
|
||||
|
||||
L1="def def def def def def def def def def"
|
||||
L2="jkl jkl jkl jkl jkl jkl jkl jkl jkl jkl"
|
||||
L3="pqr pqr pqr pqr pqr pqr pqr pqr pqr pqr"
|
||||
L4="vwx vwx vwx vwx vwx vwx vwx vwx vwx vwx"
|
||||
testing "awk FIELD input (single, multiple times)" \
|
||||
"awk '{ print \$2,\$2,\$2,\$2,\$2,\$2,\$2,\$2,\$2,\$2 }' input" \
|
||||
"$L1\n$L2\n$L3\n$L4\n" "$FILE1" ""
|
||||
|
||||
|
||||
HEAD="Head1\tHead2\tHead3"
|
||||
FOOT="Report Generated"
|
||||
testcmd "awk CODE input" "'BEGIN { print \"$HEAD\"; } {
|
||||
print \$1,\"\t\",\$3; } END { print \"$FOOT\"; }' input" \
|
||||
"$HEAD\nabc \t ghi\nghi \t mno\nmno \t stu\nstu \t abc\n$FOOT\n" "$FILE1" ""
|
||||
|
||||
testcmd "awk '>' input" "'\$4>0' input" \
|
||||
"abc def ghi 5\nghi jkl mno 10\nmno pqr stu 15\nstu vwx abc 20\n" "$FILE1" ""
|
||||
|
||||
testcmd "awk '<' input" "'\$4<25' input" \
|
||||
"abc def ghi 5\nghi jkl mno 10\nmno pqr stu 15\nstu vwx abc 20\n" "$FILE1" ""
|
||||
|
||||
testcmd "awk '==' input" "'\$4==15' input" "mno pqr stu 15\n" "$FILE1" ""
|
||||
|
||||
testcmd "awk CMP input" "'\$1~/abc/' input" "abc def ghi 5\n" "$FILE1" ""
|
||||
|
||||
testcmd "awk COUNT input" "'BEGIN { count=0; } \$1~/abc/ { count++; } END {
|
||||
print \"Total Count =\",count; }' input" "Total Count = 1\n" "$FILE1" ""
|
||||
|
||||
testcmd "awk COLUMN input" "'{ print \$1 }' input" "abc\nghi\nmno\nstu\n" \
|
||||
"$FILE1" ""
|
||||
|
||||
testcmd "awk SUM input" "'BEGIN { sum=0; } { sum=sum+\$4; } END {
|
||||
print \"Sum is =\",sum; }' input" "Sum is = 50\n" "$FILE1" ""
|
||||
|
||||
testcmd "awk IF input" "'{ if(\$2 == \"jkl\") print \$1; }' input" "ghi\n" \
|
||||
"$FILE1" ""
|
||||
|
||||
testing "awk FOR MUL input" \
|
||||
"awk 'BEGIN { for(i=1;i<=3;i++) print \"square of\", i, \"is\",i*i; }'" \
|
||||
"square of 1 is 1\nsquare of 2 is 4\nsquare of 3 is 9\n" "" ""
|
||||
|
||||
testing "awk FOR ADD input" \
|
||||
"awk 'BEGIN { for(i=1;i<=3;i++) print \"twice of\", i, \"is\",i+i; }'" \
|
||||
"twice of 1 is 2\ntwice of 2 is 4\ntwice of 3 is 6\n" "" ""
|
||||
|
||||
testing "awk FOR SUB input" \
|
||||
"awk 'BEGIN { for(i=1;i<=3;i++) print \"sub of\", i, \"is\",i-i; }'" \
|
||||
"sub of 1 is 0\nsub of 2 is 0\nsub of 3 is 0\n" "" ""
|
||||
|
||||
testcmd "awk {FS:invalid} input1" "'BEGIN { FS=\"69793793\" } { print \$2
|
||||
}' input" "\n\n\n\n" "$FILE3" ""
|
||||
|
||||
testcmd "awk -F invalid input1" "-F69793793 '{ print \$2 }' input" \
|
||||
"\n\n\n\n" "$FILE3" ""
|
||||
|
||||
testcmd "awk {FS} input2" "'BEGIN { FS=\",\" } { print \$2 }' input" \
|
||||
"def\njkl\npqr\nvwx\n" "$FILE2" ""
|
||||
|
||||
testcmd "awk -F input2" "-F\",\" '{ print \$2 }' input" \
|
||||
"def\njkl\npqr\nvwx\n" "$FILE2" ""
|
||||
|
||||
testcmd "awk {FS} input3" "'BEGIN { FS=\":\" } { print \$2 }' input" \
|
||||
"def\njkl\npqr\nvwx\n" "$FILE3" ""
|
||||
|
||||
testcmd "awk -F input3" "-F: '{ print \$2 }' input" "def\njkl\npqr\nvwx\n" \
|
||||
"$FILE3" ""
|
||||
|
||||
testcmd "awk {OFS} {1} input" "'BEGIN { OFS=\"__\" } { print \$2 }' input" \
|
||||
"def\njkl\npqr\nvwx\n" "$FILE1" ""
|
||||
|
||||
testcmd "awk {OFS} {1,2} input" "'BEGIN { OFS=\"__\" } { print \$2,\$3
|
||||
}' input" "def__ghi\njkl__mno\npqr__stu\nvwx__abc\n" "$FILE1" ""
|
||||
|
||||
testcmd "awk {NF} input" "'{print NF}' input" "4\n4\n4\n4\n" "$FILE1" ""
|
||||
|
||||
testcmd "awk {NR} input" "'{print NR}' input" "1\n2\n3\n4\n" "$FILE1" ""
|
||||
|
||||
testcmd "awk END{NR} input" "'END {print NR}' input" "4\n" "$FILE1" ""
|
||||
|
||||
testcmd "awk SPLIT input" "'{ split(\$0,arr,\" \"); if(arr[3] == \"abc\")
|
||||
print \$2 }' input" "vwx\n" "$FILE1" ""
|
||||
|
||||
testcmd "awk SUBSTR input" "'{if (substr(\$0,1,3) == \"abc\") { print \$3 }
|
||||
}' input" "ghi\n" "$FILE1" ""
|
||||
|
||||
testcmd "awk SEARCH {PRINT} input" "'/ghi/ {print \$1,\$2,\$3,\$4}' input" \
|
||||
"abc def ghi 5\nghi jkl mno 10\n" "$FILE1" ""
|
||||
|
||||
testcmd "awk SEARCH {PRINTF} input" "'/ghi/ { printf \$1 \$2 \$3 \$4
|
||||
}' input" "abcdefghi5ghijklmno10" "$FILE1" ""
|
||||
|
||||
testcmd "awk {PRINT with TAB} input" "'{print \$2,\"\t\",\$4}' input" \
|
||||
"def \t 5\njkl \t 10\npqr \t 15\nvwx \t 20\n" "$FILE1" ""
|
||||
|
||||
testcmd "awk {PRINT 2,4} input" "'{print \$2,\$4}' input" \
|
||||
"def 5\njkl 10\npqr 15\nvwx 20\n" "$FILE1" ""
|
||||
|
||||
testcmd "awk {PRINT 4,2} input" "'{print \$4,\$2}' input" \
|
||||
"5 def\n10 jkl\n15 pqr\n20 vwx\n" "$FILE1" ""
|
||||
|
||||
testcmd "awk {PRINT X,Y} input" "'{print \$6,\$9}' input" \
|
||||
" \n \n \n \n" "$FILE1" ""
|
||||
|
||||
testcmd "awk {PRINT} input" "'{ print }' input" "$FILE1" "$FILE1" ""
|
||||
|
||||
testcmd "awk INVALID_ARGS1 input" "'{ print x,y }' input" \
|
||||
" \n \n \n \n" "$FILE1" ""
|
||||
|
||||
testcmd "awk INVALID_ARGS2 input" "'{ print \$4,\$5 }' input" \
|
||||
"5 \n10 \n15 \n20 \n" "$FILE1" ""
|
||||
|
||||
testcmd "awk PATTERN input (not found)" "'/abcd/' input && echo 'yes'" \
|
||||
"yes\n" "$FILE1" ""
|
||||
|
||||
testcmd "awk {PATTERN:-ve} input" "'/-5/' input" "abc def ghi -5\n" \
|
||||
"$FILE4" ""
|
||||
|
||||
testcmd "awk FIELD input (high value)" "'{print \$99999}' input &&
|
||||
echo 'yes'" "\n\n\n\nyes\n" "$FILE1" ""
|
||||
|
||||
#### Starting "-f file" tests ####
|
||||
|
||||
echo "{ if (\$1 == \"#START\") { FS=\":\"; } else if (\$1 == \"#STOP\") {
|
||||
FS=\" \"; } else { print \$3 } }" > test.awk
|
||||
testcmd "awk -f test01.awk" "-f test.awk input" \
|
||||
"ghi\nmno\nstu\nabc\n" "$FILE1" ""
|
||||
|
||||
echo "BEGIN { i=1; while (i <= 5) { printf i \"-\" i*i \" \"; i=i+1; }
|
||||
for (i=1; i <= 5; i++) { printf i \"-\" i*i \" \"; } }" > test.awk
|
||||
testcmd "awk -f test02.awk" "-f test.awk" \
|
||||
"1-1 2-4 3-9 4-16 5-25 1-1 2-4 3-9 4-16 5-25 " "" ""
|
||||
|
||||
echo "BEGIN { print \"Start.\" } { print \$1,\"-\",\$1*\$1; }
|
||||
END { print \"End.\" }" > test.awk
|
||||
testcmd "awk -f test03.awk" "-f test.awk" \
|
||||
"Start.\n5 - 25\n10 - 100\n15 - 225\n20 - 400\nEnd.\n" "" "5\n10\n15\n20\n"
|
||||
|
||||
### echo "{ if ( \$0 ~ /:/ ) {FS=\":\";} else {FS=\" \";} print \$3 }" > test.awk
|
||||
### testing "awk -f test04.awk" "awk -f test.awk input" \
|
||||
### "ghi\nmno\nstu\nabc\nghi\nmno\nstu\nabc\n" "$FILE1$FILE3" ""
|
||||
|
||||
### TEST ERROR This test originally ended with:
|
||||
### "ghi\nmno\nstu\nabc\nghi\nmno\nstu\nabc\n" "$FILE1$FILE3" ""
|
||||
### This is wrong; gawk/mawk/bbawk/bwk awk agree that second ghi should not appear.
|
||||
### (My current version of goawk agrees with the "wrong" expected value;
|
||||
### I need to update to latest goawk and test again. rdg 2023-10-29)
|
||||
echo "{ if ( \$0 ~ /:/ ) {FS=\":\";} else {FS=\" \";} print \$3 }" > test.awk
|
||||
testcmd "awk -f test04.awk" "-f test.awk input" \
|
||||
"ghi\nmno\nstu\nabc\n\nmno\nstu\nabc\n" "$FILE1$FILE3" ""
|
||||
|
||||
echo "BEGIN { lines=0; total=0; } { lines++; total+=\$1; } END {
|
||||
print \"Read:\",lines; print \"Total:\",total; if (lines > 0 ) {
|
||||
print \"Average:\", total/lines; } else { print \"0\"; } }" > test.awk
|
||||
testcmd "awk -f test05.awk" "-f test.awk input" \
|
||||
"Read: 5\nTotal: 150\nAverage: 30\n" "10\n20\n30\n40\n50\n" ""
|
||||
|
||||
echo "BEGIN{FS=\":\";}{if(\$2==\"pqr\"){print \"first one:\", \$1;}}" > test.awk
|
||||
testcmd "awk -f test06.awk" "-f test.awk input" \
|
||||
"first one: mno\n" "$FILE3" ""
|
||||
|
||||
echo "{ print \$2; FS=\":\"; print \$2 }" > test.awk
|
||||
testcmd "awk -f test07.awk" "-f test.awk input" \
|
||||
"\n\njkl\njkl\npqr\npqr\nvwx\nvwx\n" "$FILE3" ""
|
||||
|
||||
echo "BEGIN { FS=\":\"; OFS=\":\"; } { \$2=\"\"; print }" > test.awk
|
||||
testcmd "awk -f test09.awk" "-f test.awk input" \
|
||||
"abc::ghi:5\nghi::mno:10\nmno::stu:15\nstu::abc:20\n" "$FILE3" ""
|
||||
|
||||
mkdir dir && touch dir/file && LLDATA="`ls -l dir`"
|
||||
rm -rf dir
|
||||
echo "{ if (NF==8) { print \$8; } else if (NF==9) { print \$9; } }" > test.awk
|
||||
testcmd "awk -f test10.awk" "-f test.awk input" "file\n" "$LLDATA" ""
|
||||
|
||||
echo "{ if (NR >= 1) { print NR;} }" > test.awk
|
||||
testcmd "awk -f test11.awk" "-f test.awk input" "1\n2\n" "$LLDATA" ""
|
||||
|
||||
echo "BEGIN { RS=\"\"; FS=\"\n\" } { print \$2,\$3; }" > test.awk
|
||||
testcmd "awk -f test12.awk" "-f test.awk input" \
|
||||
"ghi jkl mno 10 mno pqr stu 15\n" "$FILE1" ""
|
||||
|
||||
L="abc\ndef\nghi\n5\nghi\njkl\nmno\n10\nmno\npqr\nstu\n15\nstu\nvwx\nabc\n20\n"
|
||||
echo "BEGIN { RS=\" \"; } { print; }" > test.awk
|
||||
testcmd "awk -f test13.awk" "-f test.awk input" "$L\n" "$FILE1" ""
|
||||
|
||||
L="abc def ghi 5\r\nghi jkl mno 10\r\nmno pqr stu 15\r\nstu vwx abc 20\r\n"
|
||||
echo "BEGIN { ORS=\"\r\n\" } { print }" > test.awk
|
||||
testcmd "awk -f test14.awk" "-f test.awk input" "$L" "$FILE1" ""
|
||||
|
||||
echo "BEGIN { f=\"\"; }{ if(f != FILENAME){ f=FILENAME; print f }}" > test.awk
|
||||
testcmd "awk -f test15.awk" "-f test.awk input" "input\n" "$FILE1" ""
|
||||
|
||||
echo "{ if (NF == 6) { } else { if (FILENAME == \"-\" ) { print \"ERROR\",
|
||||
NR,\"line:\"; } else { print \"ERROR\",FILENAME,NR;}}}" > test.awk
|
||||
testcmd "awk -f test16.awk" "-f test.awk input" \
|
||||
"ERROR input 1\nERROR input 2\nERROR input 3\nERROR input 4\n" "$FILE1" ""
|
||||
|
||||
echo "BEGIN { number_of_users=0; } { if (NF>7) {
|
||||
user=0; for (i=1; i<=number_of_users; i++) { if (username[i] == \$3) { user=i;
|
||||
} } if (user == 0) { username[++number_of_users]=\$3; user=number_of_users; }
|
||||
count[user]++; } } END { for (i=1; i<=number_of_users; i++) {
|
||||
print count[i], username[i] } } " > test.awk
|
||||
testcmd "awk -f test17.awk" "-f test.awk input" "1 $USER\n" "$LLDATA" ""
|
||||
|
||||
echo "{ usrname[\$3]++;}END{for(i in usrname){print usrname[i],i;} }" > test.awk
|
||||
testcmd "awk -f test18.awk" "-f test.awk input" "1 \n1 $USER\n" "$LLDATA" ""
|
||||
|
||||
echo "{ if (NF>7) { username[\$3]++; } } END { for (i in username) {
|
||||
print username[i], i; } }" > test.awk
|
||||
testcmd "awk -f test19.awk" "-f test.awk input" "1 $USER\n" "$LLDATA" ""
|
||||
|
||||
echo "BEGIN { username[\"\"]=0; } { username[\$3]++; } END {
|
||||
for (i in username) { if (i != \"\") { print username[i], i; }}}" > test.awk
|
||||
testcmd "awk -f test20.awk" "-f test.awk input" "1 $USER\n" "$LLDATA" ""
|
||||
|
||||
echo "{ printf \"%5s %3d\n\", \$3, \$4; }" > test.awk
|
||||
testcmd "awk -f test22.awk" "-f test.awk input" \
|
||||
" ghi 5\n mno 10\n stu 15\n abc 20\n" "$FILE1" ""
|
||||
|
||||
echo "BEGIN { format1 =\"%8s %6sn\"; format2 =\"%8s %6dn\"; }
|
||||
{ printf(format2, \$1, \$4); }" > test.awk
|
||||
testcmd "awk -f test23.awk" "-f test.awk input" \
|
||||
" abc 5n ghi 10n mno 15n stu 20n" "$FILE1" ""
|
||||
|
||||
echo "END { for (i=1;i<=2;i++) {
|
||||
printf(\"i=%d\n\", i) > \"ConcatedFile_a\" i; } }" > test.awk
|
||||
testcmd "awk -f test24.awk" "-f test.awk && cat ConcatedFile_a1 &&
|
||||
cat ConcatedFile_a2 && rm -f ConcatedFile_a*" "i=1\ni=2\n" "" ""
|
||||
|
||||
L1=" abc def ghi 5\n"
|
||||
L2=" ghi jkl mno 10\n"
|
||||
L3=" mno pqr stu 15\n"
|
||||
L4=" stu vwx abc 20\n"
|
||||
echo "{ if (length(\$0) < 80) { prefix = \"\";
|
||||
for (i = 1;i<(40-length(\$0))/2;i++) { prefix = prefix \" \" };
|
||||
print prefix \$0; } else { print; } }" > test.awk
|
||||
testcmd "awk -f test26.awk" "-f test.awk input" "$L1$L2$L3$L4" "$FILE1" ""
|
||||
|
||||
echo "{ line = \$0; while (substr(line,length(line),1) == \"\\\\\") {
|
||||
line = substr(line,1,length(line)-1); i=getline; if (i > 0) {
|
||||
line = line \$0; } else { printf(\"%d\", NR); } } print line; }" > test.awk
|
||||
testcmd "awk -f test27.awk" "-f test.awk input" "$FILE1" "$FILE1" ""
|
||||
|
||||
echo "BEGIN { for (x = 0; x <= 20; x++) { if (x == 5) { continue; }
|
||||
printf \"%d \",x } print \"\" }" > test.awk
|
||||
testcmd "awk -f test28.awk" "-f test.awk" \
|
||||
"0 1 2 3 4 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \n" "" ""
|
||||
|
||||
echo "{ i = 1; while (i <= 2) { print \$i; i++ } }" > test.awk
|
||||
testcmd "awk -f test29.awk" "-f test.awk input" \
|
||||
"abc\ndef\nghi\njkl\nmno\npqr\nstu\nvwx\n" "$FILE1" ""
|
||||
|
||||
L1="abc def ghi 5\nabc def ghi 5\nabc def ghi 5\n"
|
||||
L2="ghi jkl mno 10\nghi jkl mno 10\nghi jkl mno 10\n"
|
||||
L3="mno pqr stu 15\nmno pqr stu 15\nmno pqr stu 15\n"
|
||||
L4="stu vwx abc 20\nstu vwx abc 20\nstu vwx abc 20\n"
|
||||
echo "{ i = 1; do { print \$0; i++ } while (i <= 3) }" > test.awk
|
||||
testcmd "awk -f test30.awk" "-f test.awk input" "$L1$L2$L3$L4" "$FILE1" ""
|
||||
|
||||
echo "{ for (i = 1; i <= 3; i++) print \$i }" > test.awk
|
||||
testcmd "awk -f test31.awk" "-f test.awk input" \
|
||||
"abc\ndef\nghi\nghi\njkl\nmno\nmno\npqr\nstu\nstu\nvwx\nabc\n" "$FILE1" ""
|
||||
|
||||
echo "{ num = \$1; for (div = 2; div*div <= num; div++) { if (num % div == 0) {
|
||||
break } } if (num % div == 0) { printf \"divisor of %d is %d\n\", num, div }
|
||||
else { printf \"%d is prime\n\", num } }" > test.awk
|
||||
testcmd "awk -f test32.awk" "-f test.awk input" \
|
||||
"divisor of 10 is 2\ndivisor of 15 is 3\n17 is prime\n" "10\n15\n17\n" ""
|
||||
|
||||
# Mod in case prog name is not 'awk'
|
||||
## echo "BEGIN { for (i = 0; i < ARGC; i++) { print ARGV[i] } }" > test.awk
|
||||
## testcmd "awk -f test33.awk" "-f test.awk input1 input2 input3 input4" \
|
||||
## "awk\ninput1\ninput2\ninput3\ninput4\n" "$FILE1" ""
|
||||
echo "BEGIN { for (i = 1; i < ARGC; i++) { print ARGV[i] } }" > test.awk
|
||||
testcmd "awk -f test33.awk" "-f test.awk input1 input2 input3 input4" \
|
||||
"input1\ninput2\ninput3\ninput4\n" "$FILE1" ""
|
||||
|
||||
echo "NR == 2 { NR = 17 } { print NR }" > test.awk
|
||||
testcmd "awk -f test34.awk" "-f test.awk input" "1\n17\n18\n19\n" \
|
||||
"$FILE1" ""
|
||||
|
||||
echo "BEGIN{n=0;}/abc/{++n;}END{print \"abc appears\",n,\"times\"}" > test.awk
|
||||
testcmd "awk -f test35.awk" "-f test.awk input" "abc appears 2 times\n" \
|
||||
"$FILE1" ""
|
||||
|
||||
echo "{ print \"Square root of\", \$1, \"is\", sqrt(\$1) }" > test.awk
|
||||
testcmd "awk -f test36.awk" "-f test.awk input" \
|
||||
"Square root of 25 is 5\n" "25" ""
|
||||
|
||||
FILE5="foo bar 2500\nabc def 2400\n"
|
||||
echo "\$1 == \"foo\" { print \$2 }" > test.awk
|
||||
testcmd "awk -f test37.awk" "-f test.awk input" "bar\n" "$FILE5" ""
|
||||
|
||||
echo "/2400/ && /foo/" > test.awk
|
||||
testcmd "awk -f test38.awk" "-f test.awk input" "" "$FILE5" ""
|
||||
|
||||
echo "/2400/ || /foo/" > test.awk
|
||||
testcmd "awk -f test39.awk" "-f test.awk input" "$FILE5" "$FILE5" ""
|
||||
|
||||
echo "! /foo/" > test.awk
|
||||
testcmd "awk -f test40.awk" "-f test.awk input" "abc def 2400\n" "$FILE5" ""
|
||||
|
||||
echo "\$1 ~ /foo/ { print \$2 }" > test.awk
|
||||
testcmd "awk -f test41.awk" "-f test.awk input" "bar\n" "$FILE5" ""
|
||||
|
||||
echo "{ if (! (\$0 ~ /foo/)) print }" > test.awk
|
||||
testcmd "awk -f test42.awk" "-f test.awk input" "abc def 2400\n" "$FILE5" ""
|
||||
|
||||
FILE6="Pat 100 97 58\nSandy 84 72 93\nChris 72 92 89\n"
|
||||
|
||||
echo "{ print \"F1:\", \$1 }" > test.awk
|
||||
testcmd "awk -f test43.awk" "-f test.awk input" "F1: foo\nF1: abc\n" \
|
||||
"$FILE5" ""
|
||||
|
||||
echo "{ sum = \$2 + \$3 + \$4 ; avg = sum / 3; print \$1, avg }" > test.awk
|
||||
testcmd "awk -f test44.awk" "-f test.awk input" \
|
||||
"Pat 85\nSandy 83\nChris 84.3333\n" "$FILE6" ""
|
||||
|
||||
echo "{ print \$1 > \"list1\"; print \$2 > \"list2\" }" > test.awk
|
||||
testcmd "awk -f test45.awk" "-f test.awk input && cat list1 && cat list2" \
|
||||
"Pat\nSandy\nChris\n100\n84\n72\n" "$FILE6" ""
|
||||
rm -f list1 list2
|
||||
|
||||
echo "{ print \$(2*2) }" > test.awk
|
||||
testcmd "awk -f test46.awk" "-f test.awk input" "58\n93\n89\n" "$FILE6" ""
|
||||
|
||||
echo "{ sub(/a+/,\"<A>\"); print }" > test.awk
|
||||
testcmd "awk -f test47.awk" "-f test.awk input" \
|
||||
"P<A>t 100 97 58\nS<A>ndy 84 72 93\nChris 72 92 89\n" "$FILE6" ""
|
||||
|
||||
echo "{ l[lines] = \$0; ++lines } END { for (i = lines-1; i >= 0; --i) {
|
||||
print l[i]} }" > test.awk
|
||||
testcmd "awk -f test48.awk" "-f test.awk input" \
|
||||
"Chris 72 92 89\nSandy 84 72 93\n\n" "$FILE6" ""
|
||||
|
||||
FILE7="Pat 100 97 58 77 89 11 45\nSandy 84 729\nChris 92 89\nsagar 22 2213\n"
|
||||
L1="Pat 100 97 58 77 89 11 45"
|
||||
L2="sagar 22 2213"
|
||||
L3="dd 335566778856"
|
||||
testcmd "awk Print line longer than 12" "'length(\$0) > 12' input" \
|
||||
"$L1\n$L2\n" "$FILE7" ""
|
||||
|
||||
FILE8="red apple blue berry green thumb"
|
||||
testcmd "awk Print first two field opposite order" "'{ print \$2, \$1 }' input" \
|
||||
"apple red\n" "$FILE8" ""
|
||||
|
||||
FILE9="1, Justin Timberlake, Title 545, Price $7.30\n2, Taylor Swift, Title 723, Price $7.90\n3, Mick Jagger, Title 610, Price $7.90\n4, Lady Gaga, Title 118, Price $7.30\n5, Johnny Cash, Title 482, Price $6.50\n6, Elvis Presley, Title 335, Price $7.30\n7, John Lennon, Title 271, Price $7.90\n8, Michael Jackson, Title 373, Price $5.50\n"
|
||||
testcmd "awk filter data" "'{ print \$5 }' input" \
|
||||
"545,\n723,\n610,\n118,\n482,\n335,\n271,\n373,\n" "$FILE9" ""
|
||||
|
||||
FILE10="abcd efgh ijkl mnop\nqrst uvwx yzab cdef\nghij klmn opqr stuv\nwxyz abcd efgh ijkl\nmnop qrst uvwx yz\n"
|
||||
L1="abcd efgh ijkl mnop"
|
||||
L2="wxyz abcd efgh ijkl"
|
||||
testcmd "awk print selected lines" "'/abcd/' input" \
|
||||
"$L1\n$L2\n" "$FILE10" ""
|
||||
L1="efgh mnop"
|
||||
L2="uvwx cdef"
|
||||
L3="klmn stuv"
|
||||
L4="abcd ijkl"
|
||||
L5="qrst yz"
|
||||
testcmd "awk print selected fields" "'{print \$2, \$4}' input" \
|
||||
"$L1\n$L2\n$L3\n$L4\n$L5\n" "$FILE10" ""
|
||||
|
||||
FILE11="abcd efgh ijkl mnop 4\nqrst uvwx yzab cdef 6\nghij klmn opqr stuv 0\nwxyz abcd efgh ijkl 1\nmnop qrst uvwx yz 2\n"
|
||||
FILE12="abcd\efgh\ijkl\mnop\4\nqrst\uvwx\yzab\cdef\6\nghij\klmn\opqr\stuv\0\nwxyz\abcd\efgh\ijkl\1\nmnop\qrst\uvwx\yz\2\n"
|
||||
testcmd "awk FS" "'BEGIN {FS=k;lksa;lkf;l} {print \$2}' input" "b\nr\nh\nx\nn\n" "$FILE11" ""
|
||||
|
||||
echo "{ if (\$1 == \"#START\") { FS=\":\"; } else if (\$1 == \"#STOP\") {
|
||||
FS=\" \"; } else { print \$3 } }" > test.awk
|
||||
testcmd "awk -v var=val -f test.awk" "-v var=2 -f test.awk input" \
|
||||
"ghi\nmno\nstu\nabc\nghi\nmno\nstu\nabc\n" "$FILE1$FILE4" ""
|
||||
|
||||
echo -e "abc def ghi 5\nghi jkl mno 10\nmno pqr stu 15\nstu vwx abc 20\n" > testfile1.txt
|
||||
echo -e "abc,def,ghi,5\nghi,jkl,mno,10\nmno,pqr,stu,15\nstu,vwx,abc,20\n" > testfile2.txt
|
||||
echo "{ if (\$1 == \"#START\") { FS=\":\"; } else if (\$1 == \"#STOP\") {
|
||||
FS=\" \"; } else { print \$3 } }" > test.awk
|
||||
testcmd "awk -v myvar=val -f file1 file" "-v myvar=$2 -f test.awk testfile1.txt testfile2.txt" "ghi\nmno\nstu\nabc\n\n\n\n\n\n\n" "" ""
|
||||
|
||||
### The -e option is non-standard. gawk and bbawk accept it; mawk and goawk do not, bwk awk says unknown option -e ignored but continues
|
||||
### bbawk does nothing useful with it: accepts -f and -e but runs the -e code out of order.
|
||||
### Correction: bbawk does do -e correctly now (since about December 2023?)
|
||||
|
||||
###testing "awk -e print print ARGC file1 file2" "awk -e '{ print \$1; print ARGC }' testfile1.txt testfile2.txt" "abc\n3\nghi\n3\nmno\n3\nstu\n3\n\n3\nabc,def,ghi,5\n3\nghi,jkl,mno,10\n3\nmno,pqr,stu,15\n3\nstu,vwx,abc,20\n3\n\n3\n" "" ""
|
||||
###testing "awk -e print ARGC file" "awk -e '{ print ARGC }' testfile1.txt" "2\n2\n2\n2\n2\n" "$FILE1" ""
|
||||
###testing "awk -e print print ARGC input" "awk -e '{ print \$1; print ARGC }' input" "abc\n2\nghi\n2\nmno\n2\nstu\n2\n" "$FILE1" ""
|
||||
|
||||
|
||||
# 2024: New tests -- not in Divya Kothari's original ...
|
||||
|
||||
# Assigning NF=0 caused trouble
|
||||
testcmd "assign NF=0" "'BEGIN { \$0 = \"a b\"; print NF, \"x\" \$0 \"y\"; NF = 0; print NF, \"x\" \$0 \"y\" }'" "2 xa by\n0 xy\n" "" ""
|
||||
|
||||
# The following has never had a problem but is a good test anyway
|
||||
testcmd "split on empty string" "'BEGIN { n = split(\"abc\", a, \"\");print n, length(a)}'" "3 3\n" "" ""
|
||||
# The following must be run with ASAN=1 to cause failure with older versions
|
||||
testcmd "split on empty regex" "'BEGIN { n = split(\"abc\", a, //);print n, length(a)}'" "3 3\n" "" ""
|
||||
|
||||
testcmd "srand() seeds unix time seconds" "'{dt = srand(srand()) - \$0; ok = dt == 0 || dt == 1; print ok}'" "1\n" "" "`date +%s`"
|
||||
testcmd "srand() default seed is 1" "'BEGIN{ print srand()}'" "1\n" "" ""
|
||||
|
||||
# A file with empty lines can be treated as multiline records if RS="".
|
||||
FILEMULTILINE="abc defxy ghi\njkl mno\n\n\npqr stu\nvwxy abc\n"
|
||||
|
||||
testcmd "multiline 1" "'BEGIN { RS=\"\"; FS=\"\"}; {print NR, NF, \$0; for (i=1;i<=NF;i++)printf \" %s %s\", i, \$i; print \"\"}'" "1 21 abc defxy ghi\njkl mno\n 1 a 2 b 3 c 4 5 d 6 e 7 f 8 x 9 y 10 11 g 12 h 13 i 14 \n 15 j 16 k 17 l 18 19 m 20 n 21 o\n2 16 pqr stu\nvwxy abc\n 1 p 2 q 3 r 4 5 s 6 t 7 u 8 \n 9 v 10 w 11 x 12 y 13 14 a 15 b 16 c\n" "" "$FILEMULTILINE"
|
||||
testcmd "multiline 2" "'BEGIN { RS=\"\"; FS=\" \"}; {print NR, NF, \$0; for (i=1;i<=NF;i++)printf \" %s %s\", i, \$i; print \"\"}'" "1 5 abc defxy ghi\njkl mno\n 1 abc 2 defxy 3 ghi 4 jkl 5 mno\n2 4 pqr stu\nvwxy abc\n 1 pqr 2 stu 3 vwxy 4 abc\n" "" "$FILEMULTILINE"
|
||||
testcmd "multiline 3" "'BEGIN { RS=\"\"; FS=\"x\"}; {print NR, NF, \$0; for (i=1;i<=NF;i++)printf \" %s %s\", i, \$i; print \"\"}'" "1 3 abc defxy ghi\njkl mno\n 1 abc def 2 y ghi 3 jkl mno\n2 3 pqr stu\nvwxy abc\n 1 pqr stu 2 vw 3 y abc\n" "" "$FILEMULTILINE"
|
||||
testcmd "multiline 4" "'BEGIN { RS=\"\"; FS=\"[ ]\"}; {print NR, NF, \$0; for (i=1;i<=NF;i++)printf \" %s %s\", i, \$i; print \"\"}'" "1 4 abc defxy ghi\njkl mno\n 1 abc 2 defxy 3 ghi\njkl 4 mno\n2 3 pqr stu\nvwxy abc\n 1 pqr 2 stu\nvwxy 3 abc\n" "" "$FILEMULTILINE"
|
||||
testcmd "multiline 5" "'BEGIN { RS=\"\"; FS=\"xy\"}; {print NR, NF, \$0; for (i=1;i<=NF;i++)printf \" %s %s\", i, \$i; print \"\"}'" "1 2 abc defxy ghi\njkl mno\n 1 abc def 2 ghi\njkl mno\n2 2 pqr stu\nvwxy abc\n 1 pqr stu\nvw 2 abc\n" "" "$FILEMULTILINE"
|
||||
|
||||
# A "null" RS other than an empty string, e.g. "()" cannot match anywhere and most awks will take the entire file as one record.
|
||||
# A bug in earlier versions (also in busybox awk) cause infinite output on "null RS" test
|
||||
testcmd "null RS" "'BEGIN { RS=\"()\"; FS=\" \"}; {print NR, NF, \$0; for (i=1;i<=NF;i++)printf \" %s %s\", i, \$i; print \"\"}'" "1 9 abc defxy ghi\njkl mno\n\n\npqr stu\nvwxy abc\n\n 1 abc 2 defxy 3 ghi 4 jkl 5 mno 6 pqr 7 stu 8 vwxy 9 abc\n" "" "$FILEMULTILINE"
|
||||
|
||||
testcmd "split() utf8" "'BEGIN{n = split(\"aβc\", a, \"\"); printf \"%d %d\", n, length(a);for (e = 1; e <= n; e++) printf \" %s %s\", e, \"(\" a[e] \")\";print \"\"}'" "3 3 1 (a) 2 (β) 3 (c)\n" "" ""
|
||||
testcmd "split fields utf8" "'BEGIN{FS=\"\"}; {printf \"%d\", NF; for (e = 1; e <= NF; e++) printf \" %s %s\", e, \"(\" \$e \")\"; print \"\"}'" "3 1 (a) 2 (β) 3 (c)\n" "" "aβc"
|
||||
|
||||
testcmd "nextfile" " '{print NR, FNR, \$0};/ghi jkl/{nextfile}/ghi,jkl/{nextfile}' testfile1.txt testfile2.txt" "1 1 abc def ghi 5\n2 2 ghi jkl mno 10\n3 1 abc,def,ghi,5\n4 2 ghi,jkl,mno,10\n" "" ""
|
||||
|
||||
testcmd "getline var numeric string bug fixed 20240514" "'BEGIN{getline var; print (var < 10.0)}'" "1\n" "" "5.0\n"
|
||||
|
||||
testcmd "lshift()" "'BEGIN{print lshift(3,2)}'" "12\n" "" ""
|
||||
testcmd "lshift() 64 bit" "'BEGIN{print lshift(1,40)}'" "1099511627776\n" "" ""
|
||||
testcmd "rshift()" "'BEGIN{print rshift(12, 1)}'" "6\n" "" ""
|
||||
testcmd "rshift() 64 bit" "'BEGIN{print rshift(1099511627776,39)}'" "2\n" "" ""
|
||||
testcmd "and()" "'BEGIN{print and(16, 25)}'" "16\n" "" ""
|
||||
testcmd "and(a, b, ...)" "'BEGIN{print and(16, 25, 10+16)}'" "16\n" "" ""
|
||||
testcmd "or()" "'BEGIN{print or(256, 16)}'" "272\n" "" ""
|
||||
testcmd "or(a, b, ...)" "'BEGIN{print or(256, 16, 8)}'" "280\n" "" ""
|
||||
testcmd "toupper()" "'BEGIN{print toupper(\"abABcD\")}'" "ABABCD\n" "" ""
|
||||
testcmd "tolower()" "'BEGIN{print tolower(\"abABcD\")}'" "ababcd\n" "" ""
|
||||
testcmd "substr()" "'BEGIN{print substr(\"abac\", 2, 2)}'" "ba\n" "" ""
|
||||
testcmd "atan2()" "'BEGIN{print substr(atan2(0, -1), 1, 5)}'" "3.141\n" "" ""
|
||||
testcmd "length()" "'{print length()}'" "1\n2\n0\n4\n" "" "a\n12\n\n6502"
|
||||
[ -n "$TEST_HOST" ] && export LC_ALL=en_US.UTF-8
|
||||
testcmd "length() utf8" "'{print length()}'< $FILES/utf8/japan.txt" "25\n" "" ""
|
||||
testcmd "substr() utf8" "'{print substr(\$0,2,1)}' < $FILES/utf8/arabic.txt" "ل\nأ\n" "" ""
|
||||
testcmd "index() utf8" "'{print index(\$0, \"ス\")}' < $FILES/utf8/japan.txt"\
|
||||
"5\n" "" ""
|
||||
testcmd "tolower() utf8" "'{print tolower(\$0)}'" "ğжþ\n" "" "ĞЖÞ"
|
||||
testcmd "tolower() utf8 expand" "'{print tolower(\$0)}'" "ⱥⱥⱥⱥⱥⱥⱥⱥⱥⱥⱥⱥⱥⱥⱥⱥⱥⱥⱥⱥⱥⱥ\n"\
|
||||
"" "ȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺȺ\n"
|
||||
testcmd "index() none" "'BEGIN{print index(\"ス\", \"deadbeef\")}'" "0\n" "" ""
|
||||
testcmd "index() same" "'BEGIN{print index(\"deadbeef\", \"deadbeef\")}'" "1\n" "" ""
|
||||
testcmd "match()" "'BEGIN{print match(\"bcdab\", \"ab\")}'" "4\n" "" ""
|
||||
testcmd "match() none" "'BEGIN{print match(\"ス\", \"deadbeef\")}'" "0\n" "" ""
|
||||
testcmd "match() utf8" "'{print match(\$0, \"ス\")}' < $FILES/utf8/japan.txt"\
|
||||
"5\n" "" ""
|
||||
testcmd "\\u" "'BEGIN{print \"\\u20\u255\"}' < /dev/null" " ɕ\n" "" ""
|
||||
testcmd "printf %c" "'BEGIN{a=255; printf \"%c%c%c\", a, b, 255}'"\
|
||||
"ÿ\0ÿ" "" ""
|
||||
|
||||
testcmd "printf %c, 0" "'BEGIN{a=0; printf \"(%c)\", a}'" "(\000)" "" ""
|
||||
testcmd "printf %c, null_string" "'BEGIN{a=\"\"; printf \"(%c)\", a}'" "(\000)" "" ""
|
||||
testcmd "printf %c, utf8" "'BEGIN{a=\"ú\"; printf \"(%c)\", a}'" "(ú)" "" ""
|
||||
#testcmd "name" "command" "result" "infile" "stdin"
|
||||
|
||||
testcmd "-b" "-b '{print length()}'< $FILES/utf8/japan.txt" "75\n" "" ""
|
||||
|
||||
testcmd "awk -e print print ARGC file1 file2" "'{ print \$1; print ARGC }' testfile1.txt testfile2.txt" "abc\n3\nghi\n3\nmno\n3\nstu\n3\n\n3\nabc,def,ghi,5\n3\nghi,jkl,mno,10\n3\nmno,pqr,stu,15\n3\nstu,vwx,abc,20\n3\n\n3\n" "" ""
|
||||
testcmd "awk -e print ARGC file" "'{ print ARGC }' testfile1.txt" "2\n2\n2\n2\n2\n" "$FILE1" ""
|
||||
testcmd "awk -e print print ARGC input" "'{ print \$1; print ARGC }' input" "abc\n2\nghi\n2\nmno\n2\nstu\n2\n" "$FILE1" ""
|
||||
|
||||
rm test.awk testfile1.txt testfile2.txt
|
||||
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
[ -f testing.sh ] && . testing.sh
|
||||
|
||||
# testing "name" "flags" "result" "infile" "stdin"
|
||||
|
||||
testcmd "simple" "" "ONUW24DMMUFA====\n" "" "simple\n"
|
||||
testcmd "file" "input" "ONUW24DMMUFA====\n" "simple\n" ""
|
||||
testcmd "simple -d" "-d" "simple\n" "" "ONUW24DMMUFA====\n"
|
||||
testcmd "file -d" "-d input" "simple\n" "ONUW24DMMUFA====" ""
|
||||
testcmd "default wrap" "" \
|
||||
"K5SSO5TFEBZGK4DMMFRWKZBAORUGKIDENFWGS5DINF2W2IDUNBSXSIDON5ZG2YLMNR4SA5LTMUQH\nO2LUNAQEM33MM5SXEJ3TEBBXE6LTORQWY4ZO\n" \
|
||||
"" "We've replaced the dilithium they normally use with Folger's Crystals."
|
||||
testcmd "multiline -d " "-d" \
|
||||
"We've replaced the dilithium they normally use with Folger's Crystals." "" \
|
||||
"K5SSO5TFEBZGK4DMMFRWKZBAORUGKIDENFWGS5DINF2W2IDUNBSXSIDON5ZG2YLMNR4SA5LTMUQH\nO2LUNAQEM33MM5SXEJ3TEBBXE6LTORQWY4ZO\n"
|
||||
|
||||
testcmd "-w" "-w 10" \
|
||||
"JVQXEY3INF\nXGOIDUN4QH\nI2DFEBRGKY\nLUEBXWMIDB\nEBSGSZTGMV\nZGK3TUEBVW\nK5DUNRSSA3\n3GEBTGS43I\nFY======\n" \
|
||||
"" "Marching to the beat of a different kettle of fish."
|
||||
|
||||
testcmd "-w0" "-w0 input" \
|
||||
"KZUWW2LOM5ZT6ICUNBSXEZJAMFUW4J3UEBXG6IDWNFVWS3THOMQGQZLSMUXCASTVON2CA5LTEBUG63TFON2CAZTBOJWWK4TTFYQFI2DFEB2G653OEB3WC4ZAMJ2XE3TJNZTSYIDUNBSSA5TJNRWGCZ3FOJZSA53FOJSSAZDFMFSC4ICUNBSXSIDENFSG4J3UEBXGKZLEEB2GQ33TMUQHG2DFMVYCAYLOPF3WC6JOEBKGQYLUE5ZSA33VOIQHG5DPOJ4SAYLOMQQHOZJHOJSSA43UNFRWW2LOM4QHI3ZANF2C4CQ=" \
|
||||
"Vikings? There ain't no vikings here. Just us honest farmers. The town was burning, the villagers were dead. They didn't need those sheep anyway. That's our story and we're sticking to it.\n" ""
|
||||
@@ -5,7 +5,6 @@
|
||||
#testcmd "name "args" "result" "infile" "stdin"
|
||||
|
||||
BDIR="$FILES/bc"
|
||||
TESTDIR="./"
|
||||
|
||||
run_bc_test() {
|
||||
tst="$1"
|
||||
|
||||
@@ -28,6 +28,9 @@ testing "ext4" "BLKID ext4" \
|
||||
testing "f2fs" "BLKID f2fs" \
|
||||
'temp.img: LABEL="myf2fs" UUID="b53d3619-c204-4c0b-8504-36363578491c" TYPE="f2fs"\n' \
|
||||
"" ""
|
||||
testing "iso" "BLKID iso" \
|
||||
'temp.img: LABEL="CDROM" UUID="2023-02-08-04-47-27-00" TYPE="iso9660"\n' \
|
||||
"" ""
|
||||
testing "msdos" "BLKID msdos" \
|
||||
'temp.img: SEC_TYPE="msdos" LABEL="mymsdos" UUID="6E1E-0851" TYPE="vfat"\n' \
|
||||
"" ""
|
||||
@@ -42,6 +45,9 @@ testing "squashfs" "BLKID squashfs" 'temp.img: TYPE="squashfs"\n' "" ""
|
||||
testing "vfat" "BLKID vfat" \
|
||||
'temp.img: SEC_TYPE="msdos" LABEL="myvfat" UUID="7356-B91D" TYPE="vfat"\n' \
|
||||
"" ""
|
||||
testing "fat32" "BLKID fat32" \
|
||||
'temp.img: LABEL="myfat32" UUID="2E7D-E046" TYPE="vfat"\n' \
|
||||
"" ""
|
||||
testing "xfs" "BLKID xfs" \
|
||||
'temp.img: LABEL="XFS_test" UUID="d63a1dc3-27d5-4dd4-8b38-f4f97f495c6f" TYPE="xfs"\n' \
|
||||
"" ""
|
||||
@@ -53,3 +59,8 @@ toyonly testing "stdin" "bzcat $FILES/blkid/squashfs.bz2 | blkid -" \
|
||||
#testing "minix" 'bzcat "$BDIR"/minix.bz2 | blkid -'
|
||||
#adfs bfs btrfs cramfs jfs nilfs romfs
|
||||
#vfat // fat32 fat12 fat16
|
||||
|
||||
bzcat $FILES/blkid/ext3.bz2 > temp.img
|
||||
testcmd "-o value -s" "-o value -s TYPE temp.img" 'ext3\n' "" ""
|
||||
testcmd "-o export" "-o export temp.img" 'DEVNAME=temp.img\nLABEL=myext3\nUUID=79d1c877-1a0f-4e7d-b21d-fc32ae3ef101\nSEC_TYPE=ext2\nTYPE=ext3\n' "" ""
|
||||
rm temp.img
|
||||
|
||||
+5
-6
@@ -16,17 +16,16 @@ testing "file1 notfound file2" \
|
||||
"cat file1 notfound file2 2>stderr && echo ok ; cat stderr; rm stderr" \
|
||||
"one\ntwo\ncat: notfound: No such file or directory\n" "" ""
|
||||
|
||||
FILE="$(readlink -f /proc/self/exe)"
|
||||
testing "file1" \
|
||||
'cat "$FILE" > file1 && cmp "$FILE" file1 && echo yes' \
|
||||
"yes\n" "" ""
|
||||
testing "binary" \
|
||||
'cat "$C" > file1 && cmp "$C" file1 && echo yes' "yes\n" "" ""
|
||||
|
||||
testing "- file1" \
|
||||
"cat - file1 | diff -a -U 0 - file1 | tail -n 1" \
|
||||
"-hello\n" "" "hello\n"
|
||||
|
||||
skipnot [ -e /dev/full ]
|
||||
testing "> /dev/full" \
|
||||
"cat - > /dev/full 2>stderr && echo ok; cat stderr; rm stderr" \
|
||||
"cat: xwrite: No space left on device\n" "" "zero\n"
|
||||
"cat - > /dev/full 2>/dev/null || echo failed" \
|
||||
"failed\n" "" "zero\n"
|
||||
|
||||
rm file1 file2
|
||||
|
||||
+60
-108
@@ -4,130 +4,82 @@
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
if [ "$(id -u)" -ne 0 ]
|
||||
then
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
echo "$SHOWSKIP: chattr (not root)"
|
||||
return 2>/dev/null
|
||||
exit
|
||||
fi
|
||||
|
||||
# chattr - Testcases
|
||||
function clean()
|
||||
{
|
||||
# We don't know whether the fs will have extents (e, typically true on the
|
||||
# desktop) or be encrypted (E, typically true on Android), or have data
|
||||
# inlined in the inode (N), or use indexed directories, so strip those out.
|
||||
# We also don't want to rely on chattr(1) to set a known version number or
|
||||
# project number, so blank out any numbers.
|
||||
sed -E -e 's/, (Encrypted|Extents|Indexed_directory|Inline_Data)//g;' \
|
||||
-e 's/[EeIN]-/--/g; s/[0-9]+/_/g'
|
||||
}
|
||||
|
||||
mkdir testattr
|
||||
IN="cd testattr"
|
||||
OUT="cd .."
|
||||
_t="abcdefghijklmnopqrstuvwxyz"
|
||||
|
||||
testing "[-/+]i FILE[write]" "$IN && echo "$_t" > testFile &&
|
||||
chattr +i testFile && lsattr testFile && echo "$_t" > testFile;
|
||||
chattr -i testFile; rm -rf testFile; $OUT " "----i-------- testFile\n" "" ""
|
||||
testing "[-/+]i FILE[re-write]" "$IN && echo "$_t" > testFile &&
|
||||
chattr +i testFile && echo \"$_t\" > testFile || chattr -i testFile &&
|
||||
echo \"$_t\" > testFile && lsattr testFile; rm -rf testFile; $OUT" \
|
||||
"------------- testFile\n" "" ""
|
||||
testing "[-/+]i FILE[append]" "$IN && echo "$_t" > testFile &&
|
||||
chattr +i testFile && echo \"$_t\" >> testFile || lsattr testFile &&
|
||||
chattr -i testFile; rm -rf testFile; $OUT" "----i-------- testFile\n" "" ""
|
||||
testing "[-/+]i FILE[move]" "$IN && echo "$_t" > testFile &&
|
||||
chattr +i testFile && mv testFile testFile1 || lsattr testFile &&
|
||||
chattr -i testFile; rm -rf testFile; $OUT" "----i-------- testFile\n" "" ""
|
||||
testing "[-/+]i FILE[delete]" "$IN && echo "$_t" > testFile &&
|
||||
chattr +i testFile && rm -f testFile || lsattr testFile &&
|
||||
chattr -i testFile; rm -rf testFile; $OUT" "----i-------- testFile\n" "" ""
|
||||
testing "[-/+]i FILE[read]" "$IN && echo "$_t" > testFile &&
|
||||
chattr +i testFile && cat testFile && lsattr testFile &&
|
||||
chattr -i testFile; rm -rf testFile; $OUT" "$_t\n----i-------- testFile\n" "" ""
|
||||
testing "[-/+]a FILE[write]" "$IN && echo "$_t" > testFile &&
|
||||
chattr +a testFile && echo $_t > testFile || lsattr testFile &&
|
||||
chattr -a testFile; rm -rf testFile; $OUT" "-----a------- testFile\n" "" ""
|
||||
testing "[-/+]a FILE[re-write]" "$IN && echo "$_t" > testFile &&
|
||||
chattr +a testFile && echo $_t > testFile || lsattr testFile &&
|
||||
chattr -a testFile && echo $_t > testFile && cat testFile &&
|
||||
lsattr testFile; rm -rf testFile;
|
||||
$OUT" "-----a------- testFile\n$_t\n------------- testFile\n" "" ""
|
||||
testing "[-/+]a FILE[append]" "$IN && echo "$_t" > testFile &&
|
||||
chattr +a testFile && echo $_t >> testFile && cat testFile &&
|
||||
lsattr testFile && chattr -a testFile; rm -rf testFile; $OUT" \
|
||||
"$_t\n$_t\n-----a------- testFile\n" "" ""
|
||||
testing "[-/+]a FILE[move]" "$IN && echo "$_t" > testFile &&
|
||||
chattr +a testFile && mv testFile testFile1 || lsattr testFile &&
|
||||
chattr -a testFile; rm -rf testFile; $OUT" "-----a------- testFile\n" "" ""
|
||||
testing "[-/+]a FILE[delete]" "$IN && echo "$_t" > testFile &&
|
||||
chattr +a testFile && rm -f testFile || lsattr testFile &&
|
||||
chattr -a testFile; rm -rf testFile; $OUT" "-----a------- testFile\n" "" ""
|
||||
testing "[-/+]a FILE[read]" "$IN && echo "$_t" > testFile &&
|
||||
chattr +a testFile && cat testFile && lsattr testFile && chattr -a testFile;
|
||||
rm -rf testFile; $OUT" "$_t\n-----a------- testFile\n" "" ""
|
||||
_empty="--------------------"
|
||||
|
||||
for attr in "A" "a" "c" "D" "d" "i" "j" "s" "S" "t" "T" "u"
|
||||
do
|
||||
testing "[-/+]$attr FILE" "$IN && echo "$_t" > testFile &&
|
||||
chattr +$attr testFile && cat testFile && chattr -$attr testFile &&
|
||||
lsattr testFile; rm -rf testFile; $OUT" "$_t\n------------- testFile\n" "" ""
|
||||
# Check +i (immutable) works by trying to write to and remove the file.
|
||||
_i="----i---------------"
|
||||
testing "immutable" "$IN && echo "$_t" > testFile &&
|
||||
chattr +i testFile && lsattr testFile | clean &&
|
||||
date > testFile 2>/dev/null; rm testFile; chattr -i testFile;
|
||||
cat testFile; rm -rf testFile; $OUT " "$_i testFile\n$_t\n" "" ""
|
||||
|
||||
# Check +a (append-only) works by failing to write and succeeding in appending.
|
||||
_a="-----a--------------"
|
||||
testing "append-only" "$IN && echo "$_t" > testFile &&
|
||||
chattr +a testFile &&
|
||||
echo $_t >> testFile &&
|
||||
date > testFile || lsattr testFile | clean &&
|
||||
chattr -a testFile; cat testFile; rm -rf testFile; $OUT" \
|
||||
"$_a testFile\n$_t\n$_t\n" "" ""
|
||||
|
||||
# For the rest, just toggle the bits back and forth (where supported).
|
||||
# Note that some file system/kernel combinations do return success but
|
||||
# silently ignore your request: +T on 4.19 f2fs, or +F on 5.2 ext4,
|
||||
# for example, so we're deliberately a bit selective here.
|
||||
# f2fs in 5.6+ kernels supports compression, but you can only enable
|
||||
# compression on a file while it's still empty, so we skip +c too.
|
||||
for attr in "A" "d" "e" "j" "P" "S" "s" "t" "u"; do
|
||||
echo "$_t" > testFile && chattr +$attr testFile 2>/dev/null || ((++SKIP))
|
||||
# Check that $attr is in the lsattr output, then that - turns it back off.
|
||||
testing "toggle $attr" "lsattr testFile | awk '{print \$1}' > attrs;
|
||||
grep -q $attr attrs || cat attrs; cat testFile && chattr -$attr testFile &&
|
||||
lsattr testFile | clean; rm -rf testFile" "$_t\n$_empty testFile\n" "" ""
|
||||
done
|
||||
|
||||
for attr in "A" "a" "c" "D" "d" "i" "j" "s" "S" "t" "T" "u"
|
||||
do
|
||||
testing "-$attr FILE" "$IN && echo "$_t" > testFile && chattr -$attr testFile &&
|
||||
cat testFile && lsattr testFile; rm -rf testFile; $OUT" "$_t\n------------- testFile\n" "" ""
|
||||
done
|
||||
_aA="-----a-A------------"
|
||||
testing "multiple bits" "$IN && touch testFile &&
|
||||
chattr +Aa testFile && lsattr testFile | clean &&
|
||||
chattr -Aa testFile && lsattr testFile | clean;
|
||||
rm -rf testFile; $OUT" "$_aA testFile\n$_empty testFile\n" "" ""
|
||||
|
||||
testing "[-/+]AacDdijsStTu FILE" "$IN && echo "$_t" > testFile &&
|
||||
chattr +AacDdijsStTu testFile && cat testFile && chattr -AacDdijsStTu testFile &&
|
||||
lsattr testFile; rm -rf testFile; $OUT" "$_t\n------------- testFile\n" "" ""
|
||||
testing "[-/+]AacDdijsStTu(random) FILE" \
|
||||
"$IN && echo "$_t" > testFile &&
|
||||
chattr +AacDdijsStTu testFile && cat testFile && chattr -A testFile &&
|
||||
chattr -a testFile && chattr -c testFile && chattr -D testFile &&
|
||||
chattr -d testFile && chattr -i testFile && chattr -j testFile &&
|
||||
chattr -s testFile && chattr -S testFile && chattr -t testFile &&
|
||||
chattr -T testFile && chattr -u testFile && lsattr testFile &&
|
||||
chattr -AacDdijsStTu testFile; rm -rf testFile; $OUT" \
|
||||
"$_t\n------------- testFile\n" "" ""
|
||||
testing "[-/+]AacDdijsStTu FILE*" "$IN &&
|
||||
echo "$_t" > testFile && echo "$_t" > testFile1 &&
|
||||
echo "$_t" > testFile2 && echo "$_t" > testFile3 &&
|
||||
echo "$_t" > testFile4 && echo "$_t" > testFile5 &&
|
||||
echo "$_t" > testFile6 && echo "$_t" > testFile7 &&
|
||||
echo "$_t" > testFile8 && echo "$_t" > testFile9 &&
|
||||
echo "$_t" > testFile10 && echo "$_t" > testFile11 &&
|
||||
chattr +AacDdijsStTu testFile* &&
|
||||
cat testFile9 && chattr -AacDdijsStTu testFile* && lsattr testFile*; rm -rf testFile*; $OUT" \
|
||||
"$_t\n------------- testFile\n------------- testFile1\n------------- testFile10\n------------- testFile11\n------------- testFile2\n------------- testFile3\n------------- testFile4\n------------- testFile5\n------------- testFile6\n------------- testFile7\n------------- testFile8\n------------- testFile9\n" "" ""
|
||||
testing "[-/+]AacDdijsStTu(random) FILE*" \
|
||||
"$IN && echo "$_t" > testFile &&
|
||||
chattr +AacDdijsStTu testFile* && cat testFile && chattr -A testFile* &&
|
||||
chattr -a testFile* && chattr -c testFile* && chattr -D testFile* &&
|
||||
chattr -d testFile* && chattr -i testFile* && chattr -j testFile* &&
|
||||
chattr -s testFile* && chattr -S testFile* && chattr -t testFile* &&
|
||||
chattr -T testFile* && chattr -u testFile* && lsattr testFile;
|
||||
rm -rf testFile; $OUT" \
|
||||
"$_t\n------------- testFile\n" "" ""
|
||||
testing "[-/+]i FILE[write]" \
|
||||
"$IN && echo "$_t" > testFile &&
|
||||
chattr +i testFile &&
|
||||
echo \"$_t\" > testFile || lsattr testFile && chattr -i testFile;
|
||||
rm -rf testFile; $OUT" "----i-------- testFile\n" "" ""
|
||||
testing "[-/+]A FILE[write]" \
|
||||
"$IN && echo "$_t" > testFile && chattr +A testFile &&
|
||||
echo \"$_t\" > testFile && lsattr testFile && chattr -A testFile;
|
||||
rm -rf testFile; $OUT" "-------A----- testFile\n" "" ""
|
||||
testing "[-/+]s FILE[write]" \
|
||||
"$IN && echo "$_t" > testFile && chattr +s testFile &&
|
||||
echo \"$_t\" > testFile && lsattr testFile && chattr -s testFile
|
||||
rm -rf testFile; $OUT" "s------------ testFile\n" "" ""
|
||||
testing "-v version FILE[write]" \
|
||||
"$IN && echo "$_t" > testFile &&
|
||||
chattr -v 1234 testFile && echo \"$_t\" > testFile &&
|
||||
lsattr -v testFile; rm -rf testFile" \
|
||||
" 1234 ------------- testFile\n" "" ""
|
||||
testing "multiple files" "$IN && touch fileA && touch fileB &&
|
||||
chattr +Aa fileA fileB && lsattr fileA fileB | clean &&
|
||||
chattr -Aa fileA fileB && lsattr fileA fileB | clean;
|
||||
rm -rf testFile*; $OUT" \
|
||||
"$_aA fileA\n$_aA fileB\n$_empty fileA\n$_empty fileB\n" "" ""
|
||||
|
||||
_a="-------A-----"
|
||||
testing "-R [-/+]a FILE" "$IN && touch aa && chattr -R +A aa && lsattr aa &&
|
||||
chattr -R -A aa; rm -rf aa; $OUT" "$_a aa\n" "" ""
|
||||
testing "-R [-/+]a FILE.." "$IN && touch aa bb &&
|
||||
chattr -R +A aa bb && lsattr aa bb &&
|
||||
chattr -R -A aa bb; rm -rf aa bb; $OUT" "$_a aa\n$_a bb\n" "" ""
|
||||
touch testFile && chattr -v 1234 testFile 2>/dev/null || ((++SKIP))
|
||||
testing "-v version" "lsattr -v testFile | awk '{print \$1}' &&
|
||||
chattr -v 4567 testFile && lsattr -v testFile | awk '{print \$1}';
|
||||
rm -rf testFile" "1234\n4567\n" "" ""
|
||||
|
||||
mkdir -p a/b/c && touch a/b/c/fA a/b/c/fB
|
||||
testing "-R" "chattr -R +a a && lsattr a/b/c/fA a/b/c/fB | clean &&
|
||||
chattr -R -a a && rm -rf a" \
|
||||
"$_a a/b/c/fA\n$_a a/b/c/fB\n" "" ""
|
||||
rm -rf a
|
||||
|
||||
# Clean up
|
||||
rm -rf testattr
|
||||
|
||||
+97
-210
@@ -24,223 +24,110 @@ mkdir dir
|
||||
touch file
|
||||
|
||||
# We don't need to test all 512 permissions
|
||||
for u in 0 1 2 3 4 5 6 7
|
||||
do
|
||||
for g in 0 3 6
|
||||
do
|
||||
for o in 0 7
|
||||
do
|
||||
if [ "$type" == file ]
|
||||
then
|
||||
type=dir
|
||||
rm -rf "./$type" && mkdir $type
|
||||
DASH=d
|
||||
else
|
||||
type=file
|
||||
rm -f "./$type" && touch $type
|
||||
DASH=-
|
||||
fi
|
||||
DASHES=$(num2perm $u$g$o)
|
||||
testing "$u$g$o $type" "chmod $u$g$o $type &&
|
||||
ls -ld $type | cut -d' ' -f 1 | cut -d. -f 1" "$DASH$DASHES\n" "" ""
|
||||
done
|
||||
done
|
||||
done
|
||||
for U in $(seq 0 7); do for G in 0 3 6; do for O in 0 7; do for T in dir file; do
|
||||
chmod 777 $T 2>/dev/null
|
||||
rm -rf $T
|
||||
if [ "$T" == file ]; then
|
||||
touch file
|
||||
C=-
|
||||
else
|
||||
mkdir dir
|
||||
C=d
|
||||
fi
|
||||
testing "$U$G$O $T" "chmod $U$G$O $T && ls -ld $T | cut -d' ' -f 1" \
|
||||
"${C}$(num2perm $U$G$O)\n" "" ""
|
||||
done; done; done; done
|
||||
unset U G O T C
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "750 dir 640 file" \
|
||||
"chmod 750 dir 640 file 2>/dev/null ||
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-x---\n-rwxr-x---\n" "" ""
|
||||
rm -rf dir file && mkdir dir && touch file 640
|
||||
testing "750 dir 640 file" "chmod 750 dir 640 file &&
|
||||
ls -ld 640 dir file | cut -d' ' -f 1 | cut -d. -f 1" \
|
||||
"-rwxr-x---\ndrwxr-x---\n-rwxr-x---\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "666 dir file" \
|
||||
"chmod 666 dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drw-rw-rw-\n-rw-rw-rw-\n" "" ""
|
||||
chtest()
|
||||
{
|
||||
chmod -fR 700 dir file 2>/dev/null
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "$1 dir file" \
|
||||
"chmod $1 dir file && ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" \
|
||||
"$2" "" ""
|
||||
}
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "765 *" "chmod 765 * &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxrw-r-x\n-rwxrw-r-x\n" "" ""
|
||||
chtest 666 "drw-rw-rw-\n-rw-rw-rw-\n"
|
||||
chtest 765 "drwxrw-r-x\n-rwxrw-r-x\n"
|
||||
chtest u=r "dr--r-xr-x\n-r--r--r--\n"
|
||||
chtest u=w "d-w-r-xr-x\n--w-r--r--\n"
|
||||
chtest u=x "d--xr-xr-x\n---xr--r--\n"
|
||||
chtest u+r "drwxr-xr-x\n-rw-r--r--\n"
|
||||
chtest u+w "drwxr-xr-x\n-rw-r--r--\n"
|
||||
chtest u+x "drwxr-xr-x\n-rwxr--r--\n"
|
||||
chtest u-r "d-wxr-xr-x\n--w-r--r--\n"
|
||||
chtest u-w "dr-xr-xr-x\n-r--r--r--\n"
|
||||
chtest u-x "drw-r-xr-x\n-rw-r--r--\n"
|
||||
chtest g=r "drwxr--r-x\n-rw-r--r--\n"
|
||||
chtest g=w "drwx-w-r-x\n-rw--w-r--\n"
|
||||
chtest g=x "drwx--xr-x\n-rw---xr--\n"
|
||||
chtest g+r "drwxr-xr-x\n-rw-r--r--\n"
|
||||
chtest g+w "drwxrwxr-x\n-rw-rw-r--\n"
|
||||
chtest g+x "drwxr-xr-x\n-rw-r-xr--\n"
|
||||
chtest g-r "drwx--xr-x\n-rw----r--\n"
|
||||
chtest g-w "drwxr-xr-x\n-rw-r--r--\n"
|
||||
chtest g-x "drwxr--r-x\n-rw-r--r--\n"
|
||||
chtest o=r "drwxr-xr--\n-rw-r--r--\n"
|
||||
chtest o=w "drwxr-x-w-\n-rw-r---w-\n"
|
||||
chtest o=x "drwxr-x--x\n-rw-r----x\n"
|
||||
chtest o+r "drwxr-xr-x\n-rw-r--r--\n"
|
||||
chtest o+w "drwxr-xrwx\n-rw-r--rw-\n"
|
||||
chtest o+x "drwxr-xr-x\n-rw-r--r-x\n"
|
||||
chtest o-r "drwxr-x--x\n-rw-r-----\n"
|
||||
chtest o-w "drwxr-xr-x\n-rw-r--r--\n"
|
||||
chtest o-x "drwxr-xr--\n-rw-r--r--\n"
|
||||
chtest a=r "dr--r--r--\n-r--r--r--\n"
|
||||
chtest a=w "d-w--w--w-\n--w--w--w-\n"
|
||||
chtest a=x "d--x--x--x\n---x--x--x\n"
|
||||
chtest a+r "drwxr-xr-x\n-rw-r--r--\n"
|
||||
chtest a+w "drwxrwxrwx\n-rw-rw-rw-\n"
|
||||
chtest a+x "drwxr-xr-x\n-rwxr-xr-x\n"
|
||||
chtest a-r "d-wx--x--x\n--w-------\n"
|
||||
chtest a-w "dr-xr-xr-x\n-r--r--r--\n"
|
||||
chtest a-x "drw-r--r--\n-rw-r--r--\n"
|
||||
chtest =r "dr--r--r--\n-r--r--r--\n"
|
||||
chtest =w "d-w-------\n--w-------\n"
|
||||
chtest =x "d--x--x--x\n---x--x--x\n"
|
||||
chtest +r "drwxr-xr-x\n-rw-r--r--\n"
|
||||
chtest +w "drwxr-xr-x\n-rw-r--r--\n"
|
||||
chtest +x "drwxr-xr-x\n-rwxr-xr-x\n"
|
||||
chtest -r "d-wx--x--x\n--w-------\n"
|
||||
chtest -w "dr-xr-xr-x\n-r--r--r--\n"
|
||||
chtest -x "drw-r--r--\n-rw-r--r--\n"
|
||||
chtest a-w,a+x "dr-xr-xr-x\n-r-xr-xr-x\n"
|
||||
|
||||
##### u,g,o,a=r,w,x
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "u=r dir file" "chmod u=r dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "dr--r-xr-x\n-r--r--r--\n" "" ""
|
||||
# macOS doesn't allow +s in /tmp
|
||||
touch s-supported
|
||||
chmod +s s-supported 2>/dev/null || SKIP=99
|
||||
rm s-supported
|
||||
chtest g+s "drwxr-sr-x\n-rw-r-Sr--\n"
|
||||
chtest u+s "drwsr-xr-x\n-rwSr--r--\n"
|
||||
chtest +s "drwsr-sr-x\n-rwSr-Sr--\n"
|
||||
chtest o+s "drwxr-xr-x\n-rw-r--r--\n"
|
||||
SKIP=0
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "u=w dir file" "chmod u=w dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d-w-r-xr-x\n--w-r--r--\n" "" ""
|
||||
chtest +t "drwxr-xr-t\n-rw-r--r-T\n"
|
||||
chtest a=r+w+x "drwxrwxrwx\n-rwxrwxrwx\n"
|
||||
chtest u+rwX-s,g+rX-ws,o+rX-wt "drwxr-xr-x\n-rw-r--r--\n"
|
||||
chtest u+rwX,u-s,g+rX,g-ws,o+rX,o-wt "drwxr-xr-x\n-rw-r--r--\n"
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "u=x dir file" "chmod u=x dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d--xr-xr-x\n---xr--r--\n" "" ""
|
||||
# (chtest starts off with a directory that's +x...)
|
||||
testing "+X" \
|
||||
"mkdir -m 000 Xd && touch Xf && chmod +X Xd Xf && ls -ld Xd Xf | cut -d' ' -f 1" \
|
||||
"d--x--x--x\n-rw-r--r--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "u+r dir file" "chmod u+r dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "u+w dir file" "chmod u+w dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "u+x dir file" "chmod u+x dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rwxr--r--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "u-r dir file" "chmod u-r dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d-wxr-xr-x\n--w-r--r--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "u-w dir file" "chmod u-w dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "dr-xr-xr-x\n-r--r--r--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "u-x dir file" "chmod u-x dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drw-r-xr-x\n-rw-r--r--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "g=r dir file" "chmod g=r dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr--r-x\n-rw-r--r--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "g=w dir file" "chmod g=w dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwx-w-r-x\n-rw--w-r--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "g=x dir file" "chmod g=x dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwx--xr-x\n-rw---xr--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "g+r dir file" "chmod g+r dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "g+w dir file" "chmod g+w dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxrwxr-x\n-rw-rw-r--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "g+x dir file" "chmod g+x dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r-xr--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "g-r dir file" "chmod g-r dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwx--xr-x\n-rw----r--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "g-w dir file" "chmod g-w dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "g-x dir file" "chmod g-x dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr--r-x\n-rw-r--r--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "o=r dir file" "chmod o=r dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr--\n-rw-r--r--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "o=w dir file" "chmod o=w dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-x-w-\n-rw-r---w-\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "o=x dir file" "chmod o=x dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-x--x\n-rw-r----x\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "o+r dir file" "chmod o+r dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "o+w dir file" "chmod o+w dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xrwx\n-rw-r--rw-\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "o+x dir file" "chmod o+x dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r-x\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "o-r dir file" "chmod o-r dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-x--x\n-rw-r-----\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "o-w dir file" "chmod o-w dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "o-x dir file" "chmod o-x dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr--\n-rw-r--r--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "a=r dir file" "chmod a=r dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "dr--r--r--\n-r--r--r--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "a=w dir file" "chmod a=w dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d-w--w--w-\n--w--w--w-\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "a=x dir file" "chmod a=x dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d--x--x--x\n---x--x--x\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "a+r dir file" "chmod a+r dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "a+w dir file" "chmod a+w dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxrwxrwx\n-rw-rw-rw-\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "a+x dir file" "chmod a+x dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rwxr-xr-x\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "a-r dir file" "chmod a-r dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d-wx--x--x\n--w-------\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "a-w dir file" "chmod a-w dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "dr-xr-xr-x\n-r--r--r--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "a-x dir file" "chmod a-x dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drw-r--r--\n-rw-r--r--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "=r dir file" "chmod =r dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "dr--r--r--\n-r--r--r--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "=w dir file" "chmod =w dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d-w-------\n--w-------\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "=x dir file" "chmod =x dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d--x--x--x\n---x--x--x\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "+r dir file" "chmod +r dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "+w dir file" "chmod +w dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "+x dir file" "chmod +x dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rwxr-xr-x\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "-r dir file" "chmod -r dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d-wx--x--x\n--w-------\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "-w dir file" "chmod -w dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "dr-xr-xr-x\n-r--r--r--\n" "" ""
|
||||
|
||||
rm -rf dir file && mkdir dir && touch file
|
||||
testing "-x dir file" "chmod -x dir file &&
|
||||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drw-r--r--\n-rw-r--r--\n" "" ""
|
||||
mkdir foo
|
||||
ln -s bar foo/baz
|
||||
# If you explicitly ask us, we'll try (and fail) to chmod a symlink.
|
||||
testing "-R symlink arg" 'chmod -R 750 foo/baz 2>/dev/null; echo $?' "1\n" "" ""
|
||||
# If you only imply that you might want us to do that, we'll skip it.
|
||||
testing "-R symlink recurse" 'chmod -R 750 foo; echo $?' "0\n" "" ""
|
||||
|
||||
# Removing test files for cleanup purpose
|
||||
rm -rf dir file
|
||||
|
||||
+4
-4
@@ -17,13 +17,13 @@ rm -f one two
|
||||
# Check the length suppression, both calculate the CRC on 'abc' but the second
|
||||
# option has length suppression on and has the length concatenated to 'abc'.
|
||||
testing "on abc including length" "cksum" "1219131554 3\n" "" 'abc'
|
||||
testing "on abc excluding length" "cksum -N" "1219131554\n" "" 'abc\x3'
|
||||
toyonly testing "on abc excluding length" "cksum -N" "1219131554\n" "" 'abc\x3'
|
||||
|
||||
# cksum on no contents gives 0xffffffff (=4294967295)
|
||||
testing "on no data post-inversion" "echo -n "" | cksum" "4294967295 0\n" "" ""
|
||||
# If we do preinversion we will then get 0.
|
||||
testing "on no data pre+post-inversion" "echo -n "" | cksum -P" "0 0\n" "" ""
|
||||
toyonly testing "on no data pre+post-inversion" "echo -n "" | cksum -P" "0 0\n" "" ""
|
||||
# If we skip the post-inversion we also get 0
|
||||
testing "on no data no inversion" "echo -n "" | cksum -I" "0 0\n" "" ""
|
||||
toyonly testing "on no data no inversion" "echo -n "" | cksum -I" "0 0\n" "" ""
|
||||
# Two wrongs make a right.
|
||||
testing "on no data pre-inversion" "echo -n "" | cksum -PI" "4294967295 0\n" "" ""
|
||||
toyonly testing "on no data pre-inversion" "echo -n "" | cksum -PI" "4294967295 0\n" "" ""
|
||||
|
||||
+19
-16
@@ -3,13 +3,13 @@
|
||||
[ -f testing.sh ] && . testing.sh
|
||||
|
||||
# TODO: coreutils cmp uses stdin if only one file is given
|
||||
testing "one argument match" 'cmp input && echo yes' "yes\n" \
|
||||
testcmd "one argument match" 'input && echo yes' "yes\n" \
|
||||
"one\ntwo\nthree" "one\ntwo\nthree"
|
||||
# posix says ""%s %s differ: char %d, line %d\n" but diffutils says "byte"
|
||||
testing "one argument diff" 'cmp input | sed s/byte/char/' \
|
||||
testcmd "one argument diff" 'input | sed s/byte/char/' \
|
||||
"input - differ: char 5, line 2\n" "one\ntwo\nthree" "one\nboing\nthree"
|
||||
|
||||
testing "missing file1 [fail]" 'cmp file1 input 2>/dev/null || echo $?' "2\n" "foo" ""
|
||||
testcmd "missing file1 [fail]" 'file1 input 2>/dev/null || echo $?' "2\n" "foo" ""
|
||||
|
||||
#mkdir dir
|
||||
#testing "directory [fail]" "cmp dir dir 2>/dev/null || echo yes" \
|
||||
@@ -19,27 +19,30 @@ testing "missing file1 [fail]" 'cmp file1 input 2>/dev/null || echo $?' "2\n" "f
|
||||
echo "ab
|
||||
c" > input2
|
||||
|
||||
testing "identical files, stdout" "cmp input input2" "" "ab\nc\n" ""
|
||||
testing "identical files, return code" "cmp input input2 && echo yes" "yes\n" "ab\nc\n" ""
|
||||
testcmd "identical files, stdout" "input input2" "" "ab\nc\n" ""
|
||||
testcmd "identical files, return code" "input input2 && echo yes" "yes\n" "ab\nc\n" ""
|
||||
|
||||
testing "EOF, stderr" "cmp input input2 2>&1" "cmp: EOF on input2\n" "ab\nc\nx" ""
|
||||
testing "EOF, return code" "cmp input input2 2>/dev/null || echo yes" "yes\n" "ab\nc\nx" ""
|
||||
testcmd "EOF, stderr" "input input2 2>&1" \
|
||||
"cmp: EOF on input2 after byte 5, line 2\n" "ab\nc\nx" ""
|
||||
testcmd "EOF, return code" "input input2 2>/dev/null || echo yes" "yes\n" "ab\nc\nx" ""
|
||||
# The gnu/dammit version fails this because posix says "char" and they don't.
|
||||
testing "diff, stdout" "cmp input input2 | sed s/byte/char/" \
|
||||
testcmd "diff, stdout" "input input2 | sed s/byte/char/" \
|
||||
"input input2 differ: char 4, line 2\n" "ab\nx\nx" ""
|
||||
testing "diff, return code" "cmp input input2 > /dev/null || echo yes" "yes\n" "ab\nx\nx" ""
|
||||
testcmd "diff, return code" "input input2 > /dev/null || echo yes" "yes\n" "ab\nx\nx" ""
|
||||
|
||||
testing "-s EOF, return code" "cmp -s input input2 2>&1 || echo yes" "yes\n" "ab\nc\nx" ""
|
||||
testing "-s diff, return code" "cmp -s input input2 2>&1 || echo yes" "yes\n" "ab\nx\nx" ""
|
||||
testcmd "-s EOF, return code" "-s input input2 2>&1 || echo yes" "yes\n" "ab\nc\nx" ""
|
||||
testcmd "-s diff, return code" "-s input input2 2>&1 || echo yes" "yes\n" "ab\nx\nx" ""
|
||||
|
||||
testing "-l EOF, stderr" "cmp -l input input2 2>&1" "cmp: EOF on input2\n" "ab\nc\nx" ""
|
||||
testing "-l diff and EOF, stdout and stderr" "cmp -l input input2 2>&1 | sort" "4 170 143\ncmp: EOF on input2\n" "ab\nx\nx" ""
|
||||
testcmd "-l EOF, stderr" "-l input input2 2>&1" \
|
||||
"cmp: EOF on input2 after byte 5\n" "ab\nc\nx" ""
|
||||
testcmd "-l diff and EOF, stdout and stderr" "-l input input2 2>&1 | sort" \
|
||||
"4 170 143\ncmp: EOF on input2 after byte 5\n" "ab\nx\nx" ""
|
||||
|
||||
testing "-s not exist" "cmp -s input doesnotexist 2>&1 || echo yes" "yes\n" "" ""
|
||||
testcmd "-s not exist" "-s input doesnotexist 2>&1 || echo yes" "yes\n" "x" ""
|
||||
|
||||
rm input2
|
||||
|
||||
testing "stdin and file" "cmp input - | sed s/byte/char/" \
|
||||
testcmd "stdin and file" "input - | sed s/byte/char/" \
|
||||
"input - differ: char 4, line 2\n" "ab\nc\n" "ab\nx\n"
|
||||
#testing "stdin and stdin" "cmp input -" "" "" "ab\nc\n"
|
||||
testcmd "-n skip1 skip2" "-n 3 input - 3 5 && echo yes" "yes\n" "abcdef123" "vwxyzdef987"
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
[ -f testing.sh ] && . testing.sh
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
echo -e 'a\nb\nc'> lhs
|
||||
for i in c d e ; do echo $i >> rhs ; done
|
||||
testing "comm" "comm lhs input" "a\nb\n\t\tc\n\td\n\te\n" "c\nd\ne\n" ""
|
||||
testing "comm -" "comm - input" "a\nb\n\t\tc\n\td\n\te\n" "c\nd\ne\n" "a\nb\nc\n"
|
||||
testing "comm -123 detects missing" "comm - missing 2>/dev/null || echo here" \
|
||||
"here\n" "" ""
|
||||
+36
-7
@@ -83,8 +83,7 @@ rm one two random
|
||||
rm -rf dir
|
||||
|
||||
mkdir -p one/two/three/four
|
||||
touch one/two/three/five
|
||||
touch one/{six,seven,eight}
|
||||
touch one/two/three/five one/{six,seven,eight}
|
||||
testing "-r /abspath dest" \
|
||||
"cp -r \"$(readlink -f one)\" dir && diff -r one dir && echo yes" \
|
||||
"yes\n" "" ""
|
||||
@@ -113,12 +112,42 @@ testing "duplicated --preserve options" \
|
||||
"cp --preserve=mode,mode walrus walrus2 2>&1 || echo bad" "" "" ""
|
||||
rm -rf walrus woot carpenter
|
||||
|
||||
mkdir -p b/c/d/
|
||||
mkdir a/
|
||||
mkdir dir
|
||||
echo a > file
|
||||
echo b > b
|
||||
testing "-T file" "cp -T b file && cat file" "b\n" "" ""
|
||||
testing "-T dir" "cp -T b dir 2>/dev/null || echo expected" "expected\n" "" ""
|
||||
rm b file
|
||||
|
||||
mkdir -p b/c/d/ a/
|
||||
echo a > b/c/d/file
|
||||
testing "-D b/c/d/file a/" "cp -D b/c/d/file a/ && cat a/b/c/d/file" "a\n" "" ""
|
||||
rm -rf a/
|
||||
rm -rf b/
|
||||
testing "--parents b/c/d/file a/" "cp --parents b/c/d/file a/ && cat a/b/c/d/file" "a\n" "" ""
|
||||
rm -rf a/ b/
|
||||
|
||||
echo a > file
|
||||
testing "-P file" "cp -P file fdst && stat -c %F fdst" "regular file\n" "" ""
|
||||
ln -s file lnk
|
||||
testing "-P symlink" "cp -P lnk ldst && stat -c %F ldst" "symbolic link\n" "" ""
|
||||
testing "follow symlink" "cp lnk ldst2 && stat -c %F ldst2" "regular file\n" "" ""
|
||||
rm file fdst lnk ldst ldst2
|
||||
|
||||
mkdir sub
|
||||
testing "-t one arg" 'cp -t sub/ input && cat sub/input' 'yes\n' 'yes\n' ''
|
||||
toyonly testing "-Dt" 'cp -Dt sub2 input && cat sub2/input' 'and\n' 'and\n' ''
|
||||
rm -rf sub sub2
|
||||
|
||||
testing '-u1' 'echo one>one; sleep .1; echo two>two; cp -u one two; cat two' \
|
||||
'two\n' '' ''
|
||||
testing '-u2' 'echo two>two; sleep .1; echo one>one; cp -u one two; cat two' \
|
||||
'one\n' '' ''
|
||||
mkdir a b
|
||||
|
||||
echo potato > a/one
|
||||
echo potato > a/two
|
||||
touch b/one b/two
|
||||
testing '-i' 'cp -ri a/. b/. 2>/dev/null; cmp -s a/one b/one || cmp -s a/one b/two && echo yes' \
|
||||
'yes\n' '' 'n\ny\n'
|
||||
rm -rf one two a b
|
||||
|
||||
# cp -r ../source destdir
|
||||
# cp -r one/two/three missing
|
||||
|
||||
+66
-6
@@ -6,15 +6,20 @@
|
||||
# This means all possible values of strlen(name)+1 % 4,
|
||||
# plus file sizes of at least 0-4.
|
||||
|
||||
CPIO="cpio${TEST_HOST:+ --quiet}"
|
||||
CPI_O="$CPIO -o -H newc"
|
||||
|
||||
touch a bb ccc dddd
|
||||
testing "name padding" "cpio -o -H newc|cpio -it" "a\nbb\nccc\ndddd\n" "" "a\nbb\nccc\ndddd\n"
|
||||
testing "name padding" "$CPI_O|$CPIO -it" "a\nbb\nccc\ndddd\n" \
|
||||
"" "a\nbb\nccc\ndddd\n"
|
||||
rm a bb ccc dddd
|
||||
|
||||
touch a
|
||||
printf '1' >b
|
||||
printf '22' >c
|
||||
printf '333' >d
|
||||
testing "file padding" "cpio -o -H newc|cpio -it" "a\nb\nc\nd\n" "" "a\nb\nc\nd\n"
|
||||
testing "file padding" "$CPI_O|$CPIO -it" "a\nb\nc\nd\n" "" \
|
||||
"a\nb\nc\nd\n"
|
||||
rm a b c d
|
||||
|
||||
touch a
|
||||
@@ -25,15 +30,70 @@ printf '333' >dddd
|
||||
# the relevant bit should be here:
|
||||
# 110*5 + 4*3 + 2 + 6*3 = 550 + 12 + 20 = 582
|
||||
# files are padded to n*4, names are padded to 2 + n*4 due to the header length
|
||||
testing "archive length" "cpio -o -H newc|dd ibs=2 skip=291 count=5 2>/dev/null" "TRAILER!!!" "" "a\nbb\nccc\ndddd\n"
|
||||
testing "archive magic" "cpio -o -H newc|dd ibs=2 count=3 2>/dev/null" "070701" "" "a\n"
|
||||
testing "archive length" "$CPI_O|dd ibs=2 skip=291 count=5 2>/dev/null" "TRAILER!!!" "" "a\nbb\nccc\ndddd\n"
|
||||
testing "archive magic" "$CPI_O|dd ibs=2 count=3 2>/dev/null" "070701" "" "a\n"
|
||||
# check name length (8 bytes before the empty "crc")
|
||||
testing "name length" "cpio -o -H newc|dd ibs=2 skip=47 count=4 2>/dev/null" "00000002" "" "a\n"
|
||||
testing "name length" "$CPI_O|dd ibs=2 skip=47 count=4 2>/dev/null" "00000002" "" "a\n"
|
||||
testing "-t" "$CPI_O|$CPIO -it" "a\nbb\n" "" "a\nbb"
|
||||
# Only actually tests anything on toybox. :)
|
||||
testing "-t --quiet" "$CPI_O|$CPIO -it --quiet" "a\nbb\n" "" "a\nbb"
|
||||
mkdir out
|
||||
testing "-p" "$CPIO -p out && find out | sort" "out\nout/a\nout/bb\n" "" "a\nbb"
|
||||
rm -rf out
|
||||
testing "-pd" "$CPIO -pd out && find out | sort" "out\nout/a\nout/bb\n" "" "a\nbb"
|
||||
rm a bb ccc dddd
|
||||
|
||||
# archive dangling symlinks and empty files even if we cannot open them
|
||||
touch a; chmod a-rwx a; ln -s a/cant b
|
||||
testing "archives unreadable empty files" "cpio -o -H newc|cpio -it" "a\nb\n" "" "a\nb\n"
|
||||
toyonly testing "archives unreadable empty files" "$CPI_O|$CPIO -it" "b\na\n" "" "b\na\n"
|
||||
chmod u+rw a; rm -f a b
|
||||
|
||||
mkdir a
|
||||
echo "old" >a/b
|
||||
echo "a/b" | $CPI_O >a.cpio
|
||||
testing "directory exists is not an error" \
|
||||
"$CPI_O | { $CPIO -i 2>&1 || echo bad; }" "" "" "a\n"
|
||||
rm -rf a
|
||||
testing "-i doesn't create leading directories" \
|
||||
"$CPIO -i <a.cpio 2>/dev/null; [ -e a ] || echo yes" "yes\n" "" ""
|
||||
rm -rf a
|
||||
testing "-id creates leading directories" "$CPIO -id <a.cpio && cat a/b" \
|
||||
"old\n" "" ""
|
||||
rm -rf a a.cpio
|
||||
|
||||
mkdir a
|
||||
echo "old" >a/b
|
||||
find a | $CPI_O >a.cpio
|
||||
testing "-i keeps existing files" "echo new >a/b && $CPIO -i <a.cpio 2>/dev/null; cat a/b" "new\n" "" ""
|
||||
testing "-id keeps existing files" "echo new >a/b && $CPIO -id <a.cpio 2>/dev/null; cat a/b" "new\n" "" ""
|
||||
testing "-iu replaces existing files; no error" "echo new >a/b && $CPIO -iu <a.cpio && cat a/b" "old\n" "" ""
|
||||
testing "-idu replaces existing files; no error" "echo new >a/b && $CPIO -idu <a.cpio && cat a/b" "old\n" "" ""
|
||||
# The kernel's initramfs extractor does this
|
||||
toyonly testing "skip NUL" "for i in a b; do dd if=/dev/zero bs=512 count=1 2>/dev/null; cat a.cpio; done | $CPIO -t -H newc" \
|
||||
"a\na/b\na\na/b\n" "" ""
|
||||
rm -rf a a.cpio
|
||||
|
||||
testing "error on empty file" "$CPIO -i 2>/dev/null || echo err" "err\n" "" ""
|
||||
|
||||
mkdir a
|
||||
touch a/file
|
||||
ln -s a/symlink a/symlink
|
||||
mkdir a/dir
|
||||
find a | $CPI_O >a.cpio
|
||||
if [ "$(id -u)" -eq 0 ]; then
|
||||
# We chown between user "root" and the last user in /etc/passwd,
|
||||
# and group "root" and the last group in /etc/group.
|
||||
USR="$(sed -n '$s/:.*//p' /etc/passwd)"
|
||||
GRP="$(sed -n '$s/:.*//p' /etc/group)"
|
||||
# Or if that fails, we assume we're on Android...
|
||||
: "${USR:=shell}"
|
||||
: "${GRP:=shell}"
|
||||
chown -h "${USR}:${GRP}" a/file a/symlink a/dir
|
||||
fi
|
||||
skipnot [ $(id -u) -eq 0 ]
|
||||
testing "-t preserve ownership" "$CPIO -t <a.cpio >/dev/null && stat -c '%U:%G' a/file a/symlink a/dir" "${USR}:${GRP}\n${USR}:${GRP}\n${USR}:${GRP}\n" "" ""
|
||||
rm -rf a a.cpio
|
||||
|
||||
echo payload > one
|
||||
ln -s one two
|
||||
testing '-L' "$CPI_O -L | grep -ao payload" 'payload\n' '' 'two\n'
|
||||
|
||||
+31
-24
@@ -13,27 +13,28 @@ echo "one:two:three:four:five:six:seven
|
||||
alpha:beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu
|
||||
the quick brown fox jumps over the lazy dog" >abc.txt
|
||||
|
||||
testing "-b a,a,a" "cut -b 3,3,3 abc.txt" "e\np\ne\n" "" ""
|
||||
testing "-b overlaps" "cut -b 1-3,2-5,7-9,9-10 abc.txt" \
|
||||
testcmd "-b a,a,a" "-b 3,3,3 abc.txt" "e\np\ne\n" "" ""
|
||||
testcmd "-b overlaps" "-b 1-3,2-5,7-9,9-10 abc.txt" \
|
||||
"one:to:th\nalphabeta\nthe qick \n" "" ""
|
||||
testing "-b encapsulated" "cut -b 3-8,4-6 abc.txt" "e:two:\npha:be\ne quic\n" \
|
||||
testcmd "-b encapsulated" "-b 3-8,4-6 abc.txt" "e:two:\npha:be\ne quic\n" \
|
||||
"" ""
|
||||
testing "-bO overlaps" \
|
||||
"cut --output-delimiter ' ' -b 1-3,2-5,7-9,9-10 abc.txt" \
|
||||
toyonly testcmd "-bO overlaps" "-O ' ' -b 1-3,2-5,7-9,9-10 abc.txt" \
|
||||
"one:t o:th\nalpha beta\nthe q ick \n" "" ""
|
||||
testing "high-low error" "cut -b 8-3 abc.txt 2>/dev/null || echo err" "err\n" \
|
||||
testcmd "high-low error" "-b 8-3 abc.txt 2>/dev/null || echo err" "err\n" \
|
||||
"" ""
|
||||
|
||||
testing "-c a-b" "cut -c 4-10 abc.txt" ":two:th\nha:beta\n quick \n" "" ""
|
||||
testing "-c a-" "cut -c 41- abc.txt" "\ntheta:iota:kappa:lambda:mu\ndog\n" "" ""
|
||||
testing "-c -b" "cut -c -39 abc.txt" \
|
||||
testcmd "-c a-b" "-c 4-10 abc.txt" ":two:th\nha:beta\n quick \n" "" ""
|
||||
testcmd "-c a-" "-c 41- abc.txt" "\ntheta:iota:kappa:lambda:mu\ndog\n" "" ""
|
||||
testcmd "-c -b" "-c -39 abc.txt" \
|
||||
"one:two:three:four:five:six:seven\nalpha:beta:gamma:delta:epsilon:zeta:eta\nthe quick brown fox jumps over the lazy\n" \
|
||||
"" ""
|
||||
testing "-c a" "cut -c 40 abc.txt" "\n:\n \n" "" ""
|
||||
testing "-c a,b-c,d" "cut -c 3,5-7,10 abc.txt" "etwoh\npa:ba\nequi \n" "" ""
|
||||
toyonly testing "-c japan.txt" 'cut -c 3-6,9-12 "$FILES/utf8/japan.txt"' \
|
||||
testcmd "-c a" "-c 40 abc.txt" "\n:\n \n" "" ""
|
||||
testcmd "-c a,b-c,d" "-c 3,5-7,10 abc.txt" "etwoh\npa:ba\nequi \n" "" ""
|
||||
toyonly testcmd "-c japan.txt" '-c 3-6,9-12 "$FILES/utf8/japan.txt"' \
|
||||
"ガラスをられます\n" "" ""
|
||||
|
||||
toyonly testcmd "-C test1.txt" '-C -1 "$FILES/utf8/test1.txt"' "l̴̗̞̠\n" "" ""
|
||||
|
||||
# substitute for awk
|
||||
toyonly testcmd "-DF" "-DF 2,7,5" \
|
||||
"said and your\nare\nis demand. supply\nforecast :\nyou you better,\n\nEm: Took hate\n" "" \
|
||||
@@ -44,24 +45,26 @@ Weather forecast for tonight : dark.
|
||||
Apple: you can buy better, but you can't pay more.
|
||||
Subcalifragilisticexpialidocious.
|
||||
Auntie Em: Hate you, hate Kansas. Took the dog. Dorothy."
|
||||
toyonly testcmd "-DF 2" "-DF 7,1,3-6,2-5" \
|
||||
"seven one three four five six two three four five\n" "" \
|
||||
"one two three four five six seven eight nine\n"
|
||||
|
||||
testcmd "empty field" "-d ':' -f 1-3" "a::b\n" "" "a::b\n"
|
||||
testcmd "empty field 2" "-d ':' -f 3-5" "b::c\n" "" "a::b::c:d\n"
|
||||
|
||||
testing "-f a-" "cut -d ':' -f 5- abc.txt" "five:six:seven\nepsilon:zeta:eta:theta:iota:kappa:lambda:mu\nthe quick brown fox jumps over the lazy dog\n" "" ""
|
||||
testcmd "-f a-" "-d ':' -f 5- abc.txt" "five:six:seven\nepsilon:zeta:eta:theta:iota:kappa:lambda:mu\nthe quick brown fox jumps over the lazy dog\n" "" ""
|
||||
|
||||
testing "show whole line with no delim" "cut -d ' ' -f 3 abc.txt" \
|
||||
testcmd "show whole line with no delim" "-d ' ' -f 3 abc.txt" \
|
||||
"one:two:three:four:five:six:seven\nalpha:beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu\nbrown\n" "" ""
|
||||
|
||||
testing "with echo, -c (a-b)" "echo 'ref_categorie=test' | cut -c 1-15 " "ref_categorie=t\n" "" ""
|
||||
testing "with echo, -c (a)" "echo 'ref_categorie=test' | cut -c 14" "=\n" "" ""
|
||||
testcmd "-c (a-b)" "-c 1-15 " "ref_categorie=t\n" "" "ref_categorie=test\n"
|
||||
testcmd "-c (a)" "-c 14" "=\n" "" "ref_categorie=test\n"
|
||||
|
||||
# Modifying abc.txt data as per new testcase
|
||||
echo "abcdefghijklmnopqrstuvwxyz" >abc.txt
|
||||
|
||||
testing "with -c (a,b,c)" "cut -c 4,5,20 abc.txt" "det\n" "" ""
|
||||
|
||||
testing "with -b (a,b,c)" "cut -b 4,5,20 abc.txt" "det\n" "" ""
|
||||
testcmd "-c (a,b,c)" "-c 4,5,20 abc.txt" "det\n" "" ""
|
||||
testcmd "-b (a,b,c)" "-b 4,5,20 abc.txt" "det\n" "" ""
|
||||
|
||||
# Modifying abc.txt data as per testcase
|
||||
echo "406378:Sales:Itorre:Jan
|
||||
@@ -69,13 +72,17 @@ echo "406378:Sales:Itorre:Jan
|
||||
636496:Research:Ancholie:Mel
|
||||
396082:Sales:Jucacion:Ed" >abc.txt
|
||||
|
||||
testing "with -d -f(:) -s" "cut -d: -f3 -s abc.txt" "Itorre\nNasium\nAncholie\nJucacion\n" "" ""
|
||||
testcmd "-d -f(:) -s" "-d: -f3 -s abc.txt" "Itorre\nNasium\nAncholie\nJucacion\n" "" ""
|
||||
testcmd "-d -f( ) -s" "-d' ' -f3 -s abc.txt && echo yes" "yes\n" "" ""
|
||||
testcmd "-d -f(a) -s" "-da -f3 -s abc.txt" "n\nsium:Jim\n\ncion:Ed\n" "" ""
|
||||
testcmd "-d -f(a) -s -n" "-da -f3 -s -n abc.txt" "n\nsium:Jim\n\ncion:Ed\n" "" ""
|
||||
|
||||
testing "with -d -f( ) -s" "cut -d' ' -f3 -s abc.txt && echo yes" "yes\n" "" ""
|
||||
# Feature posix documents but nobody bothers to implement
|
||||
toyonly testcmd "-nb" '-nb 8-17 "$FILES/utf8/japan.txt"' "ガラス\n" "" ""
|
||||
|
||||
testing "with -d -f(a) -s" "cut -da -f3 -s abc.txt" "n\nsium:Jim\n\ncion:Ed\n" "" ""
|
||||
|
||||
testing "with -d -f(a) -s -n" "cut -da -f3 -s -n abc.txt" "n\nsium:Jim\n\ncion:Ed\n" "" ""
|
||||
# Feature that is, as far as I can tell, totally undocumented?
|
||||
testcmd "-d newline" "-d \$'\n' -f 2-3,5" "two\nthree\nfive\n" "" \
|
||||
'one\ntwo\nthree\nfour\nfive\nsix\seven\n'
|
||||
|
||||
# Removing abc.txt file for cleanup purpose
|
||||
rm abc.txt
|
||||
|
||||
+48
-2
@@ -7,6 +7,10 @@
|
||||
# Use a consistent TZ for these tests, but not GMT/UTC because that
|
||||
# makes mistakes harder to spot.
|
||||
tz=Europe/Berlin
|
||||
this_year=$(TZ=$tz date +%Y)
|
||||
|
||||
# Use a consistent locale too.
|
||||
export LANG=C
|
||||
|
||||
# Unix date parsing.
|
||||
testing "-d @0" "TZ=$tz date -d @0" "Thu Jan 1 01:00:00 CET 1970\n" "" ""
|
||||
@@ -16,7 +20,7 @@ testing "-d @0x123 invalid" "TZ=$tz date -d @0x123 2>/dev/null || echo expected
|
||||
# All toyonly because coreutils rejects POSIX format dates supplied to -d.
|
||||
# These expected values are from running on the host without -d (not as root!).
|
||||
toyonly testing "-d MMDDhhmm" \
|
||||
"TZ=$tz date -d 06021234" "Sun Jun 2 12:34:00 CEST $(date +%Y)\n" "" ""
|
||||
"TZ=$tz date -d 06021234 +'%F %T'" "$this_year-06-02 12:34:00\n" "" ""
|
||||
toyonly testing "-d MMDDhhmmYY.SS" \
|
||||
"TZ=$tz date -d 1110143115.30" "Tue Nov 10 14:31:30 CET 2015\n" "" ""
|
||||
# busybox thinks this is the year 603 (ISO time 0602-12-34 19:82 with out of range fields normalized).
|
||||
@@ -35,7 +39,6 @@ testing "Unix time missing @" "TZ=$tz date 1438053157 2>/dev/null || echo no" \
|
||||
"no\n" "" ""
|
||||
|
||||
# Test just hour and minute (accepted by coreutils and busybox, presumably for setting the time).
|
||||
this_year=$(date +%Y)
|
||||
testing "-d 12:34" 'TZ=UTC date -d 12:34 | grep -q " 12:34:00 UTC $this_year" && echo OK' "OK\n" "" ""
|
||||
testing "-d 12:34:56" 'TZ=UTC date -d 12:34:56 | grep -q " 12:34:56 UTC $this_year" && echo OK' "OK\n" "" ""
|
||||
|
||||
@@ -50,7 +53,50 @@ testing "trailing %" "touch -d 2012-01-23T12:34:56.123456789 f && date -r f +%Y%
|
||||
testing "just %" "touch -d 2012-01-23T12:34:56.123456789 f && date -r f +%" "%\n" "" ""
|
||||
rm -f f
|
||||
|
||||
# Test --iso...
|
||||
testing "-I" "touch -d 2012-01-23T12:34:56.123456789Z f && date -r f -u -I" \
|
||||
"2012-01-23\n" "" ""
|
||||
testing "-Id" "touch -d 2012-01-23T12:34:56.123456789Z f && date -r f -u -Id" \
|
||||
"2012-01-23\n" "" ""
|
||||
testing "-Ih" "touch -d 2012-01-23T12:34:56.123456789Z f && date -r f -u -Ih" \
|
||||
"2012-01-23T12+00:00\n" "" ""
|
||||
testing "-Im" "touch -d 2012-01-23T12:34:56.123456789Z f && date -r f -u -Im" \
|
||||
"2012-01-23T12:34+00:00\n" "" ""
|
||||
testing "-Is" "touch -d 2012-01-23T12:34:56.123456789Z f && date -r f -u -Is" \
|
||||
"2012-01-23T12:34:56+00:00\n" "" ""
|
||||
testing "-In" "touch -d 2012-01-23T12:34:56.123456789Z f && date -r f -u -In" \
|
||||
"2012-01-23T12:34:56,123456789+00:00\n" "" ""
|
||||
rm -f f
|
||||
|
||||
# Test embedded TZ to take a date in one time zone and display it in another.
|
||||
testing "TZ=" "TZ='America/Los_Angeles' date -d 'TZ=\"Europe/Berlin\" 2018-01-04 08:00'" "Wed Jan 3 23:00:00 PST 2018\n" "" ""
|
||||
testing "TZ=" "TZ='America/Los_Angeles' date -d 'TZ=\"Europe/Berlin\" 2018-10-04 08:00'" "Wed Oct 3 23:00:00 PDT 2018\n" "" ""
|
||||
testing "TZ= @" "TZ='America/Los_Angeles' date -d 'TZ=\"GMT\" @1533427200'" "Sat Aug 4 17:00:00 PDT 2018\n" "" ""
|
||||
|
||||
# Test all supported UTC offset variants.
|
||||
testing "tz Z" \
|
||||
"date -u -d 2020-08-01T12:34:56Z" "Sat Aug 1 12:34:56 UTC 2020\n" "" ""
|
||||
testing "tz ' Z '" \
|
||||
"date -u -d '2020-08-01T12:34:56 Z '" "Sat Aug 1 12:34:56 UTC 2020\n" "" ""
|
||||
testing "tz -0800" \
|
||||
"date -u -d 2020-08-01T12:34:56-0800" "Sat Aug 1 20:34:56 UTC 2020\n" "" ""
|
||||
testing "tz +0800" \
|
||||
"date -u -d 2020-08-01T12:34:56+0800" "Sat Aug 1 04:34:56 UTC 2020\n" "" ""
|
||||
testing "tz +08:00" \
|
||||
"date -u -d 2020-08-01T12:34:56+08:00" "Sat Aug 1 04:34:56 UTC 2020\n" "" ""
|
||||
testing "tz +8" \
|
||||
"date -u -d 2020-08-01T12:34:56+8" "Sat Aug 1 04:34:56 UTC 2020\n" "" ""
|
||||
testing "tz +08" \
|
||||
"date -u -d 2020-08-01T12:34:56+08" "Sat Aug 1 04:34:56 UTC 2020\n" "" ""
|
||||
testing "tz +008" \
|
||||
"date -u -d 2020-08-01T12:34:56+008" "Sat Aug 1 12:26:56 UTC 2020\n" "" ""
|
||||
testing "tz + 8 : 8 " \
|
||||
"date -u -d '2020-08-01T12:34:56 + 8 : 8 '" "Sat Aug 1 04:26:56 UTC 2020\n"\
|
||||
"" ""
|
||||
|
||||
# Can we parse date's own output format?
|
||||
testing "round trip" 'TZ=$tz date -d "$(TZ=$tz date -d @1598476818)"' \
|
||||
"Wed Aug 26 23:20:18 CEST 2020\n" "" ""
|
||||
|
||||
toyonly testcmd "-D with -d" "-uD '%s' -d '1234567890'" \
|
||||
"Fri Feb 13 23:31:30 UTC 2009\n" "" ""
|
||||
|
||||
+79
-60
@@ -3,107 +3,126 @@
|
||||
# Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>
|
||||
# Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>
|
||||
|
||||
# TODO test skip= for seekable and nonseekable input.
|
||||
# TODO bs overrides ibs= and obs=, and disables block aggregation
|
||||
|
||||
[ -f testing.sh ] && . testing.sh
|
||||
|
||||
# 'dd' command, stderr prints redirecting to /dev/null
|
||||
opt="2>/dev/null"
|
||||
exec 2>/dev/null
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
# Test suffixed number parsing; `count` is representative.
|
||||
testing "count=2" "dd if=input count=2 ibs=1 $opt" "hi" "high\n" ""
|
||||
testing "count= 2" "dd if=input 'count= 2' ibs=1 $opt" "hi" "high\n" ""
|
||||
toyonly testing "count=0x2" "dd if=input 'count=0x2' ibs=1 $opt" "hi" \
|
||||
"high\n" ""
|
||||
testing "count=-2" "dd if=input 'count=-2' ibs=1 2>/dev/null || echo errored" "errored\n" "" ""
|
||||
testcmd "count=2" "if=input count=2 ibs=1" "hi" "high\n" ""
|
||||
testcmd "count= 2" "if=input 'count= 2' ibs=1" "hi" "high\n" ""
|
||||
toyonly testcmd "count=0x2" "if=input 'count=0x2' ibs=1" "hi" "high\n" ""
|
||||
testcmd 'posix 2x3x4' "if=input count=2x3x4 ibs=1" \
|
||||
'abcdefghijklmnopqrstuvwx' 'abcdefghijklmnopqrstuvwxyz' ''
|
||||
testcmd "count=-2" "if=input 'count=-2' ibs=1 || echo errored" "errored\n" "" ""
|
||||
|
||||
testing "if=(file)" "dd if=input $opt" "I WANT\n" "I WANT\n" ""
|
||||
testing "of=(file)" "dd of=file $opt && cat file" "I WANT\n" "" "I WANT\n"
|
||||
testing "if=file of=file" "dd if=input of=foo $opt && cat foo && rm -f foo" \
|
||||
testcmd "if=(file)" "if=input" "I WANT\n" "I WANT\n" ""
|
||||
testcmd "of=(file)" "of=file && cat file" "I WANT\n" "" "I WANT\n"
|
||||
testcmd "if=file of=file" "if=input of=foo && cat foo && rm -f foo" \
|
||||
"I WANT\n" "I WANT\n" ""
|
||||
testing "if=file | dd of=file" "dd if=input $opt | dd of=foo $opt &&
|
||||
cat foo && rm -f foo" "I WANT\n" "I WANT\n" ""
|
||||
testing "(stdout)" "dd $opt" "I WANT\n" "" "I WANT\n"
|
||||
testing "sync,noerror" \
|
||||
"dd if=input of=outFile seek=8860 bs=1M conv=sync,noerror $opt &&
|
||||
testcmd "if=file | dd of=file" "if=input | dd of=foo && cat foo && rm -f foo" \
|
||||
"I WANT\n" "I WANT\n" ""
|
||||
testcmd "(stdout)" '' "I WANT\n" "" "I WANT\n"
|
||||
testcmd "sync,noerror" \
|
||||
"if=input of=outFile seek=8860 bs=1M conv=sync,noerror &&
|
||||
stat -c \"%s\" outFile && rm -f outFile" "9291431936\n" "I WANT\n" ""
|
||||
testing "if=file of=(null)" \
|
||||
"dd if=input of=/dev/null $opt && echo 'yes'" "yes\n" "I WANT\n" ""
|
||||
testing "with if of bs" \
|
||||
"dd if=/dev/zero of=sda.txt bs=512 count=1 $opt &&
|
||||
testcmd "if=file of=(null)" "if=input of=/dev/null && echo 'yes'" "yes\n" \
|
||||
"I WANT\n" ""
|
||||
testcmd "with if of bs" \
|
||||
"if=/dev/zero of=sda.txt bs=512 count=1 &&
|
||||
stat -c '%s' sda.txt && rm -f sda.txt" "512\n" "" ""
|
||||
testing "with if of ibs obs" \
|
||||
"dd if=/dev/zero of=sda.txt ibs=512 obs=256 count=1 $opt &&
|
||||
testcmd "with if of ibs obs" \
|
||||
"if=/dev/zero of=sda.txt ibs=512 obs=256 count=1 &&
|
||||
stat -c '%s' sda.txt && rm -f sda.txt" "512\n" "" ""
|
||||
testing "with if of ibs obs count" \
|
||||
"dd if=/dev/zero of=sda.txt ibs=512 obs=256 count=3 $opt &&
|
||||
// TODO check block size of transactions
|
||||
testcmd "with if of ibs obs count" \
|
||||
"if=/dev/zero of=sda.txt ibs=512 obs=256 count=3 &&
|
||||
stat -c '%s' sda.txt && rm -f sda.txt" "1536\n" "" ""
|
||||
|
||||
ln -s input softlink
|
||||
testing "if=softlink" "dd if=softlink $opt" "I WANT\n" "I WANT\n" ""
|
||||
unlink softlink
|
||||
testcmd "if=softlink" "if=softlink" "I WANT\n" "I WANT\n" ""
|
||||
rm -f softlink
|
||||
|
||||
ln -s file softlink
|
||||
testing "if=file of=softlink" "dd if=input of=softlink $opt &&
|
||||
testcmd "if=file of=softlink" "if=input of=softlink &&
|
||||
[ -f file -a -L softlink ] && cat softlink" "I WANT\n" "I WANT\n" ""
|
||||
unlink softlink && rm -f file
|
||||
rm -f softlink file
|
||||
|
||||
testing "if=file of=file (same file)" "dd if=input of=input $opt &&
|
||||
testcmd "if=file of=file (same file)" "if=input of=input &&
|
||||
[ -f input ] && cat input && echo 'yes'" "yes\n" "I WANT\n" ""
|
||||
testing "same file notrunc" \
|
||||
"dd if=input of=input conv=notrunc $opt && cat input" \
|
||||
"I WANT\n" "I WANT\n" ""
|
||||
testcmd "same file notrunc" \
|
||||
"if=input of=input conv=notrunc && cat input" "I WANT\n" "I WANT\n" ""
|
||||
testcmd "seek truncate" \
|
||||
'of=input bs=3 count=2 seek=7 oflag=seek_bytes && cat input' \
|
||||
'1234567ABCDEF' '1234567890abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJK'
|
||||
testcmd "seek notrunc" \
|
||||
'of=input bs=3 count=2 seek=7 conv=notrunc oflag=seek_bytes && cat input' \
|
||||
'1234567ABCDEFdefghijklmnopqrstuvwxyz' '1234567890abcdefghijklmnopqrstuvwxyz'\
|
||||
'ABCDEFGHIJK'
|
||||
|
||||
testing "with ibs obs bs" "dd ibs=2 obs=5 bs=9 $opt" "I WANT\n" "" "I WANT\n"
|
||||
testing "with ibs obs bs if" "dd ibs=2 obs=5 bs=9 if=input $opt" \
|
||||
"I WANT\n" "I WANT\n" ""
|
||||
testcmd "with ibs obs bs" "ibs=2 obs=5 bs=9" "I WANT\n" "" "I WANT\n"
|
||||
testcmd "with ibs obs bs if" "ibs=2 obs=5 bs=9 if=input" "I WANT\n" "I WANT\n"\
|
||||
""
|
||||
|
||||
testing "with ibs obs count" "dd ibs=1 obs=1 count=1 $opt" "I" "" "I WANT\n"
|
||||
testing "with ibs obs count if" "dd ibs=1 obs=1 count=3 if=input $opt" \
|
||||
"I W" "I WANT\n" ""
|
||||
testcmd "with ibs obs count" "ibs=1 obs=1 count=1" "I" "" "I WANT\n"
|
||||
testcmd "with ibs obs count if" "ibs=1 obs=1 count=3 if=input" "I W" "I WANT\n"\
|
||||
""
|
||||
|
||||
testing "with count" "dd count=1 $opt" "I WANT\n" "" "I WANT\n"
|
||||
testing "with count if" "dd count=1 if=input $opt" "I WANT\n" "I WANT\n" ""
|
||||
testcmd "with count" "count=1" "I WANT\n" "" "I WANT\n"
|
||||
testcmd "with count if" "count=1 if=input" "I WANT\n" "I WANT\n" ""
|
||||
|
||||
testing "with skip" "dd skip=0 $opt" "I WANT\n" "" "I WANT\n"
|
||||
testing "with skip if" "dd skip=0 if=input $opt" "I WANT\n" "I WANT\n" ""
|
||||
testcmd "with skip" "skip=0" "I WANT\n" "" "I WANT\n"
|
||||
testcmd "with skip if" "skip=0 if=input" "I WANT\n" "I WANT\n" ""
|
||||
|
||||
testing "with seek" "dd seek=0 $opt" "I WANT\n" "" "I WANT\n"
|
||||
testing "with seek if" "dd seek=0 if=input $opt" "I WANT\n" "I WANT\n" ""
|
||||
testcmd "with seek" "seek=0" "I WANT\n" "" "I WANT\n"
|
||||
testcmd "with seek if" "seek=0 if=input" "I WANT\n" "I WANT\n" ""
|
||||
|
||||
# Testing only 'notrunc', 'noerror', 'fsync', 'sync'
|
||||
|
||||
testing "conv=notrunc" "dd conv=notrunc $opt" "I WANT\n" "" "I WANT\n"
|
||||
testing "conv=notrunc with IF" "dd conv=notrunc if=input $opt" "I WANT\n" \
|
||||
testcmd "conv=notrunc" "conv=notrunc" "I WANT\n" "" "I WANT\n"
|
||||
testcmd "conv=notrunc with IF" "conv=notrunc if=input" "I WANT\n" \
|
||||
"I WANT\n" ""
|
||||
|
||||
testing "conv=noerror" "dd conv=noerror $opt" "I WANT\n" "" "I WANT\n"
|
||||
testing "conv=noerror with IF" "dd conv=noerror if=input $opt" "I WANT\n" \
|
||||
testcmd "conv=noerror" "conv=noerror" "I WANT\n" "" "I WANT\n"
|
||||
testcmd "conv=noerror with IF" "conv=noerror if=input" "I WANT\n" \
|
||||
"I WANT\n" ""
|
||||
|
||||
testing "conv=fsync" "dd conv=fsync $opt" "I WANT\n" "" "I WANT\n"
|
||||
testing "conv=fsync with IF" "dd conv=fsync if=input $opt" "I WANT\n" \
|
||||
testcmd "conv=fsync" "conv=fsync" "I WANT\n" "" "I WANT\n"
|
||||
testcmd "conv=fsync with IF" "conv=fsync if=input" "I WANT\n" \
|
||||
"I WANT\n" ""
|
||||
|
||||
testing "conv=sync" "dd conv=sync $opt | head -n 1" "I WANT\n" "" "I WANT\n"
|
||||
testing "conv=sync with IF" "dd conv=sync if=input $opt | head -n 1" "I WANT\n" \
|
||||
testcmd "conv=sync" "conv=sync | head -n 1" "I WANT\n" "" "I WANT\n"
|
||||
testcmd "conv=sync with IF" "conv=sync if=input | head -n 1" "I WANT\n" \
|
||||
"I WANT\n" ""
|
||||
|
||||
# status=noxfer|none
|
||||
testing "status=noxfer" "dd if=input status=noxfer ibs=1 2>&1" "input\n6+0 records in\n0+1 records out\n" "input\n" ""
|
||||
testing "status=none" "dd if=input status=none ibs=1 2>&1" "input\n" "input\n" ""
|
||||
testcmd "status=noxfer" "if=input status=noxfer ibs=1 2>&1" \
|
||||
"input\n6+0 records in\n0+1 records out\n" "input\n" ""
|
||||
testcmd "status=none" "if=input status=none ibs=1 2>&1" \
|
||||
"input\n" "input\n" ""
|
||||
|
||||
testing "seek stdout" "yes 2> /dev/null | dd bs=8 seek=2 count=1 > out 2> /dev/null && xxd -p out" \
|
||||
testing "seek stdout" "yes | dd bs=8 seek=2 count=1 > out && xxd -p out" \
|
||||
"00000000000000000000000000000000790a790a790a790a\n" "" ""
|
||||
|
||||
# Duplicated options are fine.
|
||||
testing "conv=sync,sync" "dd conv=sync,sync $opt | head -n 1" "I WANT\n" "" "I WANT\n"
|
||||
testcmd "conv=sync,sync" "conv=sync,sync | head -n 1" "I WANT\n" "" "I WANT\n"
|
||||
|
||||
# _bytes options
|
||||
testing "iflag=count_bytes" \
|
||||
"dd if=input count=2 ibs=4096 iflag=count_bytes $opt" "hi" "high" ""
|
||||
testing "iflag=skip_bytes" \
|
||||
"dd if=input skip=2 ibs=4096 iflag=skip_bytes $opt" "gh" "high" ""
|
||||
testing "oflag=seek_bytes" \
|
||||
"dd if=input of=output seek=2 obs=4096 oflag=seek_bytes status=none && \
|
||||
testcmd "iflag=count_bytes" "if=input count=2 ibs=4096 iflag=count_bytes" "hi"\
|
||||
"high" ""
|
||||
testcmd "iflag=skip_bytes" "if=input skip=2 ibs=4096 iflag=skip_bytes" "gh" \
|
||||
"high" ""
|
||||
testcmd "oflag=seek_bytes" \
|
||||
"if=input of=output seek=2 obs=4096 oflag=seek_bytes status=none && \
|
||||
xxd -p output" "000030313233\n" "0123" ""
|
||||
|
||||
# The sleep decouples input blocks to force short reads for conv=sync to pad
|
||||
testing 'sync padding ticks down count' \
|
||||
'for i in one two three four five "$(seq 1 100)"
|
||||
do echo "$i"; sleep .1; done | dd bs=1024 count=5 conv=sync | sha1sum' \
|
||||
'02dcf1f497ccbe940f57818dfc34f2d0def8b3f9 -\n' '' ''
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
echo "xxxxxxxxhello, world!" > foo
|
||||
testcmd 'read default (4)' '-f foo 0x8' '0x6c6c6568\n' '' ''
|
||||
testcmd 'read 1' '-f foo 0x8 1' '0x68\n' '' ''
|
||||
testcmd 'read 2' '-f foo 0x8 2' '0x6568\n' '' ''
|
||||
testcmd 'read 4' '-f foo 0x8 4' '0x6c6c6568\n' '' ''
|
||||
testcmd 'read 8' '-f foo 0x8 8' '0x77202c6f6c6c6568\n' '' ''
|
||||
|
||||
testcmd 'read --no-mmap default (4)' '--no-mmap -f foo 0x8' '0x6c6c6568\n' '' ''
|
||||
testcmd 'read --no-mmap 1' '--no-mmap -f foo 0x8 1' '0x68\n' '' ''
|
||||
testcmd 'read --no-mmap 2' '--no-mmap -f foo 0x8 2' '0x6568\n' '' ''
|
||||
testcmd 'read --no-mmap 4' '--no-mmap -f foo 0x8 4' '0x6c6c6568\n' '' ''
|
||||
testcmd 'read --no-mmap 8' '--no-mmap -f foo 0x8 8' '0x77202c6f6c6c6568\n' '' ''
|
||||
|
||||
head -c 32 /dev/zero > foo
|
||||
NOSPACE=1 testcmd 'write 1' '-f foo 0x8 1 0x12 && od -t x foo' '0000000 00000000 00000000 00000012 00000000\n0000020 00000000 00000000 00000000 00000000\n0000040\n' '' ''
|
||||
NOSPACE=1 testcmd 'write 2' '-f foo 0x8 2 0x1234 && od -t x foo' '0000000 00000000 00000000 00001234 00000000\n0000020 00000000 00000000 00000000 00000000\n0000040\n' '' ''
|
||||
NOSPACE=1 testcmd 'write 4' '-f foo 0x8 4 0x12345678 && od -t x foo' '0000000 00000000 00000000 12345678 00000000\n0000020 00000000 00000000 00000000 00000000\n0000040\n' '' ''
|
||||
NOSPACE=1 testcmd 'write 8' '-f foo 0x8 8 0x12345678abcdef01 && od -t x foo' '0000000 00000000 00000000 abcdef01 12345678\n0000020 00000000 00000000 00000000 00000000\n0000040\n' '' ''
|
||||
|
||||
head -c 32 /dev/zero > foo
|
||||
NOSPACE=1 testcmd 'write --no-mmap 1' '--no-mmap -f foo 0x8 1 0x12 && od -t x foo' '0000000 00000000 00000000 00000012 00000000\n0000020 00000000 00000000 00000000 00000000\n0000040\n' '' ''
|
||||
NOSPACE=1 testcmd 'write --no-mmap 2' '--no-mmap -f foo 0x8 2 0x1234 && od -t x foo' '0000000 00000000 00000000 00001234 00000000\n0000020 00000000 00000000 00000000 00000000\n0000040\n' '' ''
|
||||
NOSPACE=1 testcmd 'write --no-mmap 4' '--no-mmap -f foo 0x8 4 0x12345678 && od -t x foo' '0000000 00000000 00000000 12345678 00000000\n0000020 00000000 00000000 00000000 00000000\n0000040\n' '' ''
|
||||
NOSPACE=1 testcmd 'write --no-mmap 8' '--no-mmap -f foo 0x8 8 0x12345678abcdef01 && od -t x foo' '0000000 00000000 00000000 abcdef01 12345678\n0000020 00000000 00000000 00000000 00000000\n0000040\n' '' ''
|
||||
|
||||
head -c 32 /dev/zero > foo
|
||||
NOSPACE=1 testcmd 'write 1 multiple' '-f foo 0x8 1 0x12 0x34 && od -t x foo' '0000000 00000000 00000000 00003412 00000000\n0000020 00000000 00000000 00000000 00000000\n0000040\n' '' ''
|
||||
NOSPACE=1 testcmd 'write 2 multiple' '-f foo 0x8 2 0x1234 0x5678 && od -t x foo' '0000000 00000000 00000000 56781234 00000000\n0000020 00000000 00000000 00000000 00000000\n0000040\n' '' ''
|
||||
NOSPACE=1 testcmd 'write 4 multiple' '-f foo 0x8 4 0x12345678 0xabcdef01 && od -t x foo' '0000000 00000000 00000000 12345678 abcdef01\n0000020 00000000 00000000 00000000 00000000\n0000040\n' '' ''
|
||||
NOSPACE=1 testcmd 'write 8 multiple' '-f foo 0x8 8 0x12345678abcdef01 0x1122334455667788 && od -t x foo' '0000000 00000000 00000000 abcdef01 12345678\n0000020 55667788 11223344 00000000 00000000\n0000040\n' '' ''
|
||||
|
||||
head -c 32 /dev/zero > foo
|
||||
NOSPACE=1 testcmd 'write --no-mmap 1 multiple' '--no-mmap -f foo 0x8 1 0x12 0x34 && od -t x foo' '0000000 00000000 00000000 00003412 00000000\n0000020 00000000 00000000 00000000 00000000\n0000040\n' '' ''
|
||||
NOSPACE=1 testcmd 'write --no-mmap 2 multiple' '--no-mmap -f foo 0x8 2 0x1234 0x5678 && od -t x foo' '0000000 00000000 00000000 56781234 00000000\n0000020 00000000 00000000 00000000 00000000\n0000040\n' '' ''
|
||||
NOSPACE=1 testcmd 'write --no-mmap 4 multiple' '--no-mmap -f foo 0x8 4 0x12345678 0xabcdef01 && od -t x foo' '0000000 00000000 00000000 12345678 abcdef01\n0000020 00000000 00000000 00000000 00000000\n0000040\n' '' ''
|
||||
NOSPACE=1 testcmd 'write --no-mmap 8 multiple' '--no-mmap -f foo 0x8 8 0x12345678abcdef01 0x1122334455667788 && od -t x foo' '0000000 00000000 00000000 abcdef01 12345678\n0000020 55667788 11223344 00000000 00000000\n0000040\n' '' ''
|
||||
+115
-17
@@ -5,36 +5,134 @@
|
||||
seq 10 > left
|
||||
seq 11 > right
|
||||
|
||||
testing "unknown argument" 'diff --oops left right 2>/dev/null ; echo $?' "2\n" "" ""
|
||||
testing "missing" 'diff missing1 missing2 2>/dev/null ; echo $?' "2\n" "" ""
|
||||
testcmd "unknown argument" '--oops left right 2>/dev/null ; echo $?' "2\n" "" ""
|
||||
testcmd "missing" 'missing1 missing2 2>/dev/null ; echo $?' "2\n" "" ""
|
||||
|
||||
testing "- -" 'diff - - ; echo $?' "0\n" "" "whatever"
|
||||
testcmd "- -" '- - ; echo $?' "0\n" "" "whatever"
|
||||
|
||||
expected='--- lll
|
||||
testcmd "simple" "-u -L lll -L rrr left right" '--- lll
|
||||
+++ rrr
|
||||
@@ -8,3 +8,4 @@
|
||||
8
|
||||
9
|
||||
10
|
||||
+11
|
||||
'
|
||||
# Hm this only gives unified diffs?
|
||||
testing "simple" "diff -L lll -L rrr left right" "$expected" "" ""
|
||||
' "" ""
|
||||
rm left right
|
||||
|
||||
|
||||
expected='--- tree1/file
|
||||
+++ tree2/file
|
||||
@@ -1 +1 @@
|
||||
-foo
|
||||
+food
|
||||
'
|
||||
mkdir -p tree1 tree2
|
||||
echo foo > tree1/file
|
||||
echo food > tree2/file
|
||||
|
||||
testing "-r" "diff -r -L tree1/file -L tree2/file tree1 tree2 |tee out" "$expected" "" ""
|
||||
# Debian's diff gratuitously echoes its command line with -r. No idea why.
|
||||
testcmd "-r" "-u -r -L tree1/file -L tree2/file tree1 tree2 | grep -v ^diff" \
|
||||
'--- tree1/file
|
||||
+++ tree2/file
|
||||
@@ -1 +1 @@
|
||||
-foo
|
||||
+food
|
||||
' "" ""
|
||||
rm tree1/file tree2/file
|
||||
rmdir tree1 tree2
|
||||
|
||||
echo -e "hello\r\nworld\r\n"> a
|
||||
echo -e "hello\nworld\n"> b
|
||||
testing "--strip-trailing-cr off" "diff -q a b" "Files a and b differ\n" "" ""
|
||||
testing "--strip-trailing-cr on" "diff -u --strip-trailing-cr a b" "" "" ""
|
||||
testcmd "--strip-trailing-cr off" "-q a b" "Files a and b differ\n" "" ""
|
||||
testcmd "--strip-trailing-cr on" '-u --strip-trailing-cr a b; echo $?' \
|
||||
"0\n" "" ""
|
||||
|
||||
echo -e "1\n2" > aa
|
||||
echo -e "1\n3" > bb
|
||||
testcmd "line format" "--unchanged-line-format=U%l --old-line-format=D%l --new-line-format=A%l aa bb" "U1D2A3" "" ""
|
||||
testcmd "line format empty" "--unchanged-line-format= --old-line-format=D%l --new-line-format=A%l aa bb" "D2A3" "" ""
|
||||
|
||||
ln -s aa cc
|
||||
testcmd "follow symlink" "-q -L aa -L cc aa cc" "" "" ""
|
||||
testcmd "no follow symlink" "-q --no-dereference -L aa -L cc aa cc" "File aa is a regular file while file cc is a symbolic link\n" "" ""
|
||||
ln -s ./aa dd
|
||||
testcmd "symlink differs" "-q -L cc -L dd cc dd" "" "" ""
|
||||
testcmd "symlink differs no follow" "-q --no-dereference -L cc -L dd cc dd" "Symbolic links cc and dd differ\n" "" ""
|
||||
rm aa bb cc dd
|
||||
|
||||
mkfifo fifo1
|
||||
mkfifo fifo2
|
||||
echo -e "1\n2" > fifo1&
|
||||
echo -e "1\n3" > fifo2&
|
||||
testcmd "fifos" "-u -L fifo1 -L fifo2 fifo1 fifo2" '--- fifo1
|
||||
+++ fifo2
|
||||
@@ -1,2 +1,2 @@
|
||||
1
|
||||
-2
|
||||
+3
|
||||
' "" ""
|
||||
|
||||
echo -e "1\n2" > fifo1&
|
||||
echo -e "1\n3" > file1
|
||||
ln -s file1 link1
|
||||
|
||||
testcmd "fifo symlinked file" "-u -L fifo1 -L link1 fifo1 link1" '--- fifo1
|
||||
+++ link1
|
||||
@@ -1,2 +1,2 @@
|
||||
1
|
||||
-2
|
||||
+3
|
||||
' "" ""
|
||||
|
||||
testcmd "fifo symlinked file no follow" "-u -L fifo1 -L link1 fifo1 link1 --no-dereference" "File fifo1 is a fifo while file link1 is a symbolic link\n" "" ""
|
||||
testcmd "symlinked file stdin no follow" "-u -L link1 -L - link1 - --no-dereference" "File link1 is a symbolic link while file - is a fifo\n" "" "test"
|
||||
rm fifo1 fifo2 link1 file1
|
||||
|
||||
echo -e 'int bar() {
|
||||
}
|
||||
|
||||
int foo() {
|
||||
}
|
||||
|
||||
int baz() {
|
||||
1
|
||||
{2
|
||||
3
|
||||
4
|
||||
foo
|
||||
}
|
||||
'> a
|
||||
echo -e 'int barbar() {
|
||||
}
|
||||
|
||||
int foo() {
|
||||
}
|
||||
|
||||
int baz() {
|
||||
1a
|
||||
{2
|
||||
3
|
||||
4
|
||||
bar
|
||||
}
|
||||
'> b
|
||||
testcmd 'show function' "--show-function-line=' {$' -U1 -L lll -L rrr a b" \
|
||||
'--- lll
|
||||
+++ rrr
|
||||
@@ -1,2 +1,2 @@
|
||||
-int bar() {
|
||||
+int barbar() {
|
||||
}
|
||||
@@ -7,3 +7,3 @@ int foo() {
|
||||
int baz() {
|
||||
- 1
|
||||
+ 1a
|
||||
{2
|
||||
@@ -11,3 +11,3 @@ int baz() {
|
||||
4
|
||||
- foo
|
||||
+ bar
|
||||
}
|
||||
' \
|
||||
'' ''
|
||||
rm a b
|
||||
|
||||
seq 1 100000 > one
|
||||
seq 1 4 100000 > two
|
||||
testcmd 'big hunk' '-u --label nope --label nope one two' \
|
||||
"$(echo -e '--- nope\n+++ nope\n@@ -1,100000 +1,25000 @@'; for i in $(seq 1 100000); do (((i-1)&3)) && echo "-$i" || echo " $i"; done)\n" '' ''
|
||||
rm one two
|
||||
|
||||
+8
-1
@@ -11,6 +11,14 @@ if [ "$(stat --format %C . 2>/dev/null)" != "?" ]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
# darwin stores empty directories in the inode itself, making all the numbers
|
||||
# in the tests below 0. (TODO this is not the right fix.)
|
||||
if [ "$(uname)" == "Darwin" ]; then
|
||||
echo "$SHOWSKIP: du (Darwin stores empty directories in inode)"
|
||||
return 2>/dev/null
|
||||
exit
|
||||
fi
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
# we only test with -k since getting POSIX version is variable
|
||||
@@ -37,4 +45,3 @@ testing "-LH does not follow unspecified symlinks" "du -ksLH du_test" "8\tdu_tes
|
||||
testing "-H follows specified symlinks" "du -ksH du_test/xyz" "8\tdu_test/xyz\n" "" ""
|
||||
|
||||
rm -rf du_test du_2
|
||||
|
||||
|
||||
+7
-1
@@ -9,7 +9,7 @@
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
testcmd "echo" "&& echo yes" "\nyes\n" "" ""
|
||||
testcmd "echo" "&& $C yes" "\nyes\n" "" ""
|
||||
testcmd "1 2 3" "one two three" "one two three\n" "" ""
|
||||
testcmd "with spaces" "'one two three'" \
|
||||
"one two three\n" "" ""
|
||||
@@ -45,3 +45,9 @@ testcmd "-e \p" "-e '\\p'" "\\p\n" "" ""
|
||||
# http://austingroupbugs.net/view.php?id=1222 added -E
|
||||
testcmd "-En" "-En 'one\ntwo'" 'one\\ntwo' "" ""
|
||||
testcmd "-eE" "-eE '\e'" '\\e\n' "" ""
|
||||
|
||||
# This is how bash's built-in echo behaves, but not how /bin/echo behaves.
|
||||
toyonly testcmd "" "-e 'a\x123\ufb3bbc' | od -An -tx1" \
|
||||
" 61 12 33 ef ac bb 62 63 0a\n" "" ""
|
||||
|
||||
testcmd "trailing nul" "-ne 'a\0b\0' | od -An -tx1" " 61 00 62 00\n" "" ""
|
||||
|
||||
+4
-3
@@ -11,10 +11,11 @@ FILTER="| egrep '^(WALRUS|BANANA|LETTERS)=' | sort"
|
||||
testcmd "read" "$FILTER" "BANANA=hello\nLETTERS=\nWALRUS=42\n" "" ""
|
||||
testcmd "-u" "-u BANANA $FILTER" "LETTERS=\nWALRUS=42\n" "" ""
|
||||
testcmd "-uu" "-u LETTERS -u WALRUS $FILTER" "BANANA=hello\n" "" ""
|
||||
testcmd "-i" "-i env" "" "" ""
|
||||
testcmd "-i =" "-i one=two three=four env | sort" \
|
||||
testcmd "-i uses old \$PATH" "-i echo hello" "hello\n" "" ""
|
||||
testcmd "-i env" "-i env" "" "" ""
|
||||
testcmd "-i =" "-i one=two three=four $C | sort" \
|
||||
"one=two\nthree=four\n" "" ""
|
||||
testcmd "-0" "-i five=six seven=eight env -0 | sort -z" "five=six\0seven=eight\0" "" ""
|
||||
testcmd "-0" "-i five=six seven=eight $C -0 | sort -z" "five=six\0seven=eight\0" "" ""
|
||||
unset WALRUS BANANA LETTERS FILTER
|
||||
|
||||
testcmd "early fail" '--oops 2> /dev/null ; echo $?' "125\n" "" ""
|
||||
|
||||
+3
-4
@@ -18,6 +18,7 @@ testing "% * same priority" "expr 3 % 2 \* 4" "4\n" "" ""
|
||||
testing "* % same priority" "expr 3 \* 2 % 4" "2\n" "" ""
|
||||
testing "= > same priority" "expr 0 = 2 \> 3" "0\n" "" ""
|
||||
testing "> = same priority" "expr 3 \> 2 = 1" "1\n" "" ""
|
||||
testing "64 bit comparison" "expr 100000000000 \> 1" "1\n" "" ""
|
||||
|
||||
testing "00 | 1" "expr 00 \| 1" "1\n" "" ""
|
||||
testing "-0 | 1" "expr -0 \| 2" "2\n" "" ""
|
||||
@@ -31,8 +32,7 @@ testing "regex no match" "expr ab21xx : x" "0\n" "" ""
|
||||
testing "long str" "expr abcdefghijklmnopqrstuvwxyz : '\(.*\)' = a" "0\n" "" ""
|
||||
|
||||
# result of ':' regex match can subsequently be used for arithmetic
|
||||
testing "string becomes integer" "expr ab21xx : '[^0-9]*\([0-9]*\)' + 3" \
|
||||
"24\n" "" ""
|
||||
testing "str becomes int" "expr ab21xx : '[^0-9]*\([0-9]*\)' + 3" "24\n" "" ""
|
||||
|
||||
testing "integer comparison" "expr -3 \< -2" "1\n" "" ""
|
||||
testing "string comparison" "expr -3 \< -2s" "0\n" "" ""
|
||||
@@ -44,8 +44,7 @@ testing "parens around literal" "expr \( a \)" "a\n" "" ""
|
||||
|
||||
testing "exit code when true" "expr a; echo \$?" "a\n0\n" "" ""
|
||||
testing "exit code when false" "expr 0; echo \$?" "0\n1\n" "" ""
|
||||
testing "exit code with syntax error" "expr \( 2>/dev/null; echo \$?" \
|
||||
"2\n" "" ""
|
||||
testing "exit code with syntax err" "expr \( 2>/dev/null; echo \$?" "2\n" "" ""
|
||||
testing "exit code when evaluating to 0" "expr -1 + 1; echo \$?" "0\n1\n" "" ""
|
||||
|
||||
# BUG: segfaults because '3' is coerced to integer and regexc gets NULL
|
||||
|
||||
+8
-3
@@ -4,9 +4,9 @@
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
testing "-32" "factor -32" "-32: -1 2 2 2 2 2\n" "" ""
|
||||
testing "0" "factor 0" "0: 0\n" "" ""
|
||||
testing "1" "factor 1" "1: 1\n" "" ""
|
||||
toyonly testing "-32" "factor -32" "-32: -1 2 2 2 2 2\n" "" ""
|
||||
toyonly testing "0" "factor 0" "0: 0\n" "" ""
|
||||
toyonly testing "1" "factor 1" "1: 1\n" "" ""
|
||||
testing "2" "factor 2" "2: 2\n" "" ""
|
||||
testing "3" "factor 3" "3: 3\n" "" ""
|
||||
testing "4" "factor 4" "4: 2 2\n" "" ""
|
||||
@@ -20,3 +20,8 @@ testing "10000000019" "factor 10000000019" \
|
||||
testing "3 6 from stdin" "factor" "3: 3\n6: 2 3\n" "" "3 6"
|
||||
testing "stdin newline" "factor" "3: 3\n6: 2 3\n" "" "3\n6\n"
|
||||
|
||||
toyonly testing "-h" "factor -h $(((1<<63)-26))" \
|
||||
"9223372036854775782: 2 3^4 17 23 319279 456065899\n" "" ""
|
||||
toyonly testing "-x" "factor -x $(((1<<63)-20))" \
|
||||
"7fffffffffffffec: 2 2 3 283 43f2ba978e663\n" "" ""
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
rm -f foo
|
||||
testcmd 'simple' '-l 123 foo && stat -c %s foo' '123\n' '' ''
|
||||
testcmd 'shorter' '-l 12 foo && stat -c %s foo' '123\n' '' ''
|
||||
testcmd 'longer' '-o 200 -l 12 foo && stat -c %s foo' '212\n' '' ''
|
||||
+103
-37
@@ -4,57 +4,123 @@
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
touch empty
|
||||
echo "#!/bin/bash" > bash.script
|
||||
echo "#! /bin/bash" > bash.script2
|
||||
echo "#! /usr/bin/env python" > env.python.script
|
||||
echo "Hello, world!" > ascii
|
||||
echo "6465780a3033350038ca8f6ce910f94e" | xxd -r -p > android.dex
|
||||
ln -s $FILES/java.class symlink
|
||||
test_line() {
|
||||
ONE="$1"; shift; TWO="\"$FILES\"/$1 | sed 's/^.*: //'"; shift
|
||||
testcmd "$ONE" "$TWO" "$@"
|
||||
}
|
||||
|
||||
ln -s "$FILES"/java.class symlink
|
||||
LINK=$(readlink symlink)
|
||||
ln -s $FILES/java.klass dangler
|
||||
ln -s "$FILES"/java.klass dangler
|
||||
BROKEN=$(readlink dangler)
|
||||
|
||||
mkdir directory
|
||||
testing "directory" "file ." ".: directory\n" "" ""
|
||||
rmdir directory
|
||||
touch empty
|
||||
testing "empty" "file empty" "empty: empty\n" "" ""
|
||||
testing "bash.script" "file bash.script" "bash.script: /bin/bash script\n" "" ""
|
||||
testing "bash.script with spaces" "file bash.script2" "bash.script2: /bin/bash script\n" "" ""
|
||||
testing "env python script" "file env.python.script" "env.python.script: python script\n" "" ""
|
||||
testing "ascii" "file ascii" "ascii: ASCII text\n" "" ""
|
||||
testing "utf-8" "file $FILES/utf8/japan.txt | sed 's|$FILES/||'" \
|
||||
"utf8/japan.txt: UTF-8 text\n" "" ""
|
||||
testing "java class" "file $FILES/java.class | sed 's|$FILES/||'" \
|
||||
"java.class: Java class file, version 53.0 (Java 1.9)\n" "" ""
|
||||
testing "tar file" "file $FILES/tar/tar.tar | sed 's|$FILES/||'" \
|
||||
"tar/tar.tar: POSIX tar archive (GNU)\n" "" ""
|
||||
testing "gzip data" "file $FILES/tar/tar.tgz | sed 's|$FILES/||'" \
|
||||
"tar/tar.tgz: gzip compressed data\n" "" ""
|
||||
testing "bzip2 data" "file $FILES/tar/tar.tbz2 | sed 's|$FILES/||'" \
|
||||
"tar/tar.tbz2: bzip2 compressed data, block size = 900k\n" "" ""
|
||||
testing "zip file" "file $FILES/zip/example.zip | sed 's|$FILES/||'" \
|
||||
"zip/example.zip: Zip archive data, requires at least v1.0 to extract\n" "" ""
|
||||
rm -f empty
|
||||
|
||||
testing "script" "file input | grep -o ' script'" " script\n" "#!/bin/bash\n" ""
|
||||
testing "script with spaces" "file input | grep -o ' script'" " script\n" \
|
||||
"#! /bin/bash\n" ""
|
||||
testing "env script" "file input | tr P p | egrep -o '(python|script)' | sort" \
|
||||
"python\nscript\n" "#! /usr/bin/env python\n" ""
|
||||
testing "ascii" "file input" "input: ASCII text\n" "Hello, world!\n" ""
|
||||
testing "utf-8" \
|
||||
"file \"$FILES\"/utf8/japan.txt | egrep -o 'UTF-8 text' | LANG=c sort" \
|
||||
"UTF-8 text\n" "" ""
|
||||
|
||||
# TODO each of these has multiple options we could test
|
||||
testing "java class" \
|
||||
"file \"$FILES\"/java.class | egrep -o '(Java class|version 53.0)'"\
|
||||
"Java class\nversion 53.0\n" "" ""
|
||||
|
||||
echo "cafebabe000000020100000700000003000040000000d9300000000e0100000c8000000200014000000098500000000e" | xxd -r -p > universal
|
||||
testcmd "mach-o universal" \
|
||||
"universal | egrep -o '(Mach-O|universal|x86_64|arm64)' | sort -u" \
|
||||
"Mach-O\narm64\nuniversal\nx86_64\n" "" ""
|
||||
rm universal
|
||||
|
||||
test_line "tar file" "tar/tar.tar" "POSIX tar archive (GNU)\n" "" ""
|
||||
testing "gzip data" "file \"$FILES\"/tar/tar.tgz | grep -o 'gzip compressed data'" \
|
||||
"gzip compressed data\n" "" ""
|
||||
test_line "bzip2 data" "tar/tar.tbz2" \
|
||||
"bzip2 compressed data, block size = 900k\n" "" ""
|
||||
test_line "7z file" "tar/tar.7z" "7-zip archive data, version 0.4\n" "" ""
|
||||
testing "zip file" \
|
||||
"file $FILES/zip/example.zip | egrep -o '(Zip archive data|at least v1.0 to extract)'" \
|
||||
"Zip archive data\nat least v1.0 to extract\n" "" ""
|
||||
|
||||
echo R0lGODlhIAAgAMZHAAAAABYWFiYmJioqKi4uLjIy | base64 -d > gif
|
||||
testing "gif file" "file gif" "gif: GIF image data, version 89a, 32 x 32\n" "" ""
|
||||
rm -f gif
|
||||
|
||||
# TODO: check in a genuine minimal .dex
|
||||
testing "Android .dex" "file android.dex" "android.dex: Android dex file, version 035\n" "" ""
|
||||
|
||||
echo "6465780a3033350038ca8f6ce910f94e" | xxd -r -p > android.dex
|
||||
testing "Android .dex" "file android.dex | egrep -o '(dex file|version 035)'" \
|
||||
"dex file\nversion 035\n" "" ""
|
||||
rm -f android.dex
|
||||
|
||||
# These actually test a lot of the ELF code: 32-/64-bit, arm/arm64, PT_INTERP,
|
||||
# the two kinds of NDK ELF note, BuildID, and stripped/not stripped.
|
||||
toyonly testing "Android NDK full ELF note" \
|
||||
"file $FILES/elf/ndk-elf-note-full | sed 's/^.*: //'" \
|
||||
"ELF shared object, 64-bit LSB arm64, dynamic (/system/bin/linker64), for Android 24, built by NDK r19b (5304403), BuildID=0c712b8af424d57041b85326f0000fadad38ee0a, not stripped\n" "" ""
|
||||
toyonly testing "Android NDK short ELF note" \
|
||||
"file $FILES/elf/ndk-elf-note-short | sed 's/^.*: //'" \
|
||||
"ELF shared object, 32-bit LSB arm, dynamic (/system/bin/linker), for Android 28, BuildID=da6a5f4ca8da163b9339326e626d8a3c, stripped\n" "" ""
|
||||
toyonly test_line "Android NDK full ELF note" "elf/ndk-elf-note-full" \
|
||||
"ELF shared object, 64-bit LSB arm64, dynamic (/system/bin/linker64), for Android 24, built by NDK r19b (5304403), BuildID=0c712b8af424d57041b85326f0000fadad38ee0a, not stripped\n" "" ""
|
||||
toyonly test_line "Android NDK short ELF note" "elf/ndk-elf-note-short" \
|
||||
"ELF shared object, 32-bit LSB arm, EABI5, soft float, dynamic (/system/bin/linker), for Android 28, BuildID=da6a5f4ca8da163b9339326e626d8a3c, stripped\n" "" ""
|
||||
toyonly test_line "ELF static fdpic" "elf/fdstatic" \
|
||||
"ELF executable (fdpic), 32-bit MSB sh, static, stripped\n" "" ""
|
||||
echo -ne '\x7fELF\00000000000000000000000000000000000000000000' > bad-bits
|
||||
testing "ELF bad bits" "file bad-bits | egrep -o '(ELF|unknown)'" \
|
||||
"ELF\nunknown\n" "" ""
|
||||
rm -f bad-bits
|
||||
|
||||
testing "broken symlink" "file dangler" "dangler: broken symbolic link to $BROKEN\n" "" ""
|
||||
testing "symlink" "file symlink" "symlink: symbolic link to $LINK\n" "" ""
|
||||
testing "symlink -h" "file -h symlink" "symlink: symbolic link to $LINK\n" "" ""
|
||||
testing "symlink -L" "file -L symlink" "symlink: Java class file, version 53.0 (Java 1.9)\n" "" ""
|
||||
testing "symlink -L" \
|
||||
"file -L symlink | egrep -o '(symlink:|Java class|version 53.0)'" \
|
||||
"symlink:\nJava class\nversion 53.0\n" "" ""
|
||||
|
||||
testing "- pipe" "cat $FILES/java.class | file -" "-: Java class file, version 53.0 (Java 1.9)\n" "" ""
|
||||
testing "- redirect" "file - <$FILES/java.class" "-: Java class file, version 53.0 (Java 1.9)\n" "" ""
|
||||
# Some host versions say "-" some "/dev/stdin"...
|
||||
testing "- pipe" "cat $FILES/java.class | file - | egrep -o '(Java class|version 53.0)'" \
|
||||
"Java class\nversion 53.0\n" "" ""
|
||||
testing "- redirect" \
|
||||
"file - <$FILES/java.class | egrep -o '(Java class|version 53.0)'" \
|
||||
"Java class\nversion 53.0\n" "" ""
|
||||
|
||||
testing "/dev/zero" "file /dev/zero" "/dev/zero: character special (1/5)\n" "" ""
|
||||
testing "- </dev/zero" "file - </dev/zero" "-: data\n" "" ""
|
||||
zero_dev="1/5"
|
||||
[ "$(uname)" == "Darwin" ] && zero_dev="3/3"
|
||||
testing "/dev/zero" "file /dev/zero" "/dev/zero: character special ($zero_dev)\n" "" ""
|
||||
testing "- </dev/zero" "file - </dev/zero | grep -ow data" "data\n" "" ""
|
||||
|
||||
rm empty bash.script bash.script2 env.python.script ascii android.dex
|
||||
testcmd 'ar' 'input | grep -o " ar archive"' ' ar archive\n' \
|
||||
"$(echo -e '!<arch>\nhello/ 0 0 0 644 6 `\nworld')\n" ""
|
||||
testcmd 'cpio' 'input' 'input: ASCII cpio archive (SVR4 with no CRC)\n' \
|
||||
'07070103344745000081A4000003E800' ''
|
||||
|
||||
#TODO block fifo socket
|
||||
#can't stat (unopenable)
|
||||
#file
|
||||
# readerror
|
||||
# elf
|
||||
# png (grayscale, color RGB, indexed color, grayscale with alpha, color RGBA
|
||||
# X x X x-bit/{non-}interlaced
|
||||
# gif87
|
||||
# jpeg
|
||||
# xz
|
||||
# Ogg (buncha types)
|
||||
# wav audio (buncha types)
|
||||
# truetype font/collection
|
||||
# Opentype font
|
||||
# LLVM IR bitcode
|
||||
# PEM certificate
|
||||
# pe32
|
||||
# BMP
|
||||
# Linux perf
|
||||
# Android sparse image file
|
||||
# Android boot image
|
||||
# Android DTB/DTBO
|
||||
# Android Binary XML
|
||||
# #! shell script
|
||||
|
||||
+6
-301
@@ -1,301 +1,6 @@
|
||||
scale = 1
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 2
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 3
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 4
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 5
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 6
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 7
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 8
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 9
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 10
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 11
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 12
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 13
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 14
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 15
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 16
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 17
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 18
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 19
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 20
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 21
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 22
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 23
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 24
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 25
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 26
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 27
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 28
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 29
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 30
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 31
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 32
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 33
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 34
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 35
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 36
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 37
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 38
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 39
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 40
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 41
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 42
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 43
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 44
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 45
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 46
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 47
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 48
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 49
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 50
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 51
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 52
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 53
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 54
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 55
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 56
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 57
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 58
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 59
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 60
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 61
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 62
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 63
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 64
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 65
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 66
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 67
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 68
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 69
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 70
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 71
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 72
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 73
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 74
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 75
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 76
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 77
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 78
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 79
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 80
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 81
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 82
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 83
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 84
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 85
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 86
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 87
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 88
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 89
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 90
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 91
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 92
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 93
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 94
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 95
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 96
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 97
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 98
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 99
|
||||
a(.267)
|
||||
a(1)
|
||||
scale = 100
|
||||
a(.267)
|
||||
a(1)
|
||||
halt
|
||||
for (i = 1; i <= 100; i++) {
|
||||
scale = i
|
||||
a(.267)
|
||||
a(1)
|
||||
}
|
||||
halt
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+35
-3
@@ -10,7 +10,7 @@ mkfifo fifo
|
||||
sleep .1
|
||||
ln -s fifo link
|
||||
cd ..
|
||||
touch b
|
||||
touch irrelevant
|
||||
|
||||
mkdir perm
|
||||
touch perm/all-read-only
|
||||
@@ -38,6 +38,8 @@ testing "( -type p -o -type d ) -type p" \
|
||||
testing "-type l -o -type d -type p -o -type f" \
|
||||
"find dir -type l -o -type d -type p -o -type f | sort" \
|
||||
"dir/file\ndir/link\n" "" ""
|
||||
testing "-type l,f" \
|
||||
"find dir -type l,f | sort" "dir/file\ndir/link\n" "" ""
|
||||
|
||||
# Testing short-circuit evaluations
|
||||
|
||||
@@ -83,14 +85,16 @@ testing "-exec {} +" \
|
||||
testing "-name file" "find dir -name file" "dir/file\n" "" ""
|
||||
testing "-name FILE" "find dir -name FILE" "" "" ""
|
||||
|
||||
ln -s ../broken dir/link2
|
||||
testing "-iname file" "find dir -iname FILE" "dir/file\n" "" ""
|
||||
testing "-iname FILE" "find dir -iname FILE" "dir/file\n" "" ""
|
||||
|
||||
|
||||
testing "-name (no arguments)" \
|
||||
"find dir -name 2>&1 | grep -o '[-]name'" "-name\n" "" ""
|
||||
testing "-iname (no arguments)" \
|
||||
"find dir -iname 2>&1 | grep -o '[-]iname'" "-iname\n" "" ""
|
||||
testing "-lname" "find dir -lname '?./brok*'" "dir/link2\n" "" ""
|
||||
testing "-ilname" "find dir -ilname '*ROK*'" "dir/link2\n" "" ""
|
||||
|
||||
testing "" "find dir \( -iname file -o -iname missing \) -exec echo {} \;" \
|
||||
"dir/file\n" "" ""
|
||||
@@ -121,7 +125,6 @@ ln -s looper dir/looper
|
||||
testing "-L symlink loop noisy" \
|
||||
"LANG=C find -L dir -name file 2>err ; grep -q dir/looper err || echo missing error" \
|
||||
"dir/file\n" "" ""
|
||||
rm -f dir/looper err
|
||||
|
||||
testing "-false" "find dir -false" "" "" ""
|
||||
testing "-true" "find dir/file -true" "dir/file\n" "" ""
|
||||
@@ -129,8 +132,37 @@ testing "-true" "find dir/file -true" "dir/file\n" "" ""
|
||||
testing "missing root error" \
|
||||
"LANG=C find -L dir/missing-root 2>err ; grep -q dir/missing-root err || echo missing error" \
|
||||
"" "" ""
|
||||
rm -f dir/looper err
|
||||
|
||||
testing "-path match root" "find dir/f* -path dir/file" "dir/file\n" "" ""
|
||||
testing "-name match root" "find dir/f* -name file" "dir/file\n" "" ""
|
||||
|
||||
# https://github.com/landley/toybox/issues/69
|
||||
ln -s nowhere broken
|
||||
testing "-H broken" "find -H broken" "broken\n" "" ""
|
||||
testing "-L broken" "find -L broken" "broken\n" "" ""
|
||||
|
||||
testing "one slash" 'find /etc/ -maxdepth 1 | grep /passwd\$' '/etc/passwd\n' \
|
||||
'' ''
|
||||
testing 'empty arg' 'find "" dir -name file 2>/dev/null' 'dir/file\n' '' ''
|
||||
testing 'quit' 'find dir perm -print -quit' 'dir\n' '' ''
|
||||
ln dir/file perm/hardlink
|
||||
testing 'samefile' 'find . -samefile dir/file | sort' \
|
||||
'./dir/file\n./perm/hardlink\n' '' ''
|
||||
rm -rf dir broken perm irrelevant
|
||||
|
||||
mkdir dir
|
||||
touch -d @12345 dir/one
|
||||
touch -d @12346 dir/two
|
||||
testing 'newerat' 'find dir -type f -newerat @12345' 'dir/two\n' '' ''
|
||||
testing 'newer nano' 'find dir -type f -newerat @12345.67890' 'dir/two\n' '' ''
|
||||
ln -s one dir/three
|
||||
testing '-size implies -type f' 'find dir -size -1M | sort' \
|
||||
'dir/one\ndir/two\n' '' ''
|
||||
rm -rf dir
|
||||
|
||||
utf8locale
|
||||
skipnot [ "$(uname)" != "Darwin" ] # Darwin's towlower() is broken.
|
||||
testing 'strlower edge case' \
|
||||
'touch aaaaaⱥⱥⱥⱥⱥⱥⱥⱥⱥ; find . -iname aaaaaȺȺȺȺȺȺȺȺȺ' './aaaaaⱥⱥⱥⱥⱥⱥⱥⱥⱥ\n' \
|
||||
'' ''
|
||||
|
||||
+2
-1
@@ -26,7 +26,8 @@ testing "" "fmt -w 11" "1 2 3 4 5\n6 7 8 9 0\n" "" "1 2 3 4 5 6 7 8 9 0\n"
|
||||
testing "" "fmt -w 12" "1 2 3 4 5 6\n7 8 9 0\n" "" "1 2 3 4 5 6 7 8 9 0\n"
|
||||
|
||||
testing "matched tab indent" "fmt" "\thello world\n" "" "\thello\n\tworld"
|
||||
testing "matched tab/space" "fmt" ' hello world\n' "" \
|
||||
# Version skew: debian is now emitting \t instead of "first line's indent"
|
||||
toyonly testing "matched tab/space" "fmt" ' hello world\n' "" \
|
||||
" hello\n\tworld"
|
||||
testing "matched space/tab" "fmt" "\thello world\n" "" "\thello\n world"
|
||||
|
||||
|
||||
+23
-8
@@ -4,12 +4,27 @@
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
#copied from gnu, but according to what i understand the output should be.
|
||||
testcmd 'default wrap' '-w10' 'one two th\nree\nfour five\n' \
|
||||
'' 'one two three\nfour five\n'
|
||||
testing "abuse" "fold -w1" "a\nb\nc\nd" "" "abcd"
|
||||
testcmd 'first char goes over' '-w2' '\t\n' '' '\t\n'
|
||||
testcmd 'tab goes over' '-sw2' 'a\n\t\n' '' 'a\t\n'
|
||||
testcmd 'tab goes over unterminated' '-sw2' 'a\n\t' '' 'a\t'
|
||||
testcmd '-s' '-sw4' 'abcd\nef g\n' '' 'abcdef g\n'
|
||||
testcmd '-s 2' '-sw4' 'abcd\nef \ngh\n' '' 'abcdef gh\n'
|
||||
testcmd '-s 3' '-sw4' 'a \ncd \nfgh\n' '' 'a cd fgh\n'
|
||||
testcmd '-s 4' '-sw4' 'abcd\n efg\n' '' 'abcd efg\n'
|
||||
testcmd '-s 5' '-sw4' 'abc \nef\n' '' 'abc ef\n'
|
||||
testcmd '-b tab' '-bw8' 'abc\tdefg\nhi' '' 'abc\tdefghi'
|
||||
testcmd '-bs' '-bsw8' 'abc\t\ndefghi' '' 'abc\tdefghi'
|
||||
testcmd 'backspace' '-w3' 'abc\bd\nef\n' '' 'abc\bdef\n'
|
||||
testcmd '-b backspace' '-bw3' 'abc\n\bde\nf\n' '' 'abc\bdef\n'
|
||||
testcmd 'backspace tab' '-w8' 'a\t\b\b\bcde\nfghi' '' 'a\t\b\b\bcdefghi'
|
||||
|
||||
testing "fold_test_1" "fold -w2 -s" "a\t\n" "" "a\t"
|
||||
testing "fold_test_2" "fold -w4 -s" "abcd\nef \nd\n" "" "abcdef d\n"
|
||||
testing "fold_test_3" "fold -w4 -s" "a \ncd \nfgh\n" "" "a cd fgh\n"
|
||||
testing "fold_test_4" "fold -w4 -s" "abc \nef\n" "" "abc ef\n"
|
||||
|
||||
#the question i posted
|
||||
testing "fold_test_5" "fold -w1" "a\nb\nc\nd\n" "" "abcd"
|
||||
toyonly testcmd 'combining umlaut wrap' '-w5' 'ẅabcd\nefg\n' '' \
|
||||
'w\xcc\x88abcdefg\n'
|
||||
toyonly testcmd 'combining umlaut backspace wrap' '-w5' 'ẅ\bxabcd\nefg\n' '' \
|
||||
'w\xcc\x88\bxabcdefg\n'
|
||||
toyonly testcmd 'wide wrap' '-w3' '私a\nbc' '' '\xe7\xa7\x81abc'
|
||||
toyonly testcmd 'wide combining wrap' '-w3' '私̈\bab\nc' '' \
|
||||
'\xe7\xa7\x81\xcc\x88\babc'
|
||||
|
||||
+9
-4
@@ -4,22 +4,27 @@
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
function clean()
|
||||
{
|
||||
# The filesystem may include some extended attributes by default (for
|
||||
# instance, security.selinux). Skip them.
|
||||
grep -v "security\."
|
||||
}
|
||||
|
||||
mkdir attrs
|
||||
touch attrs/file
|
||||
setfattr -n user.empty attrs/file
|
||||
setfattr -n user.data -v hello attrs/file
|
||||
setfattr -n user.more -v world attrs/file
|
||||
|
||||
testing "" "getfattr attrs/file" \
|
||||
testing "" "getfattr attrs/file | clean" \
|
||||
"# file: attrs/file\nuser.data\nuser.empty\nuser.more\n\n" "" ""
|
||||
testing "-d" "getfattr -d attrs/file" \
|
||||
testing "-d" "getfattr -d attrs/file | clean" \
|
||||
"# file: attrs/file\nuser.data=\"hello\"\nuser.empty\nuser.more=\"world\"\n\n" "" ""
|
||||
testing "-n" "getfattr -n user.empty attrs/file" \
|
||||
"# file: attrs/file\nuser.empty\n\n" "" ""
|
||||
testing "-d -n" "getfattr -d -n user.data attrs/file" \
|
||||
"# file: attrs/file\nuser.data=\"hello\"\n\n" "" ""
|
||||
testing "--only-values" "getfattr --only-values attrs/file" \
|
||||
"helloworld" "" ""
|
||||
testing "--only-values -n" "getfattr --only-values -n user.data attrs/file" \
|
||||
"hello" "" ""
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/bin/bash
|
||||
|
||||
[ -f testing.sh ] && . testing.sh
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
function test_getopt() {
|
||||
testcmd "$1" "$1" "$2\n" "" ""
|
||||
}
|
||||
|
||||
# Traditional behavior was to take the first argument as OPTSTR and not quote.
|
||||
test_getopt "a b c" " -- b c"
|
||||
test_getopt "a -a b c" " -a -- b c"
|
||||
test_getopt "a -- -a b c" " -- -a b c"
|
||||
|
||||
# Modern -o mode.
|
||||
test_getopt "-o a -- " " --"
|
||||
test_getopt "-o a -- -a b c" " -a -- 'b' 'c'"
|
||||
test_getopt "-o a: -- -a b c" " -a 'b' -- 'c'"
|
||||
|
||||
# Long options (--like --this).
|
||||
test_getopt "-o a -l long -- -a --long a" " -a --long -- 'a'"
|
||||
test_getopt "-o a -l one -l two -- -a --one --two" " -a --one --two --"
|
||||
test_getopt "-o a -l one,two -- -a --one --two" " -a --one --two --"
|
||||
# -l arg: (required)
|
||||
test_getopt "-o a -l one: -- -a --one arg" " -a --one 'arg' --"
|
||||
# -l arg:: (optional)
|
||||
test_getopt "-o a -l one:: -- -a --one" " -a --one '' --"
|
||||
test_getopt "-o a -l one:: -- -a --one arg" " -a --one '' -- 'arg'"
|
||||
test_getopt "-o a -l one:: -- -a --one=arg" " -a --one 'arg' --"
|
||||
|
||||
# "Alternative" long options (-like -this but also --like --this).
|
||||
test_getopt "-o a -a -l long -- -long --long a" " --long --long -- 'a'"
|
||||
|
||||
# -u lets you avoid quoting even with modern -o.
|
||||
test_getopt "-u -o a: -- -a b c" " -a b -- c"
|
||||
|
||||
# Do we quote quotes right?
|
||||
test_getopt "-o a -- \"it\'s\"" " -- 'it\'\''s'"
|
||||
test_getopt "-o a -u -- \"it\'s\"" " -- it\'s"
|
||||
|
||||
# Odds and ends.
|
||||
testcmd "-T" "-T ; echo \$?" "4\n" "" ""
|
||||
testcmd "-n" "-n unlikely a -x 2>&1 | grep -o unlikely:" "unlikely:\n" "" ""
|
||||
+157
-103
@@ -1,5 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
# TODO: several tests need to check both fast and slow paths
|
||||
|
||||
[ -f testing.sh ] && . testing.sh
|
||||
|
||||
# Copyright 2013 by Kyungsu Kim <kaspyx@gmail.com>
|
||||
@@ -7,173 +9,183 @@
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
testing "-c" "grep -c 123 input" "3\n" "123\ncount 123\n123\nfasdfasdf" ""
|
||||
testcmd 'simple' 'two' 'two\n' '' 'one\ntwo\nthree\n'
|
||||
testcmd 'negative' 'a' '' '' '\n'
|
||||
testcmd 'empty' "''" '\n' '' '\n'
|
||||
|
||||
echo -e "this is test" > foo
|
||||
echo -e "this is test2" > foo2
|
||||
echo -e "this is foo3" > foo3
|
||||
testing "-l" "grep -l test foo foo2 foo3" "foo\nfoo2\n" "" ""
|
||||
rm foo foo2 foo3
|
||||
testcmd "-c" "-c 123 input" "3\n" "123\ncount 123\n123\nfasdfasdf" ""
|
||||
|
||||
testing "-q" "grep -q test input && echo yes" "yes\n" "this is a test\n" ""
|
||||
testing "-E" "grep -E '[0-9]' input" "1234123asdfas123123\n1\n" \
|
||||
echo -e "this is test" > file
|
||||
echo -e "this is test2" > file2
|
||||
echo -e "this is number3" > file3
|
||||
testcmd "-l" "-l test file file2 file3" "file\nfile2\n" "" ""
|
||||
testcmd "-L" "-L test file file2 file3" "file3\n" "" ""
|
||||
rm file file2 file3
|
||||
|
||||
testcmd "-q" "-q test input && echo yes" "yes\n" "this is a test\n" ""
|
||||
testcmd "-E" "-E '[0-9]' input" "1234123asdfas123123\n1\n" \
|
||||
"1234123asdfas123123\nabc\n1\nabcde" ""
|
||||
testing "-e" "grep -e '[0-9]' input" "1234123asdfas123123\n1\n" \
|
||||
testcmd "-e" "-e '[0-9]' input" "1234123asdfas123123\n1\n" \
|
||||
"1234123asdfas123123\nabc\n1\nabcde" ""
|
||||
testing "-e -e" "grep -e one -e two -e three input" \
|
||||
testcmd "-e -e" "-e one -e two -e three input" \
|
||||
"two\ntwo\nthree\none\n" "two\ntwo\nthree\nand\none\n" ""
|
||||
testing "-F" "grep -F is input" "this is test\nthis is test2\n" \
|
||||
testcmd "-F" "-F is input" "this is test\nthis is test2\n" \
|
||||
"this is test\nthis is test2\ntest case" ""
|
||||
testcmd "-Fo ''" "-Fo ''" "" "" "hello\n"
|
||||
testcmd "-Fw ''" "-Fw ''" "" "" "hello\n"
|
||||
testcmd "-Fw '' 2" "-Fw ''" "\n" "" "\n"
|
||||
testcmd "-F is really fixed" "-F '.[x]'" "c.[x]d\n" "" "axb\nc.[x]d\n"
|
||||
|
||||
echo -e "this is test\nthis is test2\ntest case" > foo
|
||||
echo -e "hello this is test" > foo2
|
||||
echo -e "hi hello" > foo3
|
||||
testing "-H" "grep -H is foo foo2 foo3" "foo:this is test\nfoo:this is test2\nfoo2:hello this is test\n" "" ""
|
||||
testcmd "-H" "-H is foo foo2 foo3" \
|
||||
"foo:this is test\nfoo:this is test2\nfoo2:hello this is test\n" "" ""
|
||||
rm foo foo2 foo3
|
||||
|
||||
testing "-b" "grep -b is input" "0:this is test\n13:this is test2\n" \
|
||||
testcmd "-b" "-b is input" "0:this is test\n13:this is test2\n" \
|
||||
"this is test\nthis is test2\ntest case" ""
|
||||
testing "-i" "grep -i is input" "thisIs test\nthis is test2\n" \
|
||||
testcmd "-i" "-i is input" "thisIs test\nthis is test2\n" \
|
||||
"thisIs test\nthis is test2\ntest case" ""
|
||||
testing "-n" "grep -n is input" "1:this is test\n2:this is test2\n" \
|
||||
testcmd "-n" "-n is input" "1:this is test\n2:this is test2\n" \
|
||||
"this is test\nthis is test2\ntest case" ""
|
||||
testing "-o" "grep -o is input" "is\nis\nis\nis\n" \
|
||||
testcmd "-o" "-o is input" "is\nis\nis\nis\n" \
|
||||
"this is test\nthis is test2\ntest case" ""
|
||||
testing "-s" "grep -hs hello asdf input 2>&1" "hello\n" "hello\n" ""
|
||||
testing "-v" "grep -v abc input" "1234123asdfas123123\n1ABa\n" \
|
||||
testcmd "-s" "-hs hello asdf input 2>&1" "hello\n" "hello\n" ""
|
||||
testcmd "-v" "-v abc input" "1234123asdfas123123\n1ABa\n" \
|
||||
"1234123asdfas123123\n1ABabc\nabc\n1ABa\nabcde" ""
|
||||
testing "-w" "grep -w abc input" "abc\n123 abc\nabc 123\n123 abc 456\n" \
|
||||
testcmd "-w" "-w abc input" "abc\n123 abc\nabc 123\n123 abc 456\n" \
|
||||
"1234123asdfas123123\n1ABabc\nabc\n1ABa\nabcde\n123 abc\nabc 123\n123 abc 456\n" ""
|
||||
testing "-x" "grep -x abc input" "abc\n" \
|
||||
"aabcc\nabc\n" ""
|
||||
testcmd "-x" "-x abc input" "abc\n" "aabcc\nabc\n" ""
|
||||
|
||||
testing "-H (standard input)" "grep -H abc" "(standard input):abc\n" \
|
||||
"" "abc\n"
|
||||
testing "-l (standard input)" "grep -l abc" "(standard input)\n" \
|
||||
"" "abc\n"
|
||||
testing "-n two inputs" "grep -hn def - input" "2:def\n2:def\n" \
|
||||
testcmd "-H (standard input)" "-H abc" "(standard input):abc\n" "" "abc\n"
|
||||
testcmd "-l (standard input)" "-l abc" "(standard input)\n" "" "abc\n"
|
||||
testcmd "-n two inputs" "-hn def - input" "2:def\n2:def\n" \
|
||||
"abc\ndef\n" "abc\ndef\n"
|
||||
|
||||
testing "pattern with newline" "grep 'abc
|
||||
def' input" "aabcc\nddeff\n" \
|
||||
testcmd "pattern with newline" $'"abc\ndef" input' "aabcc\nddeff\n" \
|
||||
"aaaa\naabcc\n\dddd\nddeff\nffff\n" ""
|
||||
|
||||
testing "-lH" "grep -lH abc input" "input\n" "abc\n" ""
|
||||
testing "-cn" "grep -cn abc input" "1\n" "abc\n" ""
|
||||
testing "-cH" "grep -cH abc input" "input:1\n" "abc\n" ""
|
||||
testing "-qs" "grep -qs abc none input && echo yes" "yes\n" "abc\n" ""
|
||||
testing "-hl" "grep -hl abc input" "input\n" "abc\n" ""
|
||||
testing "-b stdin" "grep -b one" "0:one\n4:one\n8:one\n" "" "one\none\none\n"
|
||||
testing "-o overlap" "grep -bo aaa" "1:aaa\n" "" "baaaa\n"
|
||||
testcmd "-lH" "-lH abc input" "input\n" "abc\n" ""
|
||||
testcmd "-cn" "-cn abc input" "1\n" "abc\n" ""
|
||||
testcmd "-cH" "-cH abc input" "input:1\n" "abc\n" ""
|
||||
testcmd "-qs" "-qs abc none input && echo yes" "yes\n" "abc\n" ""
|
||||
testcmd "-hl" "-hl abc input" "input\n" "abc\n" ""
|
||||
testcmd "-b stdin" "-b one" "0:one\n4:one\n8:one\n" "" "one\none\none\n"
|
||||
testcmd "-o overlap" "-bo aaa" "1:aaa\n" "" "baaaa\n"
|
||||
# nonobvious: -co counts lines, not matches
|
||||
testing "-co" "grep -co one input" "1\n" "one one one\n" ""
|
||||
testing "-nom" "grep -nom 2 one" "1:one\n1:one\n1:one\n2:one\n2:one\n" \
|
||||
testcmd "-co" "-co one input" "1\n" "one one one\n" ""
|
||||
testcmd "-nom" "-nom 2 one" "1:one\n1:one\n1:one\n2:one\n2:one\n" \
|
||||
"" "one one one\none one\none"
|
||||
toyonly testing "-vo" "grep -vo one input" "two\nthree\n" "onetwoonethreeone\n" ""
|
||||
testing "no newline" "grep -h one input -" \
|
||||
toyonly testcmd "-vo" "-vo one input" "two\nthree\n" "onetwoonethreeone\n" ""
|
||||
testcmd "no newline" "-h one input -" \
|
||||
"hello one\nthere one\n" "hello one" "there one"
|
||||
|
||||
testing "-e multi" "grep -e one -ethree input" \
|
||||
"three\none\n" "three\ntwo\none\n" ""
|
||||
testcmd "-e multi" "-e one -ethree input" "three\none\n" "three\ntwo\none\n" ""
|
||||
# Suppress filenames for recursive test because dunno order they'd occur in
|
||||
mkdir sub
|
||||
echo -e "one\ntwo\nthree" > sub/one
|
||||
echo -e "three\ntwo\none" > sub/two
|
||||
testing "-hr" "grep -hr one sub" "one\none\n" "" ""
|
||||
testing "-r file" "grep -r three sub/two" "three\n" "" ""
|
||||
testing "-r dir" "grep -r one sub | sort" "sub/one:one\nsub/two:one\n" \
|
||||
testcmd "-hr" "-hr one sub" "one\none\n" "" ""
|
||||
testcmd "-r file" "-r three sub/two" "three\n" "" ""
|
||||
testcmd "-r dir" "-r one sub | sort" "sub/one:one\nsub/two:one\n" \
|
||||
"" ""
|
||||
rm -rf sub
|
||||
|
||||
# -x exact match trumps -F's "empty string matches whole line" behavior
|
||||
testing "-Fx ''" "grep -Fx '' input" "" "one one one\n" ""
|
||||
testing "-F ''" "grep -F '' input" "one one one\n" "one one one\n" ""
|
||||
testing "-F -e blah -e ''" "grep -F -e blah -e '' input" "one one one\n" \
|
||||
# -x exact match overrides -F's "empty string matches whole line" behavior
|
||||
testcmd "-Fx ''" "-Fx '' input" "" "one one one\n" ""
|
||||
testcmd "-F ''" "-F '' input" "one one one\n" "one one one\n" ""
|
||||
testcmd "-F -e blah -e ''" "-F -e blah -e '' input" "one one one\n" \
|
||||
"one one one\n" ""
|
||||
testing "-Fxv -e subset" "grep -Fxv -e bbswitch-dkms -e dkms" "" "" \
|
||||
"bbswitch-dkms\n"
|
||||
testing "-e blah -e ''" "grep -e blah -e '' input" "one one one\n" \
|
||||
"one one one\n" ""
|
||||
testing "-w ''" "grep -w '' input" "" "one one one\n" ""
|
||||
testing "-w '' 2" "grep -w '' input" "one two\n" "one two\n" ""
|
||||
testing "-w \\1" "grep -wo '\\(x\\)\\1'" "xx\n" "" "xx"
|
||||
testing "-o ''" "grep -o '' input" "" "one one one\n" ""
|
||||
testing "backref" 'grep -e "a\(b\)" -e "b\(c\)\1"' "bcc\nab\n" \
|
||||
"" "bcc\nbcb\nab\n"
|
||||
testcmd "-Fxv -e subset" "-Fxv -e bbswitch-dkms -e dkms" "" "" "bbswitch-dkms\n"
|
||||
testcmd "-e blah -e ''" "-e blah -e '' input" "one one one\n" "one one one\n" ""
|
||||
testcmd "-w ''" "-w '' input" "" "one one one\n" ""
|
||||
testcmd "-w '' 2" "-w '' input" "one two\n" "one two\n" ""
|
||||
#testcmd "-w '' 3" "-w ''" "one two\n" "one two\n" ""
|
||||
testcmd "'$' is ''" "'\$'" 'potato\n' '' 'potato\n'
|
||||
testcmd "'$' is '' 2" "'x*\$'" 'potato\n' '' 'potato\n'
|
||||
testcmd "-w '$'" "-w '\$'" '' '' 'abc abc\n'
|
||||
testcmd "-w '$' 2" "-w '\$'" 'abc \n' '' 'abc \n'
|
||||
testcmd "'^' is ''" "'^'" 'potato\n' '' 'potato\n'
|
||||
testcmd "'^' is '' 2" "'^x*'" 'potato\n' '' 'potato\n'
|
||||
testcmd "-w '^'" "-w '^'" '' '' 'abc abc\n'
|
||||
testcmd "-w '^' 2" "-w '^'" ' abc\n' '' ' abc\n'
|
||||
testcmd "-w \\1" "-wo '\\(x\\)\\1'" "xx\n" "" "xx"
|
||||
testcmd '' "-nw ''" '1:\n3: \n4:a \n5: a\n7:a a\n' '' \
|
||||
'\na\n \na \n a\na a\na a'
|
||||
testcmd '' "-nw '^'" '1:\n3: \n5: a\n' '' '\na\n \na \n a\na a\na a'
|
||||
testcmd '' "-nw '\$'" '1:\n3: \n4:a \n' '' '\na\n \na \n a\na a\na a'
|
||||
testcmd '' "-nw '^\$'" '1:\n' '' '\na\n \na \n a\na a\na a'
|
||||
testcmd "-o ''" "-o '' input" "" "one one one\n" ""
|
||||
testcmd "backref" '-e "a\(b\)" -e "b\(c\)\1"' "bcc\nab\n" "" "bcc\nbcb\nab\n"
|
||||
|
||||
testing "-A" "grep -A 2 yes" "yes\nno\nno\n--\nyes\nno\nno\nyes\nno\n" \
|
||||
testcmd "-A" "-A 2 yes" "yes\nno\nno\n--\nyes\nno\nno\nyes\nno\n" \
|
||||
"" "yes\nno\nno\nno\nyes\nno\nno\nyes\nno"
|
||||
testing "-B" "grep -B 1 yes" "no\nyes\n--\nno\nyes\nno\nyes\n" \
|
||||
testcmd "-B" "-B 1 yes" "no\nyes\n--\nno\nyes\nno\nyes\n" \
|
||||
"" "no\nno\nno\nyes\nno\nno\nyes\nno\nyes"
|
||||
testing "-C" "grep -C 1 yes" \
|
||||
"yes\nno\n--\nno\nyes\nno\nno\nyes\nno\nyes\nno\n" \
|
||||
testcmd "-C" "-C 1 yes" "yes\nno\n--\nno\nyes\nno\nno\nyes\nno\nyes\nno\n" \
|
||||
"" "yes\nno\nno\nno\nyes\nno\nno\nyes\nno\nyes\nno\nno"
|
||||
testing "-HnC" "grep -HnC1 two" \
|
||||
testcmd "-HnC" "-HnC1 two" \
|
||||
"(standard input)-1-one\n(standard input):2:two\n(standard input)-3-three\n" \
|
||||
"" "one\ntwo\nthree"
|
||||
|
||||
# Context lines weren't showing -b
|
||||
testing "-HnbB1" "grep -HnbB1 f input" \
|
||||
testcmd "-HnbB1" "-HnbB1 f input" \
|
||||
"input-3-8-three\ninput:4:14:four\ninput:5:19:five\n" \
|
||||
"one\ntwo\nthree\nfour\nfive\n" ""
|
||||
|
||||
testing "-q match overrides error" \
|
||||
"grep -q hello missing input 2>/dev/null && echo yes" "yes\n" "hello\n" ""
|
||||
testing "-q not found is 1" \
|
||||
'grep -q hello input || echo $?' "1\n" "" ""
|
||||
testing "-q missing is 2" \
|
||||
'grep -q hello missing missing 2>/dev/null || echo $?' "2\n" "" ""
|
||||
testing "-q missing survives exists but not found" \
|
||||
'grep -q hello missing missing input 2>/dev/null || echo $?' "2\n" "" ""
|
||||
testing "not found retained past match" \
|
||||
'grep hello missing input 2>/dev/null || echo $?' \
|
||||
"input:hello\n2\n" "hello\n" ""
|
||||
testcmd "-q match overrides error" \
|
||||
"-q hello missing input 2>/dev/null && echo yes" "yes\n" "hello\n" ""
|
||||
testcmd "-q not found is 1" '-q hello input || echo $?' "1\n" "x" ""
|
||||
testcmd "-q missing is 2" \
|
||||
'-q hello missing missing 2>/dev/null || echo $?' "2\n" "" ""
|
||||
testcmd "-q missing survives exists but not found" \
|
||||
'-q hello missing missing input 2>/dev/null || echo $?' "2\n" "" ""
|
||||
testcmd "not found retained past match" \
|
||||
'hello missing input 2>/dev/null || echo $?' "input:hello\n2\n" "hello\n" ""
|
||||
touch empty
|
||||
testing "one match good enough for 0" \
|
||||
'grep hello input empty && echo $?' 'input:hello\n0\n' 'hello\n' ''
|
||||
testcmd "one match good enough for 0" \
|
||||
'hello input empty && echo $?' 'input:hello\n0\n' 'hello\n' ''
|
||||
rm empty
|
||||
|
||||
testing "-o ''" "grep -o ''" "" "" "one two three\none two\none\n"
|
||||
testing '' "grep -o -e '' -e two" "two\ntwo\n" "" \
|
||||
"one two three\none two\none\n"
|
||||
testcmd "-o ''" "-o ''" "" "" "one two three\none two\none\n"
|
||||
testcmd '' "-o -e '' -e two" "two\ntwo\n" "" "one two three\none two\none\n"
|
||||
|
||||
echo "one\ntwo\nthree" > test
|
||||
testing "-l trumps -C" "grep -l -C1 two test input" "test\ninput\n" \
|
||||
testcmd "-l overrides -C" "-l -C1 two test input" "test\ninput\n" \
|
||||
"three\ntwo\none\n" ""
|
||||
rm test
|
||||
|
||||
# match after NUL byte
|
||||
testing "match after NUL byte" "grep -a two" "one\0and two three\n" \
|
||||
testcmd "match after NUL byte" "-a two" "one\0and two three\n" \
|
||||
"" 'one\0and two three'
|
||||
|
||||
# BREs versus EREs
|
||||
testing "implicit BRE |" "grep 'uno|dos'" "uno|dos\n" \
|
||||
"" "uno\ndos\nuno|dos\n"
|
||||
testing "explicit BRE |" "grep -e 'uno|dos'" "uno|dos\n" \
|
||||
"" "uno\ndos\nuno|dos\n"
|
||||
testing "explicit ERE |" "grep -E 'uno|dos'" "uno\ndos\nuno|dos\n" \
|
||||
testcmd "implicit BRE |" "'uno|dos'" "uno|dos\n" "" "uno\ndos\nuno|dos\n"
|
||||
testcmd "explicit BRE |" "-e 'uno|dos'" "uno|dos\n" "" "uno\ndos\nuno|dos\n"
|
||||
testcmd "explicit ERE |" "-E 'uno|dos'" "uno\ndos\nuno|dos\n" \
|
||||
"" "uno\ndos\nuno|dos\n"
|
||||
|
||||
testing "" "grep -o -e iss -e ipp" "iss\niss\nipp\n" "" "mississippi"
|
||||
testing "" "grep -o -e gum -e rgu" "rgu\n" "" "argument"
|
||||
testcmd "" "-o -e iss -e ipp" "iss\niss\nipp\n" "" "mississippi"
|
||||
testcmd "" "-o -e gum -e rgu" "rgu\n" "" "argument"
|
||||
|
||||
testing "early failure" 'grep --what 2>/dev/null || echo $?' "2\n" "" ""
|
||||
testcmd "early failure" '--what 2>/dev/null || echo $?' "2\n" "" ""
|
||||
|
||||
testing "" 'grep abc ; echo $?' "abcdef\n0\n" "" "abcdef\n"
|
||||
testing "" 'grep abc doesnotexist input 2>/dev/null; echo $?' \
|
||||
testcmd "" 'abc ; echo $?' "abcdef\n0\n" "" "abcdef\n"
|
||||
testcmd "" 'abc doesnotexist input 2>/dev/null; echo $?' \
|
||||
"input:abcdef\n2\n" "abcdef\n" ""
|
||||
mkdir sub
|
||||
ln -s nope sub/link
|
||||
testing "" 'grep -r walrus sub 2>/dev/null; echo $?' "1\n" "" ""
|
||||
testcmd "" '-r walrus sub 2>/dev/null; echo $?' "1\n" "" ""
|
||||
rm -rf sub
|
||||
|
||||
# --exclude-dir
|
||||
mkdir sub
|
||||
mkdir sub/yes
|
||||
mkdir -p sub/yes
|
||||
echo "hello world" > sub/yes/test
|
||||
mkdir sub/no
|
||||
echo "hello world" > sub/no/test
|
||||
testing "--exclude-dir" 'grep --exclude-dir=no -r world sub' "sub/yes/test:hello world\n" "" ""
|
||||
testcmd "--exclude-dir" '--exclude-dir=no -r world sub' \
|
||||
"sub/yes/test:hello world\n" "" ""
|
||||
rm -rf sub
|
||||
|
||||
# -r and -R differ in that -R will dereference symlinks to directories.
|
||||
@@ -181,19 +193,61 @@ mkdir dir
|
||||
echo "hello" > dir/f
|
||||
mkdir sub
|
||||
ln -s ../dir sub/link
|
||||
testing "" "grep -rh hello sub 2>/dev/null || echo err" "err\n" "" ""
|
||||
testing "" "grep -Rh hello sub" "hello\n" "" ""
|
||||
testcmd "" "-rh hello sub 2>/dev/null || echo err" "err\n" "" ""
|
||||
testcmd "" "-Rh hello sub" "hello\n" "" ""
|
||||
rm -rf sub real
|
||||
|
||||
# -F multiple matches
|
||||
testing "-F multiple" "grep -F h input" "this is hello\nthis is world\n" \
|
||||
testcmd "-F multiple" "-F h input" "this is hello\nthis is world\n" \
|
||||
"missing\nthis is hello\nthis is world\nmissing" ""
|
||||
testing "-Fi multiple" "grep -Fi h input" "this is HELLO\nthis is WORLD\n" \
|
||||
testcmd "-Fi multiple" "-Fi h input" "this is HELLO\nthis is WORLD\n" \
|
||||
"missing\nthis is HELLO\nthis is WORLD\nmissing" ""
|
||||
testing "-F empty multiple" "grep -Fi '' input" \
|
||||
testcmd "-F empty multiple" "-Fi '' input" \
|
||||
"missing\nthis is HELLO\nthis is WORLD\nmissing\n" \
|
||||
"missing\nthis is HELLO\nthis is WORLD\nmissing" ""
|
||||
testing "-Fx" "grep -Fx h input" "h\n" \
|
||||
testcmd "-Fx" "-Fx h input" "h\n" \
|
||||
"missing\nH\nthis is hello\nthis is world\nh\nmissing" ""
|
||||
testing "-Fix" "grep -Fix h input" "H\nh\n" \
|
||||
testcmd "-Fix" "-Fix h input" "H\nh\n" \
|
||||
"missing\nH\nthis is HELLO\nthis is WORLD\nh\nmissing" ""
|
||||
testcmd "-F bucket sort" "-F '\.zip'" '\\.zip\n' '' '\\.zip\n'
|
||||
testcmd "-f /dev/null" "-f /dev/null" "" "" "hello\n"
|
||||
|
||||
# -z doesn't apply to the \n in -e or -f patterns
|
||||
# Because x\n becomes "x" and "" the second of which matches every line.
|
||||
testcmd '-z patter\n' "-ze $'x\n' | xxd -pc0" \
|
||||
'6f6e650a74776f0a74687265650a00\n' '' 'one\ntwo\nthree\n'
|
||||
testcmd "-z patter\n 2" "-zof input | xxd -pc0" "69007400\n" "i\nt" "hi\nthere"
|
||||
testcmd '-lZ' '-lZ ^t input' 'input\0' 'one\ntwo' ''
|
||||
|
||||
# other implementations get this wrong without -a, but right with -a???
|
||||
toyonly testcmd '-l ^ after \0' '-l ^t' '' 'one\0two' ''
|
||||
|
||||
testcmd "print zero length match" "'[0-9]*'" "abc\n" "" "abc\n"
|
||||
testcmd "-o skip zero length match" "-o '[0-9]*'" "1234\n" "" "a1234b"
|
||||
# Bit of a hack, but other greps insert gratuitous \e[K clear-to-EOL
|
||||
testcmd "--color highlights all matches" \
|
||||
"--color=always def | grep -o '[[][0-9;]*[Km]def.[[]m' | wc -l" \
|
||||
"2\n" "" "abcdefghidefjkl\n"
|
||||
seq 1 100002 | base64 > testfile
|
||||
testing "speed" "timeout 5 grep -f testfile testfile 2>/dev/null | wc -l" \
|
||||
"10332\n" "" ""
|
||||
rm -f testfile
|
||||
|
||||
# Fast path tests
|
||||
|
||||
testcmd 'initial \' '\\.jar' 'bell.jar\n' '' 'bell.jar\n'
|
||||
testcmd '^$' '^\$' '\n' '' 'one\n\ntwo\n'
|
||||
testcmd 'middle ^ not special' 'a^' 'a^b\n' '' 'a^b\nb^a\n'
|
||||
# Quoted to protect it from the shell, grep should just see '$b'
|
||||
testcmd 'middle $ not special' "'\$b'" 'a$b\n' '' 'a$b\nb$a\n'
|
||||
|
||||
testcmd 'grep -of' '-of input' 'abc\n' 'a.c\n' 'abcdef\n'
|
||||
|
||||
testcmd '-A with -m' '-A1 -m2 match' 'match\n1\nmatch\n2\n' '' \
|
||||
'match\n1\nmatch\n2\nmatch\n3\n'
|
||||
|
||||
mkdir sub
|
||||
mkfifo -m 600 sub/blah
|
||||
echo found > sub/found
|
||||
testcmd "don't block on FIFO" '-rh found sub && echo done' 'found\ndone\n' '' ''
|
||||
rm -rf sub
|
||||
|
||||
@@ -21,6 +21,13 @@ testing "no files (stdin to stdout)" "cat f.gz | gunzip > f &&
|
||||
test -f f.gz && cat f" "hello world\n" "" ""
|
||||
rm -f f f.gz
|
||||
|
||||
# test FEXTRA support
|
||||
echo "1f8b08040000000000ff04000000ffff4bcbcfe70200a865327e04000000" | xxd -r -p > f1.gz
|
||||
testing "FEXTRA flag skipped properly" "gunzip f1.gz &&
|
||||
! test -f f1.gz && test -f f1 &&
|
||||
cat f1" "foo\n" "" ""
|
||||
rm -f f1 f1.gz
|
||||
|
||||
# -c Output to stdout
|
||||
echo -n "foo " | gzip > f1.gz
|
||||
echo "bar" | gzip > f2.gz
|
||||
|
||||
@@ -76,3 +76,6 @@ testing "permissions/times preservation" \
|
||||
"gzip -k f1 && TZ=UTC stat -c '%a %Y' f1 && stat -c '%a %X %Y' f1.gz" \
|
||||
"411 544413660\n411 252558240 544413660\n" "" ""
|
||||
rm -f f1 f1.gz
|
||||
|
||||
testing "reject non-gzip" "gzip -dc $FILES/blkid/msdos.bz2 2>/dev/null ||
|
||||
echo rejected" "rejected\n" "" ""
|
||||
|
||||
+17
-14
@@ -4,30 +4,33 @@
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
testing "head, stdin" "head -n 1 && echo yes" "one\nyes\n" "" "one\ntwo"
|
||||
testing "head, stdin via -" "head -n 1 - && echo yes" "one\nyes\n" "" "one\ntwo"
|
||||
testing "head, file" "head input -n 1 && echo yes" "one\nyes\n" "one\ntwo" ""
|
||||
testing "-number" "head -2 input && echo yes" "one\ntwo\nyes\n" \
|
||||
testcmd "stdin" "-n 1 && echo yes" "one\nyes\n" "" "one\ntwo"
|
||||
testcmd "stdin via -" "-n 1 - && echo yes" "one\nyes\n" "" "one\ntwo"
|
||||
testcmd "file" "input -n 1 && echo yes" "one\nyes\n" "one\ntwo" ""
|
||||
testcmd "-number" "-2 input && echo yes" "one\ntwo\nyes\n" \
|
||||
"one\ntwo\nthree\nfour" ""
|
||||
testing "head, default lines" "head" "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" "" "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12"
|
||||
testcmd "default lines" "" "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" "" "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12"
|
||||
|
||||
# coreutils & busybox name stdin as "standard input", toybox uses "-"
|
||||
testing "-v file" "head -v -n 1 input" "==> input <==\none\n" "one\ntwo\n" ""
|
||||
testing "-v stdin" "head -v -n 1 | sed 's/==> standard input <==/==> - <==/'" \
|
||||
testcmd "-v file" "-v -n 1 input" "==> input <==\none\n" "one\ntwo\n" ""
|
||||
testcmd "-v stdin" "-v -n 1 | sed 's/standard input/-/'" \
|
||||
"==> - <==\none\n" "" "one\ntwo\n"
|
||||
|
||||
testing "file and stdin" "head -n 1 input - | sed 's/==> standard input <==/==> - <==/'" \
|
||||
testcmd "file and stdin" "-n 1 input - | sed 's/standard input/-/'" \
|
||||
"==> input <==\none\n\n==> - <==\nfoo\n" "one\ntwo\n" "foo\nbar\n"
|
||||
|
||||
echo "foo
|
||||
bar
|
||||
baz" > file1
|
||||
testing "head, multiple files" "head -n 2 input file1" "==> input <==\none\ntwo\n\n==> file1 <==\nfoo\nbar\n" "one\ntwo\nthree\n" ""
|
||||
testing "-q, multiple files" "head -q -n 2 input file1" "one\ntwo\nfoo\nbar\n" \
|
||||
testcmd "multiple files" "-n 2 input file1" \
|
||||
"==> input <==\none\ntwo\n\n==> file1 <==\nfoo\nbar\n" "one\ntwo\nthree\n" ""
|
||||
testcmd "-q, multiple files" "-q -n 2 input file1" "one\ntwo\nfoo\nbar\n" \
|
||||
"one\ntwo\nthree\n" ""
|
||||
rm file1
|
||||
|
||||
testing "-c 3" "head -c 3" "one" "" "one\ntwo"
|
||||
testing "-c bigger than input" "head -c 3" "a" "" "a"
|
||||
testing "-c 3 -n 1" "head -c 3 -n 1" "one\n" "" "one\ntwo"
|
||||
testing "-n 1 -c 3" "head -n 1 -c 3" "one" "" "one\ntwo"
|
||||
testcmd "-c 3" "-c 3" "one" "" "one\ntwo"
|
||||
testcmd "-c bigger than input" "-c 3" "a" "" "a"
|
||||
testcmd "-c 3 -n 1" "-c 3 -n 1" "one\n" "" "one\ntwo"
|
||||
testcmd "-n 1 -c 3" "-n 1 -c 3" "one" "" "one\ntwo"
|
||||
testing "unget" 'while read i; do echo =$i; head -n 1; done < input' \
|
||||
'=one\ntwo\n=three\nfour\n=five\n' 'one\ntwo\nthree\nfour\nfive\n' ''
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
#!/bin/bash
|
||||
|
||||
[ -f testing.sh ] && . testing.sh
|
||||
|
||||
[ -n "$TEST_HOST" ] && NOSPACE=1
|
||||
testcmd "simple file" "input" "0000000 6973 706d 656c 000a\n0000007\n" "simple\\n" ""
|
||||
testcmd "simple file -b" "-b input" "0000000 163 151 155 160 154 145 012\n0000007\n" "simple\\n" ""
|
||||
testcmd "simple file -c" "-c input" "0000000 s i m p l e \\\\n\n0000007\n" "simple\\n" ""
|
||||
testcmd "simple file -d" "-d input" "0000000 26995 28781 25964 00010\n0000007\n" "simple\\n" ""
|
||||
testcmd "simple file -o" "-o input" "0000000 064563 070155 062554 000012\n0000007\n" "simple\\n" ""
|
||||
testcmd "simple file -x" "-x input" "0000000 6973 706d 656c 000a\n0000007\n" "simple\\n" ""
|
||||
|
||||
testcmd \
|
||||
"simple file canonical output -C" \
|
||||
"-C input" \
|
||||
"\
|
||||
00000000 73 69 6d 70 6c 65 0a |simple.|\n\
|
||||
00000007\n" \
|
||||
"simple\n" \
|
||||
""
|
||||
testcmd \
|
||||
"simple file canonical output -C multiline" \
|
||||
"-C input" \
|
||||
"\
|
||||
00000000 73 69 6d 70 6c 65 0a 62 61 72 66 6f 6f 62 61 72 |simple.barfoobar|\n\
|
||||
00000010 66 6f 6f 62 61 72 0a |foobar.|\n\
|
||||
00000017\n" \
|
||||
"\
|
||||
simple\n\
|
||||
barfoobarfoobar\n" \
|
||||
""
|
||||
|
||||
testcmd \
|
||||
"head of file -n 10" \
|
||||
"-n 10 input" \
|
||||
"\
|
||||
0000000 6973 706d 656c 730a 6d69\n\
|
||||
000000a\n" \
|
||||
"simple\nsimple\n" \
|
||||
""
|
||||
testcmd \
|
||||
"skip head of file -s 10" \
|
||||
"-s 10 input" \
|
||||
"\
|
||||
000000a 6c70 0a65\n\
|
||||
000000e\n" \
|
||||
"simple\nsimple\n" \
|
||||
""
|
||||
|
||||
testcmd \
|
||||
"squeeze repeating lines" \
|
||||
"input" \
|
||||
"\
|
||||
0000000 6161 6161 6161 6161 6161 6161 6161 0a61\n\
|
||||
*\n\
|
||||
0000070 6f66 006f\n\
|
||||
0000073\n" \
|
||||
"\
|
||||
aaaaaaaaaaaaaaa\n\
|
||||
aaaaaaaaaaaaaaa\n\
|
||||
aaaaaaaaaaaaaaa\n\
|
||||
aaaaaaaaaaaaaaa\n\
|
||||
aaaaaaaaaaaaaaa\n\
|
||||
aaaaaaaaaaaaaaa\n\
|
||||
aaaaaaaaaaaaaaa\n\
|
||||
foo" \
|
||||
""
|
||||
testcmd \
|
||||
"squeeze repeating lines" \
|
||||
"input" \
|
||||
"\
|
||||
0000000 6161 6161 6161 6161 6161 6161 6161 0a61\n\
|
||||
*\n\
|
||||
0000030 6262 6262 6262 6262 6262 6262 6262 0a62\n\
|
||||
0000040 6161 6161 6161 6161 6161 6161 6161 0a61\n\
|
||||
*\n\
|
||||
0000070 6262 6262 6262 6262 6262 6262 6262 0a62\n\
|
||||
0000080\n" \
|
||||
"\
|
||||
aaaaaaaaaaaaaaa\n\
|
||||
aaaaaaaaaaaaaaa\n\
|
||||
aaaaaaaaaaaaaaa\n\
|
||||
bbbbbbbbbbbbbbb\n\
|
||||
aaaaaaaaaaaaaaa\n\
|
||||
aaaaaaaaaaaaaaa\n\
|
||||
aaaaaaaaaaaaaaa\n\
|
||||
bbbbbbbbbbbbbbb\n" \
|
||||
""
|
||||
testcmd \
|
||||
"don't squeeze repeating lines" \
|
||||
"-v input" \
|
||||
"\
|
||||
0000000 6161 6161 6161 6161 6161 6161 6161 0a61\n\
|
||||
0000010 6161 6161 6161 6161 6161 6161 6161 0a61\n\
|
||||
0000020 6161 6161 6161 6161 6161 6161 6161 0a61\n\
|
||||
0000030 6161 6161 6161 6161 6161 6161 6161 0a61\n\
|
||||
0000040 6161 6161 6161 6161 6161 6161 6161 0a61\n\
|
||||
0000050 6161 6161 6161 6161 6161 6161 6161 0a61\n\
|
||||
0000060 6161 6161 6161 6161 6161 6161 6161 0a61\n\
|
||||
0000070 6f66 006f\n\
|
||||
0000073\n" \
|
||||
"\
|
||||
aaaaaaaaaaaaaaa\n\
|
||||
aaaaaaaaaaaaaaa\n\
|
||||
aaaaaaaaaaaaaaa\n\
|
||||
aaaaaaaaaaaaaaa\n\
|
||||
aaaaaaaaaaaaaaa\n\
|
||||
aaaaaaaaaaaaaaa\n\
|
||||
aaaaaaaaaaaaaaa\n\
|
||||
foo" \
|
||||
""
|
||||
|
||||
for _ in {1..25}; do echo "foobar" >> file1; done
|
||||
for _ in {1..25}; do echo "buzzbar" >> file2; done
|
||||
|
||||
testcmd \
|
||||
"accumulate offset accross files" \
|
||||
"file1 file2" \
|
||||
"0000000 6f66 626f 7261 660a 6f6f 6162 0a72 6f66\n\
|
||||
0000010 626f 7261 660a 6f6f 6162 0a72 6f66 626f\n\
|
||||
0000020 7261 660a 6f6f 6162 0a72 6f66 626f 7261\n\
|
||||
0000030 660a 6f6f 6162 0a72 6f66 626f 7261 660a\n\
|
||||
0000040 6f6f 6162 0a72 6f66 626f 7261 660a 6f6f\n\
|
||||
0000050 6162 0a72 6f66 626f 7261 660a 6f6f 6162\n\
|
||||
0000060 0a72 6f66 626f 7261 660a 6f6f 6162 0a72\n\
|
||||
0000070 6f66 626f 7261 660a 6f6f 6162 0a72 6f66\n\
|
||||
0000080 626f 7261 660a 6f6f 6162 0a72 6f66 626f\n\
|
||||
0000090 7261 660a 6f6f 6162 0a72 6f66 626f 7261\n\
|
||||
00000a0 660a 6f6f 6162 0a72 6f66 626f 7261 620a\n\
|
||||
00000b0 7a75 627a 7261 620a 7a75 627a 7261 620a\n\
|
||||
*\n\
|
||||
0000170 7a75 627a 7261 000a\n\
|
||||
0000177\n" \
|
||||
"" \
|
||||
""
|
||||
rm file1 file2
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
[ -f testing.sh ] && . testing.sh
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
testcmd "static file" \
|
||||
"\"\$FILES\" | sed 's/\\r//g;1,/^\$/d'>file; cmp file \$FILES/tar/tar.tar && echo yes" \
|
||||
'yes\n' '' 'GET /tar/tar.tar HTTP/1.1\r\n\r\n'
|
||||
rm -f file
|
||||
|
||||
testcmd "mime type" \
|
||||
'"$FILES" | tr A-Z a-z | sed -n "s/\r//g;s/^content-type: //p"' "application/x-tar\n" "" \
|
||||
'GET /tar/tar.tar HTTP/1.1\r\n\r\n'
|
||||
|
||||
+9
-6
@@ -4,12 +4,15 @@
|
||||
|
||||
# Example characters from https://en.wikipedia.org/wiki/UTF-16:
|
||||
# $:U+0024 €:U+20ac 𐐷:U+10437[==U+d801,U+dc37]
|
||||
echo -n "$€𐐷" > chars
|
||||
# We can't simply use echo because bash 3.2 on the Mac mangles it, but toysh
|
||||
# should let us go back to just this when it's available...
|
||||
# echo -n "$€𐐷" > chars
|
||||
echo -ne "\x24\xe2\x82\xac\xf0\x90\x90\xb7" > chars
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
utf8locale
|
||||
testing "" "iconv chars | xxd -p" "24e282acf09090b7\n" "" ""
|
||||
testing "-t UTF-16BE" "iconv -t utf16be chars | xxd -p" "002420acd801dc37\n" "" ""
|
||||
testing "-t UTF-16LE" "iconv -t utf16le chars | xxd -p" "2400ac2001d837dc\n" "" ""
|
||||
testing "-t UTF-32BE" "iconv -t utf32be chars | xxd -p" "00000024000020ac00010437\n" "" ""
|
||||
testing "-t UTF-32BE" "iconv -t utf32le chars | xxd -p" "24000000ac20000037040100\n" "" ""
|
||||
testing "-t UTF-16BE" "iconv -t UTF-16BE chars | xxd -p" "002420acd801dc37\n" "" ""
|
||||
testing "-t UTF-16LE" "iconv -t UTF-16LE chars | xxd -p" "2400ac2001d837dc\n" "" ""
|
||||
testing "-t UTF-32BE" "iconv -t UTF-32BE chars | xxd -p" "00000024000020ac00010437\n" "" ""
|
||||
testing "-t UTF-32LE" "iconv -t UTF-32LE chars | xxd -p" "24000000ac20000037040100\n" "" ""
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
[ -f testing.sh ] && . testing.sh
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
# Systems with SELinux will have security context cruft,
|
||||
# BSDs call the root group "wheel" instead,
|
||||
# and Raspberry Pi OS has root also in the 117(lpadmin) group.
|
||||
CLEAN="sed 's/ context=.*//g' | sed 's/wheel/root/g' | \
|
||||
sed 's/117//g' | sed -E 's/\(?lpadmin\)?//g' | sed 's/[ ,]$//'"
|
||||
|
||||
testing "0" "id 0 | $CLEAN" "uid=0(root) gid=0(root) groups=0(root)\n" "" ""
|
||||
testing "root" "id root | $CLEAN" \
|
||||
"uid=0(root) gid=0(root) groups=0(root)\n" "" ""
|
||||
testing "-G root" "id -G root | $CLEAN" "0\n" "" ""
|
||||
testing "-nG root" "id -nG root | $CLEAN" "root\n" "" ""
|
||||
testing "-g root" "id -g root" "0\n" "" ""
|
||||
testing "-ng root" "id -ng root | $CLEAN" "root\n" "" ""
|
||||
testing "-u root" "id -u root" "0\n" "" ""
|
||||
testing "-nu root" "id -nu root" "root\n" "" ""
|
||||
testing "no-such-user" "id no-such-user 2>/dev/null ; echo \$?" "1\n" "" ""
|
||||
testing "2147483647" "id 2147483647 2>/dev/null ; echo \$?" "1\n" "" ""
|
||||
+24
-32
@@ -19,6 +19,8 @@
|
||||
# outfill|keepalive INTEGER - SLIP analog dialup line quality monitoring
|
||||
# metric INTEGER - added to Linux 0.9.10 with comment "never used", still true
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
[ -f testing.sh ] && . testing.sh
|
||||
|
||||
if [ "$(id -u)" -ne 0 ]
|
||||
@@ -28,10 +30,8 @@ then
|
||||
exit
|
||||
fi
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
# Add a dummy interface to test with
|
||||
modprobe dummy 2>/dev/null
|
||||
modprobe dummy >/dev/null 2>&1
|
||||
if ! ifconfig dummy0 up 2>/dev/null
|
||||
then
|
||||
echo "$SHOWSKIP: ifconfig dummy0 up failed"
|
||||
@@ -39,38 +39,31 @@ then
|
||||
exit
|
||||
fi
|
||||
|
||||
# Test Description: Disable the dummy0 interface
|
||||
# Results Expected: After calling ifconfig, no lines with dummy0 are displayed
|
||||
testing "dummy0 down and if config /-only" \
|
||||
"ifconfig dummy0 down && ifconfig | grep dummy | wc -l" \
|
||||
"0\n" "" ""
|
||||
testing "Disable the dummy0 interface" \
|
||||
"ifconfig dummy0 down && ifconfig | grep dummy | wc -l" "0\n" "" ""
|
||||
|
||||
# Test Description: Enable the dummy0 interface
|
||||
# Results Expected: After calling ifconfig, one line with dummy0 is displayed
|
||||
testing "dummy0 up" \
|
||||
"ifconfig dummy0 up && ifconfig dummy0 | grep dummy | wc -l" \
|
||||
"1\n" "" ""
|
||||
testing "Enable the dummy0 interface" \
|
||||
"ifconfig dummy0 up && ifconfig dummy0 | grep dummy | wc -l" "1\n" "" ""
|
||||
|
||||
# Test Description: Set the ip address of the dummy0 interface
|
||||
# Results Expected: After calling ifconfig dummy0, one line displays the ip
|
||||
# address selected
|
||||
testing "dummy0 10.240.240.240" \
|
||||
"ifconfig dummy0 10.240.240.240 && ifconfig dummy0 | grep 10\.240\.240\.240 | wc -l" \
|
||||
"1\n" "" ""
|
||||
testing "Set the ip address of the dummy0 interface" \
|
||||
"ifconfig dummy0 10.240.240.240 && ifconfig dummy0 | grep 10\.240\.240\.240 | wc -l" \
|
||||
"1\n" "" ""
|
||||
|
||||
# Test Description: Change the netmask to the interface
|
||||
# Results Expected: After calling ifconfig dummy0, one line displays the
|
||||
# netmask selected
|
||||
testing "dummy0 netmask 255.255.240.0" \
|
||||
"ifconfig dummy0 netmask 255.255.240.0 && ifconfig dummy0 | grep 255\.255\.240\.0 | wc -l" \
|
||||
"1\n" "" ""
|
||||
testing "Change the netmask to the interface" \
|
||||
"ifconfig dummy0 netmask 255.255.240.0 && ifconfig dummy0 | grep 255\.255\.240\.0 | wc -l" \
|
||||
"1\n" "" ""
|
||||
|
||||
# Test Description: Change the broadcast address to the interface
|
||||
# Results Expected: After calling ifconfig dummy0, one line displays the
|
||||
# broadcast address selected
|
||||
testing "dummy0 broadcast 10.240.240.255" \
|
||||
"ifconfig dummy0 broadcast 10.240.240.255 && ifconfig dummy0 | grep 10\.240\.240\.255 | wc -l" \
|
||||
"1\n" "" ""
|
||||
testing "Change the broadcast address to the interface" \
|
||||
"ifconfig dummy0 broadcast 10.240.240.255 && ifconfig dummy0 | grep 10\.240\.240\.255 | wc -l" \
|
||||
"1\n" "" ""
|
||||
|
||||
# Test Description: Revert to the default ip address
|
||||
# Results Expected: After calling ifconfig dummy0, there are no lines
|
||||
@@ -83,35 +76,34 @@ testing "dummy0 default" \
|
||||
# Results Expected: After calling ifconfig dummy0, there is one line with the
|
||||
# selected MTU
|
||||
testing "dummy0 mtu 1269" \
|
||||
"ifconfig dummy0 mtu 1269 && ifconfig dummy0 | grep 1269 | wc -l" \
|
||||
"ifconfig dummy0 mtu 1269 && ifconfig dummy0 | grep MTU:1269 | wc -l" \
|
||||
"1\n" "" ""
|
||||
|
||||
# Test Description: Verify ifconfig add fails with such a small mtu
|
||||
# Results Expected: There is one line of error message containing
|
||||
# "No buffer space available"
|
||||
# Test Description: ifconfig add for IPv6 fails with an mtu too small for IPv6.
|
||||
# Results Expected: Failure. No check for the exact error because old kernels
|
||||
# used ENOBUFS but 5.4 uses EINVAL.
|
||||
testing "dummy0 add ::2 -- too small mtu" \
|
||||
"ifconfig dummy0 add ::2 2>&1 | grep No\ buffer\ space\ available | wc -l" \
|
||||
"1\n" "" ""
|
||||
"ifconfig dummy0 add ::2 2>/dev/null || echo expected" "expected\n" "" ""
|
||||
|
||||
# Test Description: Change the Maximum transmission unit (MTU) of the interface
|
||||
# Results Expected: After calling ifconfig dummy0, there is one line with the
|
||||
# selected MTU
|
||||
testing "dummy0 mtu 2000" \
|
||||
"ifconfig dummy0 mtu 2000 && ifconfig dummy0 | grep 2000 | wc -l" \
|
||||
"ifconfig dummy0 mtu 2000 && ifconfig dummy0 | grep MTU:2000 | wc -l" \
|
||||
"1\n" "" ""
|
||||
|
||||
# Test Description: Verify ifconfig add succeeds with a larger mtu
|
||||
# Results Expected: after calling ifconfig dummy0, there is one line with the
|
||||
# selected ip address
|
||||
testing "dummy0 add ::2" \
|
||||
"ifconfig dummy0 add ::2/126 && ifconfig dummy0 | grep \:\:2\/126 | wc -l" \
|
||||
"ifconfig dummy0 add ::2/126 && ifconfig dummy0 | grep \:\:2/126 | wc -l" \
|
||||
"1\n" "" ""
|
||||
|
||||
# Test Description: Verify ifconfig del removes the selected ip6 address
|
||||
# Results Expected: after calling ifconfig dummy0, there are no lines with the
|
||||
# selected ip address
|
||||
testing "dummy0 del ::2" \
|
||||
"ifconfig dummy0 del ::2/126 && ifconfig dummy0 | grep \:\:2 | wc -l" \
|
||||
"ifconfig dummy0 del ::2/126 && ifconfig dummy0 | grep \:\:2/126 | wc -l" \
|
||||
"0\n" "" ""
|
||||
|
||||
# Test Description: Remove the noarp flag and bring the interface down in
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
|
||||
# TODO: fill this out.
|
||||
# TODO: "make install" means something else, so no test_install, only callable
|
||||
# from "make tests"...
|
||||
|
||||
[ -f testing.sh ] && . testing.sh
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
dd if=/dev/urandom of=random bs=64 count=1 2> /dev/null
|
||||
testing "install -D exists" \
|
||||
"mkdir -p a; touch a/b; install -D random a/b && cmp random a/b && echo yes" \
|
||||
"yes\n" "" ""
|
||||
rm -rf a random
|
||||
testing "install -D -t creates directory" \
|
||||
"touch a; install -Dt b a && echo yes" \
|
||||
"yes\n" "" ""
|
||||
rm -rf a b
|
||||
|
||||
testing "install -d" "umask 0 && install -d potato && stat -c%a potato" \
|
||||
"755\n" "" ""
|
||||
rmdir potato
|
||||
testcmd "-dm" "-dm 02750 potato && stat -c%a potato" "2750\n" "" ""
|
||||
rmdir potato
|
||||
testcmd '' '-dm +x potato && stat -c%a potato' '111\n' '' ''
|
||||
@@ -6,3 +6,4 @@
|
||||
|
||||
testcmd "-l HUP" "-l HUP" "1\n" "" ""
|
||||
testcmd "-l 1" "-l 1" "HUP\n" "" ""
|
||||
testcmd "-0 self" "-0 $$ && echo yes" "yes\n" "" ""
|
||||
|
||||
@@ -55,6 +55,7 @@ rm -rf file dir slink
|
||||
|
||||
testing "-t" "ln -st . one/two three && readlink two three" "one/two\nthree\n" \
|
||||
"" ""
|
||||
rm -f two three
|
||||
|
||||
touch file1 file2 && mkdir dir
|
||||
testing "create_multiple_hardlinks" "ln file* dir/ &&
|
||||
@@ -78,3 +79,12 @@ testing "create_hardlink_and_remove_sourcefile" "ln file hlink &&
|
||||
[ file -ef hlink ] && rm file && [ -f hlink ] && echo 'yes'" \
|
||||
"yes\n" "" ""
|
||||
rm -f file hlink
|
||||
|
||||
mkdir -p one/two
|
||||
ln -s . circular
|
||||
mkdir -p three
|
||||
echo hello > three/four
|
||||
testing "ln -r" \
|
||||
"ln -sr circular/three/../three/four one/two/five && cat one/two/five" \
|
||||
"hello\n" "" ""
|
||||
rm -rf one three circular
|
||||
|
||||
+85
-40
@@ -9,51 +9,96 @@
|
||||
#set -x
|
||||
|
||||
# Creating test-file/dir for testing ls
|
||||
mkdir -p lstest/dir1 lstest/dir2 || exit 1
|
||||
echo "test file1" > lstest/file1.txt
|
||||
echo "test file2" > lstest/file2.txt
|
||||
echo "hidden file1" > lstest/.hfile1
|
||||
mkdir -p dir1 dir2 || exit 1
|
||||
echo "test file1" > file1.txt
|
||||
echo "test file2" > file2.txt
|
||||
echo "hidden file1" > .hfile1
|
||||
|
||||
IN="cd lstest"
|
||||
OUT="cd .. "
|
||||
testcmd "no argument" "" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" ""
|
||||
testcmd "-C column spacing equals 2" "-C" "dir1 dir2 file1.txt file2.txt\n" \
|
||||
"" ""
|
||||
testcmd "-x column spacing equals 2" "-x" "dir1 dir2 file1.txt file2.txt\n" \
|
||||
"" ""
|
||||
testcmd "explicit files" "file*" "file1.txt\nfile2.txt\n" "" ""
|
||||
testcmd "explicit -1" "-1 file*" "file1.txt\nfile2.txt\n" "" ""
|
||||
testcmd "" "-p" "dir1/\ndir2/\nfile1.txt\nfile2.txt\n" "" ""
|
||||
testcmd "" "-a" ".\n..\n.hfile1\ndir1\ndir2\nfile1.txt\nfile2.txt\n" "" ""
|
||||
testcmd "" "-A" ".hfile1\ndir1\ndir2\nfile1.txt\nfile2.txt\n" "" ""
|
||||
testcmd "" "-d" ".\n" "" ""
|
||||
testcmd "" "-d *" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" ""
|
||||
testcmd "" "-k" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" ""
|
||||
testcmd "-m" "-m" "dir1, dir2, file1.txt, file2.txt\n" "" ""
|
||||
testcmd "-F" "-F" "dir1/\ndir2/\nfile1.txt\nfile2.txt\n" "" ""
|
||||
testcmd "-dk *" "-dk *" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" ""
|
||||
testcmd "-Z" "-Z file1.txt | egrep -q '^[^ ]+ file1.txt' || echo fail" "" "" ""
|
||||
testcmd "-lZ" "--full-time -lZ file1.txt | egrep -q '^-[rwx-]+ +[0-9]+ +[^ ]+ +[^ ]+ +[^ ]+ +[0-9]+ [0-9][0-9][0-9][0-9]-[0-9][0-9]-.* file1.txt' || echo fail" "" "" ""
|
||||
|
||||
testing "no argument" "$IN && ls; $OUT" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" ""
|
||||
testing "with wild char" "$IN && ls file*; $OUT" "file1.txt\nfile2.txt\n" "" ""
|
||||
testing "with wild char - long listing" "$IN && ls -1 file*; $OUT" "file1.txt\nfile2.txt\n" "" ""
|
||||
testing "with -p" "$IN && ls -p; $OUT" "dir1/\ndir2/\nfile1.txt\nfile2.txt\n" "" ""
|
||||
testing "with -a" "$IN && ls -a; $OUT" \
|
||||
".\n..\n.hfile1\ndir1\ndir2\nfile1.txt\nfile2.txt\n" "" ""
|
||||
testing "with -A" "$IN && ls -A; $OUT" \
|
||||
".hfile1\ndir1\ndir2\nfile1.txt\nfile2.txt\n" "" ""
|
||||
testing "with -d" "$IN && ls -d; $OUT" ".\n" "" ""
|
||||
testing "with wild char and -d *" "$IN && ls -d *; $OUT" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" ""
|
||||
testing "with -k" "$IN && ls -k; $OUT" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" ""
|
||||
testing "with -m" "$IN && ls -m; $OUT" "dir1, dir2, file1.txt, file2.txt\n" "" ""
|
||||
testing "with -F" "$IN && ls -F; $OUT" "dir1/\ndir2/\nfile1.txt\nfile2.txt\n" "" ""
|
||||
testing "with -dk *" "$IN && ls -dk *; $OUT" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" ""
|
||||
testing "with -Z" "$IN && ls -Z file1.txt | egrep -q '^[^ ]+ file1.txt' || echo fail; $OUT" "" "" ""
|
||||
testing "with -lZ" "$IN && ls --full-time -lZ file1.txt | egrep -q '^-[rwx-]+ +[0-9]+ +[^ ]+ +[^ ]+ +[^ ]+ +[0-9]+ [0-9][0-9][0-9][0-9]-[0-9][0-9]-.* file1.txt' || echo fail; $OUT" "" "" ""
|
||||
ln -s file1.txt slink
|
||||
testcmd "-l symlink" "-l slink | grep -q -- ' slink -> file1.txt' && echo ok" \
|
||||
"ok\n" "" ""
|
||||
rm -f slink
|
||||
|
||||
ln -s file1.txt lstest/slink
|
||||
testing "-l symlink" \
|
||||
"$IN && ls -l slink | grep -q -- ' slink -> file1.txt' && echo ok ; $OUT" \
|
||||
"ok\n" "" ""
|
||||
rm -f lstest/slink
|
||||
ln -s /dev/null/nosuchfile nosuchfile
|
||||
testcmd "-d broken symlink" "-d nosuchfile" "nosuchfile\n" "" ""
|
||||
rm -f nosuchfile
|
||||
|
||||
ln -s /dev/null/nosuchfile lstest/nosuchfile
|
||||
testing "with -d - broken softlink" "$IN && ls -d nosuchfile; $OUT" "nosuchfile\n" "" ""
|
||||
rm -f lstest/nosuchfile
|
||||
rm -rf file{1,2}.txt .hfile1 dir1 dir2
|
||||
|
||||
rm -rf lstest/* && mkdir -p lstest/dir1 && touch lstest/file1.txt
|
||||
testing "nested recursively" "$IN && ls -R; $OUT" \
|
||||
".:\ndir1\nfile1.txt\n\n./dir1:\n" "" ""
|
||||
mkdir -p dir1 && touch file1.txt dir1/file2
|
||||
testcmd "" "-R" ".:\ndir1\nfile1.txt\n\n./dir1:\nfile2\n" "" ""
|
||||
rm -rf dir1 file1.txt
|
||||
|
||||
rm -rf lstest/* && touch lstest/file1.txt && INODE=`stat -c %i lstest/file1.txt`
|
||||
testing "with -i" "$IN && ls -i 2>/dev/null; $OUT" "$INODE file1.txt\n" "" ""
|
||||
unset INODE
|
||||
touch file1.txt
|
||||
testcmd "-i" "-i" "$(stat -c %i file1.txt) file1.txt\n" "" ""
|
||||
testcmd "missing" "does-not-exist 2>&1 >/dev/null | grep -o does-not-exist" \
|
||||
"does-not-exist\n" "" ""
|
||||
rm -f file1.txt
|
||||
|
||||
testing "missing" "$IN && ls does-not-exist 2>err ; grep -q 'ls:.*missing.*: No
|
||||
such file' err || echo missing error; $OUT" "" "" ""
|
||||
# sort tests
|
||||
TIME=1234567890
|
||||
for i in one two three four five six seven eight nine ten
|
||||
do touch -d @$((TIME++)) $i
|
||||
done
|
||||
testcmd "" "-r" "two\nthree\nten\nsix\nseven\none\nnine\nfour\nfive\neight\n" \
|
||||
"" ""
|
||||
testcmd "-w test 1" "-Cw 20" \
|
||||
"eight one three\nfive seven two\nfour six\nnine ten\n" "" ""
|
||||
testcmd "-w test 2" "-Cw 19" \
|
||||
"eight seven\nfive six\nfour ten\nnine three\none two\n" "" ""
|
||||
rm -f one two three four five six seven eight nine ten
|
||||
|
||||
# Removing test dir for cleanup purpose
|
||||
rm -rf lstest
|
||||
touch a b c d e f
|
||||
testcmd "-w test 3" "-Cw 3" "a\nb\nc\nd\ne\nf\n" "" ""
|
||||
testcmd "-w test 4" "-Cw 4" "a d\nb e\nc f\n" "" ""
|
||||
rm -f a b c d e f
|
||||
|
||||
touch 'hello
|
||||
world'
|
||||
testcmd "default escaping" "" "hello
|
||||
world\n" "" ""
|
||||
testcmd "" "-b" 'hello\\ \\rworld\n' "" ""
|
||||
testcmd "" "-q" 'hello ?world\n' "" ""
|
||||
testcmd "" "-N" 'hello
|
||||
world\n' "" ""
|
||||
# testcmd "" "-qN" 'hello ?world\n' "" "" behaves differently, and ok with it.
|
||||
rm hello*
|
||||
|
||||
mkdir zzz dir && echo hello > xxx && sleep .05 && echo longer > abc
|
||||
# pause because filesystem granularity may be "jiffies".
|
||||
X=999; for i in abc x abc.jkl zzz xxx Abc cde.def dir bcd.ghi
|
||||
do sleep .05; touch -d @$((X--)) $i; done
|
||||
|
||||
# MacOS filesystems are case insensitive, so Abc and abc can't coexist.
|
||||
[ "$(uname)" == Darwin ] && SKIP=999
|
||||
testcmd '' '--group-directories-first' \
|
||||
'dir\nzzz\nAbc\nabc\nabc.jkl\nbcd.ghi\ncde.def\nx\nxxx\n' '' ''
|
||||
testcmd '' '-cr' 'abc\nx\nabc.jkl\nzzz\nxxx\nAbc\ncde.def\ndir\nbcd.ghi\n' '' ''
|
||||
testcmd '' '-tr' 'bcd.ghi\ndir\ncde.def\nAbc\nxxx\nzzz\nabc.jkl\nx\nabc\n' '' ''
|
||||
testcmd '' '-S --group-directories-first' 'dir\nzzz\nabc\nxxx\nAbc\nabc.jkl\nbcd.ghi\ncde.def\nx\n' '' ''
|
||||
testcmd '' '-X' 'Abc\nabc\ndir\nx\nxxx\nzzz\ncde.def\nbcd.ghi\nabc.jkl\n' '' ''
|
||||
testcmd '-U matches -f' '-aU1' "$("$C" -f1)\n" '' ''
|
||||
# -ltu sorts by atime, -lu shows atime but sorts by name (same for -oc/-otc)
|
||||
TZ=utc testcmd '-ou' '-ou --full-time . | sed -n "s/.*:\([0-9]*\).*/\1/p"' \
|
||||
'34\n39\n37\n31\n33\n32\n38\n35\n36\n' '' ''
|
||||
TZ=utc testcmd '-otu' '-otu --full-time . | sed -n "s/.*:\([0-9]*\).*/\1/p"' \
|
||||
'39\n38\n37\n36\n35\n34\n33\n32\n31\n' '' ''
|
||||
|
||||
+29
-25
@@ -4,35 +4,39 @@
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
# lsattr - Testcases
|
||||
mkdir dir && cd dir && touch file
|
||||
|
||||
chattr +A file &>/dev/null
|
||||
_A='-------A------------'
|
||||
_d='--------------------'
|
||||
|
||||
_p=$PWD
|
||||
_b="-------------"
|
||||
_A="-------A-----"
|
||||
function clean()
|
||||
{
|
||||
# We don't know whether the fs will have extents (e, typically true on the
|
||||
# desktop) or be encrypted (E, typically true on Android), or have data
|
||||
# inlined in the inode (N), or use indexed directories, so strip those out.
|
||||
# We also don't want to rely on chattr(1) to set a known version number or
|
||||
# project number, so blank out any numbers.
|
||||
sed -E -e 's/, (Encrypted|Extents|Indexed_directory|Inline_Data)//g;' \
|
||||
-e 's/[EeIN]-/--/g; s/[0-9]+/_/g'
|
||||
}
|
||||
|
||||
testing "file" "lsattr file" "$_A file\n" "" ""
|
||||
testing "file_path" "lsattr $_p/file" "$_A $_p/file\n" "" ""
|
||||
testing "-R file" "lsattr -R file" "$_A file\n" "" ""
|
||||
testing "-R file_path" "lsattr -R $_p/file" "$_A $_p/file\n" "" ""
|
||||
testing "-a file" "lsattr -a file" "$_A file\n" "" ""
|
||||
testing "-a file_path" "lsattr -a $_p/file" "$_A $_p/file\n" "" ""
|
||||
testing "-d ." "lsattr -d ." "$_b .\n" "" ""
|
||||
testing "-d dir_path" "lsattr -d $_p" "$_b $_p\n" "" ""
|
||||
testing "-d file" "lsattr -d file" "$_A file\n" "" ""
|
||||
testing "-d file_path" "lsattr -d $_p/file" "$_A $_p/file\n" "" ""
|
||||
sp_44=" "
|
||||
testing "-l file" "lsattr -l file" "file $sp_44 No_Atime\n" "" ""
|
||||
_v="12345"
|
||||
testing "-v file" "chattr -v $_v * && lsattr -v file" \
|
||||
"$_v $_A file\n" "" ""
|
||||
testing "-v file_path" "chattr -v $_v * && lsattr -v $_p/file" \
|
||||
"$_v $_A $_p/file\n" "" ""
|
||||
testing "-Radlv file1 file2" "chattr -v $_v * &&
|
||||
lsattr -Radlv file input" \
|
||||
"$_v file $sp_44 No_Atime\n$_v input $sp_44 ---\n" "" ""
|
||||
testing "file" "lsattr file | clean" "$_A file\n" "" ""
|
||||
testing "-R file" "lsattr -R file | clean" "$_A file\n" "" ""
|
||||
testing "-a file" "lsattr -a file | clean" "$_A file\n" "" ""
|
||||
testing "-d ." "lsattr -d . | clean" "$_d .\n" "" ""
|
||||
testing "-d file" "lsattr -d file | clean" "$_A file\n" "" ""
|
||||
NOSPACE=1 testing "-l file" "lsattr -l file | clean" "file No_Atime\n" "" ""
|
||||
NOSPACE=1 testing "-v file" "lsattr -v file | clean" "_ $_A file\n" "" ""
|
||||
NOSPACE=1 testing "-lv file" "lsattr -lv file | clean" "_ file No_Atime\n" "" ""
|
||||
|
||||
# You need at least Linux 4.5 plus file system support for project ids.
|
||||
lsattr -p file >/dev/null 2>&1 || SKIP=999
|
||||
NOSPACE=1 testing "-p file" "lsattr -p file | clean" "_ $_A file\n" "" ""
|
||||
NOSPACE=1 testing "-lp file" "lsattr -lp file | clean" "_ file No_Atime\n" \
|
||||
"" ""
|
||||
NOSPACE=1 testing "-vp file" "lsattr -vp file | clean" "_ _ $_A file\n" "" ""
|
||||
SKIP=0
|
||||
|
||||
# Cleanup
|
||||
chattr -AacDdijsStTu file && cd ..
|
||||
rm -rf dir
|
||||
|
||||
+6
-1
@@ -8,10 +8,15 @@ testing "mkdir" "mkdir one && [ -d one ] && echo yes" "yes\n" "" ""
|
||||
rmdir one
|
||||
|
||||
touch existing
|
||||
testing "existing" \
|
||||
testing "existing file" \
|
||||
"mkdir existing 2> /dev/null || [ -f existing ] && echo yes" "yes\n" "" ""
|
||||
rm existing
|
||||
|
||||
mkdir existing
|
||||
testing "existing dir" \
|
||||
"mkdir existing 2> /dev/null || echo yes" "yes\n" "" ""
|
||||
rmdir existing
|
||||
|
||||
testing "one two" \
|
||||
"mkdir one two && [ -d one ] && [ -d two ] && echo yes" "yes\n" "" ""
|
||||
rmdir one two
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
[ -f testing.sh ] && . testing.sh
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
# TODO: migrate to internal hashes. Not sure I'm bothering with DES, so
|
||||
# this (currently) only tests md5, sha256, and sha512.
|
||||
# The -P0 is because debian's version misbehaves without it.
|
||||
testcmd 'md5' '-P0 -mmd5 -S abcdefgh' '$1$abcdefgh$G//4keteveJp0qb8z2DxG/\n' \
|
||||
'' 'password'
|
||||
# No idea why debian's requires the dash in sha-256?
|
||||
testcmd 'sha256-8' '-P0 -msha-256 -S abcdefgh' \
|
||||
'$5$abcdefgh$ZLdkj8mkc2XVSrPVjskDAgZPGjtj1VGVaa1aUkrMTU/\n' '' 'password'
|
||||
testcmd 'sha256-16' '-P0 -msha-256 -S ./Aa0Bb1Cc2Dd3Ee' \
|
||||
'$5$./Aa0Bb1Cc2Dd3Ee$5iXcesTggTRGvAAa3cWlpxmUqNGOeQh/iO3Furo4y/D\n' '' \
|
||||
'password'
|
||||
testcmd 'sha512-8' '-P0 -msha-512 -S abcdefgh' \
|
||||
'$6$abcdefgh$yVfUwsw5T.JApa8POvClA1pQ5peiq97DUNyXCZN5IrF.BMSkiaLQ5kvpuEm/VQ1Tvh/KV2TcaWh8qinoW5dhA1\n' \
|
||||
'' 'password'
|
||||
testcmd 'sha512-16' '-P0 -msha-512 -S ./Aa0Bb1Cc2Dd3Ee' \
|
||||
'$6$./Aa0Bb1Cc2Dd3Ee$PvmedaPf329sM25Jn2jv3MsfK9DaDh6tyVtJucp35A/Lmrtp9g1Ab35Mr59pkuMU3QJlbXYoWJFaxyD4OwIZ60\n' \
|
||||
'' 'password'
|
||||
+16
-14
@@ -5,32 +5,34 @@
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
# Android keeps its modules (if any) on the vendor partition.
|
||||
MODULE_ROOT=""
|
||||
[ -d /vendor/lib/modules ] && MODULE_ROOT="/vendor"
|
||||
# Don't need to quote variable expansions: no kernel version or
|
||||
# module name should ever have a space in it.
|
||||
MODULE_ROOT=/vendor/lib/modules
|
||||
[ -d $MODULE_ROOT ] || MODULE_ROOT=/lib/modules/$(uname -r)
|
||||
|
||||
if [[ ! -e /proc/modules || ! -d $MODULE_ROOT/lib/modules ]]; then
|
||||
no_modules() {
|
||||
echo "$SHOWSKIP: modinfo (no modules)"
|
||||
return 2>/dev/null
|
||||
exit
|
||||
fi
|
||||
}
|
||||
|
||||
testcmd "missing" "missing 2>&1" "modinfo: missing: not found\n" "" ""
|
||||
[[ ! -e /proc/modules || ! -d $MODULE_ROOT ]] && no_modules
|
||||
|
||||
# Find some modules to work with.
|
||||
MODULE_PATH1=$(find $MODULE_ROOT/lib/modules -name *.ko | head -1 2>/dev/null)
|
||||
# Don't need to quote wildcards because test runs in an empty dir.
|
||||
MODULE_PATH1=$(find $MODULE_ROOT -name *.ko | head -1)
|
||||
[ ! -e "$MODULE_PATH1" ] && no_modules
|
||||
MODULE1=$(basename -s .ko $MODULE_PATH1)
|
||||
MODULE_PATH2=$(find $MODULE_ROOT/lib/modules -name *.ko | tail -1 2>/dev/null)
|
||||
MODULE_PATH2=$(find $MODULE_ROOT -name *.ko | head -2 | tail -1)
|
||||
MODULE2=$(basename -s .ko $MODULE_PATH2)
|
||||
DASH_MODULE=$(basename -s .ko \
|
||||
$(find $MODULE_ROOT/lib/modules -name *-*.ko | tail -1 2>/dev/null))
|
||||
BAR_MODULE=$(basename -s .ko \
|
||||
$(find $MODULE_ROOT/lib/modules -name *_*.ko | tail -1 2>/dev/null))
|
||||
DASH_MODULE=$(basename -s .ko $(find $MODULE_ROOT -name *-*.ko | tail -1))
|
||||
BAR_MODULE=$(basename -s .ko $(find $MODULE_ROOT -name *_*.ko | tail -1))
|
||||
|
||||
testcmd "missing" "missing 2>&1" "modinfo: missing: not found\n" "" ""
|
||||
|
||||
# modinfo does not need to output fields in a specified order.
|
||||
# Instead, there are labelled fields. We can use sort to make up for this.
|
||||
# Other issues to beware of are the volatile nature of srcversion and vermagic,
|
||||
# which change from kernel to kernel and can be disabled.
|
||||
# We grep to remove these.
|
||||
# which change from kernel to kernel and can be disabled: grep to remove these.
|
||||
|
||||
skipnot [ -n "$DASH_MODULE" ]
|
||||
testing "treats - and _ as equivalent" "modinfo $DASH_MODULE > dash-dash &&
|
||||
|
||||
+2
-2
@@ -47,8 +47,8 @@ testing "-w $tmp_b_fs /mnt (write_only mode)" \
|
||||
sleep 1 && umount /mnt && ! test -e /mnt/testDir" "" "" ""
|
||||
reCreateTmpFs
|
||||
testing "-rw $tmp_b_fs /mnt (read_write mode)" \
|
||||
'mount -rw $tmp_b_fs /mnt >/dev/null && mkdir /mnt/testDir && \
|
||||
sleep 1 && ! test -e /mnt/testDir && umount /mnt' "" "" ""
|
||||
"mount -rw $tmp_b_fs /mnt >/dev/null && mkdir /mnt/testDir && \
|
||||
sleep 1 && ! test -e /mnt/testDir && umount /mnt" "" "" ""
|
||||
reCreateTmpFs
|
||||
testing "$tmp_b_fs /mnt -t fs_type" \
|
||||
"mount $tmp_b_fs /mnt -t $tmp_b_fs_type >/dev/null 2>&1 &&
|
||||
|
||||
+2
-18
@@ -135,32 +135,16 @@ testing "no clobber (dest doesn't exist)" \
|
||||
"yes\n" "" ""
|
||||
rm -f file*
|
||||
|
||||
# If there is stdin, it prompts. If no stdin, it moves anyway and file2 won't
|
||||
# exist.
|
||||
touch file1 file2
|
||||
chmod 400 file1 file2
|
||||
testing "mv over unwritable file: no stdin" \
|
||||
testing "over unwritable file only prompts when stdin is a terminal" \
|
||||
"mv file2 file1 2>/dev/null && [ -e file1 -a ! -e file2 ] && echo yes" \
|
||||
"yes\n" "" ""
|
||||
rm -f file*
|
||||
|
||||
touch file1 file2
|
||||
chmod 400 file1 file2
|
||||
testing "mv over unwritable file: answered YES" \
|
||||
"mv file2 file1 2>/dev/null && [ -e file1 -a ! -e file2 ] && echo yes" \
|
||||
"yes\n" "" "y\n"
|
||||
rm -f file*
|
||||
|
||||
touch file1 file2
|
||||
chmod 400 file1 file2
|
||||
testing "mv over unwritable file: answered NO" \
|
||||
"mv file2 file1 2>/dev/null && [ -e file1 -a -e file2 ] && echo yes" \
|
||||
"yes\n" "" "n\n"
|
||||
rm -f file*
|
||||
|
||||
touch file1 file2
|
||||
testing "interactive: no stdin" \
|
||||
"mv -i file2 file1 2>/dev/null && [ -e file1 -a ! -e file2 ] && echo yes" \
|
||||
"mv -i file2 file1 2>/dev/null && [ -e file1 -a -e file2 ] && echo yes" \
|
||||
"yes\n" "" ""
|
||||
rm -f file*
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
#!/bin/bash
|
||||
|
||||
[ -f testing.sh ] && . testing.sh
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
if [ "$(id -u)" -ne 0 ]
|
||||
then
|
||||
echo "$SHOWSKIP: nbd-client (not root)"
|
||||
return 2>/dev/null
|
||||
exit
|
||||
fi
|
||||
|
||||
# Test filesystem images
|
||||
|
||||
# truncate -s256k ext2.img; mke2fs ext2.img; bzip2 < ext2.img | base64
|
||||
base64 -d | bzcat > ext2.img << EOF
|
||||
QlpoOTFBWSZTWbBa6EkAABn//////0BEGVhI8AFKBR1FzqBiBACiQgFgAEgAAhVAZ4QMsAEYJEFN
|
||||
I0AA0AAAABoGgAGmg2ppkHMJoDQGjRhGgxGmJkxNBhGgZAMmAkiSamj0I9BMmmmEaAAAANADQGmI
|
||||
Vsb7iiy5kJkdeO7Nijja84iwwpZrgb1C54RIVpgQISiSGEk87UjHU9lMEUdeBNZVp2dNZqlfPsaF
|
||||
m1bufdAsy3r0SJadGCGluQKTCBABVYyGSUjCNaq4AABbuvG2UToQVhiJkSMCCV3QCADJbdvuYpjo
|
||||
vsnYkYkIFnzihj/ICWNlSoOYMLqmT3wO4C5ZCEAztpmAFCV0rUUwIgcB45oB+8iI/vtvYqkkWU7T
|
||||
QiPrkylDZYYRPFZQUFGmgRAFgwEygDC+o7xtv26GOcRFYzdlo2G5i0Yg1WxsQYQJJJhfrCP6DgGA
|
||||
VSH+LuSKcKEhYLXQkg==
|
||||
EOF
|
||||
|
||||
tuncate -s360k fat.img; mkfs.fat fat.img; bzip2 < fat.img | base64
|
||||
base64 -d | bzcat > fat.img << EOF
|
||||
QlpoOTFBWSZTWRzu2ngAC6j/v/C7YaDQITAEIwPHCTfv3CRAQAAUBAlAAkAABAhAC7AAu2oampqP
|
||||
SMgAGmmgAAM1AaZGE8oNU8lPU2piDQBoADQAGgaHpPUaBlIjaQAaAGgA0yaaMJk0Bo0KfAsgEkgE
|
||||
j8EGgCSAQSEwpVSi2ik+oAQCC0FJOUzrkxZikHndRLY4URVk3SAv4kdIUvCMR7xxaNBFDI63CTTL
|
||||
+9TioH4KEDXJDB1p4/uaA4CiIOROg4eLOL5FJBAk24CR6KFRyRLEdFnt1RnVbD9PKNZduYsKfdFB
|
||||
5xE1ErWAhXDDdJmXHoknmTLMhczHhSlJogGAMDGDxLOsTj+LuSKcKEgOd208AA==
|
||||
EOF
|
||||
|
||||
|
||||
|
||||
dd if=
|
||||
testcmd "
|
||||
|
||||
echo "one" > file1
|
||||
echo "two" > file2
|
||||
testing "cat" "cat && echo yes" "oneyes\n" "" "one"
|
||||
testing "-" "cat - && echo yes" "oneyes\n" "" "one"
|
||||
testing "file1 file2" "cat file1 file2" "one\ntwo\n" "" ""
|
||||
testing "- file" "cat - file1" "zero\none\n" "" "zero\n"
|
||||
testing "file -" "cat file1 -" "one\nzero\n" "" "zero\n"
|
||||
|
||||
testing "file1 notfound file2" \
|
||||
"cat file1 notfound file2 2>stderr && echo ok ; cat stderr; rm stderr" \
|
||||
"one\ntwo\ncat: notfound: No such file or directory\n" "" ""
|
||||
|
||||
testing "binary" \
|
||||
'cat "$C" > file1 && cmp "$C" file1 && echo yes' "yes\n" "" ""
|
||||
|
||||
testing "- file1" \
|
||||
"cat - file1 | diff -a -U 0 - file1 | tail -n 1" \
|
||||
"-hello\n" "" "hello\n"
|
||||
|
||||
skipnot [ -e /dev/full ]
|
||||
testing "> /dev/full" \
|
||||
"cat - > /dev/full 2>/dev/null || echo failed" \
|
||||
"failed\n" "" "zero\n"
|
||||
|
||||
rm file1 file2
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
[ -f testing.sh ] && . testing.sh
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
{ dd if=/dev/zero bs=4k count=1 2>/dev/null | tr '\0' a; echo b; } > testfile
|
||||
testing "more than buffer bytes left at end" \
|
||||
"netcat -lp 1234 wc -c & sleep .1 && cat testfile | netcat 127.0.0.1 1234" \
|
||||
"4098\n" "" ""
|
||||
rm -f testfile
|
||||
+2
-1
@@ -52,4 +52,5 @@ testing "-l" "nl -ba -l2 -w2 - input" \
|
||||
testing "no space" "nl -w 1 -v 42" "42\tline\n" "" "line\n"
|
||||
|
||||
# Should test for -E but no other implementation seems to have it?
|
||||
#testing "-E" "nl -w2 -sx -Ebp'(one|two)'" " 1x" "one\nand\ntwo\n"
|
||||
toyonly testing "-E" "nl -w2 -sx -Ebp'(one|two)'" " 1xone\n and\n 2xtwo\n" \
|
||||
"" "one\nand\ntwo\n"
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
#!/bin/bash
|
||||
|
||||
[ -f testing.sh ] && . testing.sh
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
testing "dry run doesn't create file" \
|
||||
"patch --dry-run >/dev/null && [ ! -e bork ] && echo yes" "yes\n" "" "
|
||||
--- /dev/null
|
||||
+++ bork
|
||||
@@ -0,0 +1,1 @@
|
||||
+one
|
||||
"
|
||||
|
||||
testing "create file" "patch >/dev/null && cat bork" "one\ntwo\nthree\n" "" "
|
||||
--- /dev/null
|
||||
+++ bork
|
||||
@@ -0,0 +1,3 @@
|
||||
+one
|
||||
+two
|
||||
+three
|
||||
"
|
||||
|
||||
testing "insert in middle" "patch > /dev/null && cat bork" \
|
||||
"one\nfour\ntwo\nthree\n" "" "
|
||||
--- bork
|
||||
+++ bork
|
||||
@@ -1,3 +1,4 @@
|
||||
one
|
||||
+four
|
||||
two
|
||||
three
|
||||
"
|
||||
testing "append at end" "patch > /dev/null && cat bork" \
|
||||
"one\nfour\ntwo\nthree\nfive\nsix\n" "" "
|
||||
--- bork
|
||||
+++ bork
|
||||
@@ -2,3 +2,5 @@
|
||||
four
|
||||
two
|
||||
three
|
||||
+five
|
||||
+six
|
||||
"
|
||||
testing "insert at start" "patch > /dev/null && cat bork" \
|
||||
"seven\none\nfour\ntwo\nthree\nfive\nsix\n" "" "
|
||||
--- bork
|
||||
+++ bork
|
||||
@@ -1,3 +1,4 @@
|
||||
+seven
|
||||
one
|
||||
four
|
||||
two
|
||||
"
|
||||
testing "delete at end" "patch > /dev/null && cat bork" \
|
||||
"seven\none\nfour\ntwo\nthree\nfive\n" "" "
|
||||
--- bork
|
||||
+++ bork
|
||||
@@ -4,4 +4,3 @@
|
||||
two
|
||||
three
|
||||
five
|
||||
-six
|
||||
"
|
||||
|
||||
testing "delete at start" "patch > /dev/null && cat bork" \
|
||||
"four\ntwo\nthree\nfive\n" "" "
|
||||
--- bork
|
||||
+++ bork
|
||||
@@ -1,5 +1,3 @@
|
||||
-seven
|
||||
-one
|
||||
four
|
||||
two
|
||||
three
|
||||
"
|
||||
|
||||
testing "filter timestamps" "patch > /dev/null && cat bork" \
|
||||
"four\ntwo\nthree\neight\nfive\n" "" "
|
||||
--- bork 2019-12-20 16:54:35.735630973 -0600
|
||||
+++ bork 2019-12-20 16:57:03.083625706 -0600
|
||||
@@ -1,4 +1,5 @@
|
||||
four
|
||||
two
|
||||
three
|
||||
+eight
|
||||
five
|
||||
"
|
||||
|
||||
testing "quoted name" "patch > /dev/null && cat 'fruit bat'" \
|
||||
"hello\n" "" '
|
||||
--- /dev/null
|
||||
+++ "fruit ba\164"
|
||||
@@ -0,0 +1 @@
|
||||
+hello
|
||||
'
|
||||
|
||||
testing "bad quote" "patch 2>&1" $'patch: bad "filename\n' "" '--- "filename'
|
||||
|
||||
testing "dry run doesn't delete file" \
|
||||
"patch --dry-run > /dev/null && [ -e 'fruit bat' ] && echo yes" "yes\n" "" '
|
||||
--- "fruit bat"
|
||||
+++ /dev/null
|
||||
@@ -1 +0,0 @@
|
||||
-hello
|
||||
'
|
||||
|
||||
testing "delete file" \
|
||||
"patch > /dev/null && [ ! -e 'fruit bat' ] && echo yes" "yes\n" "" '
|
||||
--- "fruit bat"
|
||||
+++ /dev/null
|
||||
@@ -1 +0,0 @@
|
||||
-hello
|
||||
'
|
||||
|
||||
# todo bork bork2
|
||||
|
||||
# We hit a bug, test the bugfix.
|
||||
testing "fuzz" "patch > /dev/null && cat input" \
|
||||
"blah blah
|
||||
*/
|
||||
package org.yaml.snakeyaml.representer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
" "blah blah
|
||||
*/
|
||||
package org.yaml.snakeyaml.representer;
|
||||
|
||||
import java.beans.IntrospectionException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
" "--- a/x/input
|
||||
+++ b/x/input
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.yaml.snakeyaml.representer;
|
||||
|
||||
-import java.beans.IntrospectionException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
"
|
||||
+3
-2
@@ -8,7 +8,8 @@
|
||||
# pidof (unlike killall) doesn't match argv[1] unless you supply -x.
|
||||
#
|
||||
|
||||
echo -e "#!$(which sh)\nread i < /proc/self/fd/1" > pidof-$$.test
|
||||
mkfifo fifo
|
||||
echo -e "#!$(which sh)\nread i < fifo" > pidof-$$.test
|
||||
chmod a+x pidof-$$.test
|
||||
cp pidof-$$.test toybox.pidof-$$.test.script
|
||||
(./pidof-$$.test & echo $! > pid.txt)
|
||||
@@ -23,7 +24,7 @@ testcmd "long argv[1]" "toybox.pidof-$$.test.script" "" "" ""
|
||||
testcmd "long argv[1] -x" "-x toybox.pidof-$$.test.script" "$pid\n" "" ""
|
||||
kill $pid
|
||||
|
||||
rm -f toybox.pidof-$$.test.script pidof-$$.test pid.txt
|
||||
rm -f toybox.pidof-$$.test.script pidof-$$.test pid.txt fifo
|
||||
|
||||
# pidof (unlike killall) will match itself.
|
||||
testcmd "pidof pidof" "pidof > /dev/null && echo found" "found\n" "" ""
|
||||
|
||||
+49
-46
@@ -7,73 +7,74 @@
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
# Disable shell builtin
|
||||
PRINTF="$(which printf)"
|
||||
# Note: must use "testcmd" not "testing" else it's testing the shell builtin.
|
||||
|
||||
testing "text" "$PRINTF TEXT" "TEXT" "" ""
|
||||
testing "escapes" "$PRINTF 'one\ntwo\n\v\t\r\f\e\b\athree'" \
|
||||
"one\ntwo\n\v\t\r\f\e\b\athree" "" ""
|
||||
testing "%b escapes" "$PRINTF %b 'one\ntwo\n\v\t\r\f\e\b\athree'" \
|
||||
"one\ntwo\n\v\t\r\f\e\b\athree" "" ""
|
||||
testing "null" "$PRINTF 'x\0y' | od -An -tx1" ' 78 00 79\n' "" ""
|
||||
testing "trailing slash" "$PRINTF 'abc\'" 'abc\' "" ""
|
||||
testing "octal" "$PRINTF ' \1\002\429\045x'" ' \001\002"9%x' "" ""
|
||||
testing "not octal" "$PRINTF '\9'" '\9' "" ""
|
||||
testing "hex" "$PRINTF 'A\x1b\x2B\x3Q\xa' | od -An -tx1" \
|
||||
' 41 1b 2b 03 51 0a\n' "" ""
|
||||
testing "%x" "$PRINTF '%x\n' 0x2a" "2a\n" "" ""
|
||||
testcmd "text" "TEXT" "TEXT" "" ""
|
||||
|
||||
testing "%d 42" "$PRINTF %d 42" "42" "" ""
|
||||
testing "%d 0x2a" "$PRINTF %d 0x2a" "42" "" ""
|
||||
testing "%d 052" "$PRINTF %d 052" "42" "" ""
|
||||
# TODO: we have to use \x1b rather than \e in the expectations because
|
||||
# the Mac is stuck on bash 3.2 which doesn't support \e. This can go
|
||||
# away when we have a usable toysh.
|
||||
testcmd "escapes" "'one\ntwo\n\v\t\r\f\e\b\athree'" \
|
||||
"one\ntwo\n\v\t\r\f\x1b\b\athree" "" ""
|
||||
testcmd "%b escapes" "%b 'one\ntwo\n\v\t\r\f\e\b\athree'" \
|
||||
"one\ntwo\n\v\t\r\f\x1b\b\athree" "" ""
|
||||
|
||||
testing "%s width precision" \
|
||||
"$PRINTF '%3s,%.3s,%10s,%10.3s' abcde fghij klmno pqrst" \
|
||||
testcmd "null" "'x\0y' | od -An -tx1" ' 78 00 79\n' "" ""
|
||||
testcmd "trailing slash" "'abc\'" 'abc\' "" ""
|
||||
testcmd "octal" "' \1\002\429\045x'" ' \001\002"9%x' "" ""
|
||||
testcmd "not octal" "'\9'" '\9' "" ""
|
||||
testcmd "hex" "'A\x1b\x2B\x3Q\xa' | od -An -tx1" ' 41 1b 2b 03 51 0a\n' "" ""
|
||||
testcmd "%x" "'%x\n' 0x2a" "2a\n" "" ""
|
||||
|
||||
testcmd "%d 42" "%d 42" "42" "" ""
|
||||
testcmd "%d 0x2a" "%d 0x2a" "42" "" ""
|
||||
testcmd "%d 052" "%d 052" "42" "" ""
|
||||
testcmd "%d none" "%d" "0" "" ""
|
||||
testcmd "%d null" "%d ''" "0" "" ""
|
||||
|
||||
testcmd "%s width precision" "'%3s,%.3s,%10s,%10.3s' abcde fghij klmno pqrst" \
|
||||
"abcde,fgh, klmno, pqr" "" ""
|
||||
|
||||
# posix: "The format operand shall be reused as often as necessary to satisfy
|
||||
# the argument operands."
|
||||
|
||||
testing "extra args" "$PRINTF 'abc%s!%ddef\n' X 42 ARG 36" \
|
||||
testcmd "extra args" "'abc%s!%ddef\n' X 42 ARG 36" \
|
||||
"abcX!42def\nabcARG!36def\n" "" ""
|
||||
|
||||
testing "'%3c'" "$PRINTF '%3c' x" " x" "" ""
|
||||
testing "'%-3c'" "$PRINTF '%-3c' x" "x " "" ""
|
||||
testing "'%+d'" "$PRINTF '%+d' 5" "+5" "" ""
|
||||
testcmd "'%3c'" "'%3c' x" " x" "" ""
|
||||
testcmd "'%-3c'" "'%-3c' x" "x " "" ""
|
||||
testcmd "'%+d'" "'%+d' 5" "+5" "" ""
|
||||
|
||||
|
||||
testing "'%5d%4d' 1 21 321 4321 54321" \
|
||||
"$PRINTF '%5d%4d' 1 21 321 4321 54321" " 1 21 321432154321 0" "" ""
|
||||
testing "'%c %c' 78 79" "$PRINTF '%c %c' 78 79" "7 7" "" ""
|
||||
testing "'%d %d' 78 79" "$PRINTF '%d %d' 78 79" "78 79" "" ""
|
||||
testing "'%f %f' 78 79" "$PRINTF '%f %f' 78 79" \
|
||||
"78.000000 79.000000" "" ""
|
||||
testing "'f f' 78 79" "$PRINTF 'f f' 78 79 2>/dev/null" "f f" "" ""
|
||||
testing "'%i %i' 78 79" "$PRINTF '%i %i' 78 79" "78 79" "" ""
|
||||
testing "'%o %o' 78 79" "$PRINTF '%o %o' 78 79" "116 117" "" ""
|
||||
testing "'%u %u' 78 79" "$PRINTF '%u %u' 78 79" "78 79" "" ""
|
||||
testing "'%u %u' -1 -2" "$PRINTF '%u %u' -1 -2" \
|
||||
testcmd "'%5d%4d' 1 21 321 4321 54321" \
|
||||
"'%5d%4d' 1 21 321 4321 54321" " 1 21 321432154321 0" "" ""
|
||||
testcmd "'%c %c' 78 79" "'%c %c' 78 79" "7 7" "" ""
|
||||
testcmd "'%d %d' 78 79" "'%d %d' 78 79" "78 79" "" ""
|
||||
testcmd "'%f %f' 78 79" "'%f %f' 78 79" "78.000000 79.000000" "" ""
|
||||
testcmd "'f f' 78 79" "'f f' 78 79 2>/dev/null" "f f" "" ""
|
||||
testcmd "'%i %i' 78 79" "'%i %i' 78 79" "78 79" "" ""
|
||||
testcmd "'%o %o' 78 79" "'%o %o' 78 79" "116 117" "" ""
|
||||
testcmd "'%u %u' 78 79" "'%u %u' 78 79" "78 79" "" ""
|
||||
testcmd "'%u %u' -1 -2" "'%u %u' -1 -2" \
|
||||
"18446744073709551615 18446744073709551614" "" ""
|
||||
testing "'%x %X' 78 79" "$PRINTF '%x %X' 78 79" "4e 4F" "" ""
|
||||
testing "'%g %G' 78 79" "$PRINTF '%g %G' 78 79" "78 79" "" ""
|
||||
testing "'%s %s' 78 79" "$PRINTF '%s %s' 78 79" "78 79" "" ""
|
||||
testcmd "'%x %X' 78 79" "'%x %X' 78 79" "4e 4F" "" ""
|
||||
testcmd "'%g %G' 78 79" "'%g %G' 78 79" "78 79" "" ""
|
||||
testcmd "'%s %s' 78 79" "'%s %s' 78 79" "78 79" "" ""
|
||||
|
||||
testing "%.s acts like %.0s" "$PRINTF %.s_ 1 2 3 4 5" "_____" "" ""
|
||||
testing "corner case" "$PRINTF '\\8'" '\8' '' ''
|
||||
testcmd "%.s acts like %.0s" "%.s_ 1 2 3 4 5" "_____" "" ""
|
||||
testcmd "corner case" "'\\8'" '\8' '' ''
|
||||
|
||||
# The posix spec explicitly specifies inconsistent behavior,
|
||||
# so treating the \0066 in %b like the \0066 not in %b is wrong because posix.
|
||||
testing "printf posix inconsistency" "$PRINTF '\\0066-%b' '\\0066'" "\x066-6" \
|
||||
testcmd "posix inconsistency" "'\\0066-%b' '\\0066'" "\x066-6" "" ""
|
||||
|
||||
testcmd '\x' "'A\x1b\x2B\x3Q\xa' | od -An -tx1" " 41 1b 2b 03 51 0a\n" \
|
||||
"" ""
|
||||
|
||||
testing "printf \x" "$PRINTF 'A\x1b\x2B\x3Q\xa' | od -An -tx1" \
|
||||
" 41 1b 2b 03 51 0a\n" "" ""
|
||||
|
||||
testing "printf \c" "$PRINTF 'one\ctwo'" "one" "" ""
|
||||
testcmd '\c' "'one\ctwo'" "one" "" ""
|
||||
|
||||
# An extra leading 0 is fine for %b, but not as a direct escape, for some
|
||||
# reason...
|
||||
testing "printf octal %b" "$PRINTF '\0007%b' '\0007' | xxd -p" "003707\n" "" ""
|
||||
testcmd "octal %b" "'\0007%b' '\0007' | xxd -p" "003707\n" "" ""
|
||||
|
||||
# Unlike echo, printf errors out on bad hex.
|
||||
testcmd "invalid hex 1" "'one\xvdtwo' 2>/dev/null || echo err" "oneerr\n" "" ""
|
||||
@@ -84,3 +85,5 @@ testcmd "invalid oct" "'one\079two'" "one\a9two" "" ""
|
||||
# extension for ESC
|
||||
testcmd "%b \e" "'%b' '\\e' | xxd -p" "1b\n" "" ""
|
||||
testcmd "\e" "'\\e' | xxd -p" "1b\n" "" ""
|
||||
|
||||
testcmd '\0 in %b' '%b ab\\x07\\0x07 | xxd -p' '61620700783037\n' '' ''
|
||||
|
||||
+2
-2
@@ -14,9 +14,9 @@ testing "-P" "[ $(stat -c %i "$(pwd -P)") = $(stat -c %i .) ] && echo yes" \
|
||||
|
||||
ln -s . sym
|
||||
cd sym
|
||||
testing "pwd" "[ $(stat -c %i "$(pwd)") = $(stat -c %i "$PWD") ] && echo yes" \
|
||||
testing "pwd2" "[ $(stat -c %i "$(pwd)") = $(stat -c %i "$PWD") ] && echo yes" \
|
||||
"yes\n" "" ""
|
||||
testing "-P" "[ $(stat -c %i "$(pwd -P)") = $(stat -c %i "$PWD") ] || echo yes" \
|
||||
testing "-P2" "[ $(stat -c %i "$(pwd -P)") = $(stat -c %i "$PWD") ] || echo yes" \
|
||||
"yes\n" "" ""
|
||||
cd ..
|
||||
rm sym
|
||||
|
||||
@@ -0,0 +1,256 @@
|
||||
#!/bin/bash
|
||||
|
||||
[ -f testing.sh ] && . testing.sh
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
elf=$FILES/elf/ndk-elf-note
|
||||
|
||||
# toybox uses Linux kernel architecture names, so rewrite binutils with sed.
|
||||
NOSPACE=1 testing "-h" "readelf -hW $elf-full | sed s/AArch64/arm64/g" \
|
||||
"ELF Header:
|
||||
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
|
||||
Class: ELF64
|
||||
Data: 2's complement, little endian
|
||||
Version: 1 (current)
|
||||
OS/ABI: UNIX - System V
|
||||
ABI Version: 0
|
||||
Type: DYN (Shared object file)
|
||||
Machine: arm64
|
||||
Version: 0x1
|
||||
Entry point address: 0x660
|
||||
Start of program headers: 64 (bytes into file)
|
||||
Start of section headers: 7776 (bytes into file)
|
||||
Flags: 0x0
|
||||
Size of this header: 64 (bytes)
|
||||
Size of program headers: 56 (bytes)
|
||||
Number of program headers: 9
|
||||
Size of section headers: 64 (bytes)
|
||||
Number of section headers: 32
|
||||
Section header string table index: 29
|
||||
" "" ""
|
||||
|
||||
# We format the key to flags differently and don't include obsolete ones.
|
||||
NOSPACE=1 testing "-S" "readelf -SW $elf-full | head -36" \
|
||||
"There are 32 section headers, starting at offset 0x1e60:
|
||||
|
||||
Section Headers:
|
||||
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
|
||||
[ 0] NULL 0000000000000000 000000 000000 00 0 0 0
|
||||
[ 1] .interp PROGBITS 0000000000000238 000238 000015 00 A 0 0 1
|
||||
[ 2] .note.android.ident NOTE 0000000000000250 000250 000098 00 A 0 0 4
|
||||
[ 3] .note.gnu.build-id NOTE 00000000000002e8 0002e8 000024 00 A 0 0 4
|
||||
[ 4] .hash HASH 0000000000000310 000310 000048 04 A 5 0 8
|
||||
[ 5] .dynsym DYNSYM 0000000000000358 000358 000138 18 A 6 3 8
|
||||
[ 6] .dynstr STRTAB 0000000000000490 000490 000097 00 A 0 0 1
|
||||
[ 7] .gnu.version VERSYM 0000000000000528 000528 00001a 02 A 5 0 2
|
||||
[ 8] .gnu.version_r VERNEED 0000000000000548 000548 000020 00 A 6 1 8
|
||||
[ 9] .rela.dyn RELA 0000000000000568 000568 000060 18 A 5 0 8
|
||||
[10] .rela.plt RELA 00000000000005c8 0005c8 000048 18 AI 5 19 8
|
||||
[11] .plt PROGBITS 0000000000000610 000610 000050 10 AX 0 0 16
|
||||
[12] .text PROGBITS 0000000000000660 000660 00008c 00 AX 0 0 4
|
||||
[13] .eh_frame_hdr PROGBITS 00000000000006ec 0006ec 000014 00 A 0 0 4
|
||||
[14] .eh_frame PROGBITS 0000000000000700 000700 000030 00 A 0 0 8
|
||||
[15] .preinit_array PREINIT_ARRAY 0000000000010d68 000d68 000010 08 WA 0 0 8
|
||||
[16] .init_array INIT_ARRAY 0000000000010d78 000d78 000010 08 WA 0 0 8
|
||||
[17] .fini_array FINI_ARRAY 0000000000010d88 000d88 000010 08 WA 0 0 8
|
||||
[18] .dynamic DYNAMIC 0000000000010d98 000d98 000210 10 WA 6 0 8
|
||||
[19] .got PROGBITS 0000000000010fa8 000fa8 000058 08 WA 0 0 8
|
||||
[20] .bss NOBITS 0000000000011000 001000 000008 00 WA 0 0 8
|
||||
[21] .comment PROGBITS 0000000000000000 001000 000107 01 MS 0 0 1
|
||||
[22] .debug_pubnames PROGBITS 0000000000000000 001107 00001b 00 0 0 1
|
||||
[23] .debug_info PROGBITS 0000000000000000 001122 00004b 00 0 0 1
|
||||
[24] .debug_abbrev PROGBITS 0000000000000000 00116d 000037 00 0 0 1
|
||||
[25] .debug_line PROGBITS 0000000000000000 0011a4 00003f 00 0 0 1
|
||||
[26] .debug_str PROGBITS 0000000000000000 0011e3 000138 01 MS 0 0 1
|
||||
[27] .debug_macinfo PROGBITS 0000000000000000 00131b 000001 00 0 0 1
|
||||
[28] .debug_pubtypes PROGBITS 0000000000000000 00131c 00001a 00 0 0 1
|
||||
[29] .shstrtab STRTAB 0000000000000000 001d0c 000151 00 0 0 1
|
||||
[30] .symtab SYMTAB 0000000000000000 001338 0007e0 18 31 68 8
|
||||
[31] .strtab STRTAB 0000000000000000 001b18 0001f4 00 0 0 1
|
||||
" "" ""
|
||||
|
||||
# Verify many section header flags display properly.
|
||||
NOSPACE=1 testing "-S flags" "readelf -SW $elf-shflags | head -32" \
|
||||
"There are 28 section headers, starting at offset 0xc74:
|
||||
|
||||
Section Headers:
|
||||
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
|
||||
[ 0] NULL 00000000 000000 000000 00 0 0 0
|
||||
[ 1] .interp PROGBITS 000001b4 0001b4 000013 00 A 0 0 1
|
||||
[ 2] .note.android.ident NOTE 000001c8 0001c8 000018 00 A 0 0 4
|
||||
[ 3] .note.gnu.build-id NOTE 000001e0 0001e0 000020 00 A 0 0 4
|
||||
[ 4] .dynsym DYNSYM 00000200 000200 000060 10 A 8 1 4
|
||||
[ 5] .gnu.version VERSYM 00000260 000260 00000c 02 A 4 0 2
|
||||
[ 6] .gnu.version_r VERNEED 0000026c 00026c 000020 00 A 8 1 4
|
||||
[ 7] .gnu.hash GNU_HASH 0000028c 00028c 000018 00 A 4 0 4
|
||||
[ 8] .dynstr STRTAB 000002a4 0002a4 000064 00 A 0 0 1
|
||||
[ 9] .rel.dyn ANDROID_REL 00000308 000308 00000d 01 A 4 0 4
|
||||
[10] .relr.dyn RELR 00000318 000318 00000c 04 A 0 0 4
|
||||
[11] .ARM.exidx ARM_EXIDX 00000324 000324 000028 00 AL 14 0 4
|
||||
[12] .rel.plt REL 0000034c 00034c 000020 08 AI 4 19 4
|
||||
[13] .rodata PROGBITS 0000036c 00036c 000015 01 AMS 0 0 1
|
||||
[14] .text PROGBITS 00001384 000384 0001c4 00 AX 0 0 4
|
||||
[15] .plt PROGBITS 00001550 000550 000060 00 AX 0 0 16
|
||||
[16] .tdata PROGBITS 000025c0 0005c0 000000 00 WAT 0 0 32
|
||||
[17] .dynamic DYNAMIC 000025c0 0005c0 0000d0 08 WA 8 0 4
|
||||
[18] .got PROGBITS 00002690 000690 000010 00 WA 0 0 4
|
||||
[19] .got.plt PROGBITS 000026a0 0006a0 00001c 00 WA 0 0 4
|
||||
[20] .data PROGBITS 000036bc 0006bc 00000c 00 WA 0 0 4
|
||||
[21] .comment PROGBITS 00000000 0006c8 0000cc 01 MS 0 0 1
|
||||
[22] .ARM.attributes ATTRIBUTES 00000000 000794 000042 00 0 0 1
|
||||
[23] .debug_frame PROGBITS 00000000 0007d8 00007a 00 C 0 0 4
|
||||
[24] .symtab SYMTAB 00000000 000854 000220 10 26 27 4
|
||||
[25] .shstrtab STRTAB 00000000 000a74 00010e 00 0 0 1
|
||||
[26] .strtab STRTAB 00000000 000b82 0000de 00 0 0 1
|
||||
[27] .gnu_debuglink PROGBITS 00000000 000c60 000014 00 0 0 4
|
||||
" "" ""
|
||||
|
||||
testing "-l" "readelf -lW $elf-short" "
|
||||
Elf file type is DYN (Shared object file)
|
||||
Entry point 0x1001
|
||||
There are 10 program headers, starting at offset 52
|
||||
|
||||
Program Headers:
|
||||
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
|
||||
PHDR 0x000034 0x00000034 0x00000034 0x00140 0x00140 R 0x4
|
||||
INTERP 0x000174 0x00000174 0x00000174 0x00013 0x00013 R 0x1
|
||||
[Requesting program interpreter: /system/bin/linker]
|
||||
LOAD 0x000000 0x00000000 0x00000000 0x00404 0x00404 R 0x1000
|
||||
LOAD 0x001000 0x00001000 0x00001000 0x00140 0x00140 R E 0x1000
|
||||
LOAD 0x002000 0x00002000 0x00002000 0x00144 0x00144 RW 0x1000
|
||||
DYNAMIC 0x002018 0x00002018 0x00002018 0x00100 0x00100 RW 0x4
|
||||
GNU_RELRO 0x002000 0x00002000 0x00002000 0x00144 0x01000 R 0x1
|
||||
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0
|
||||
NOTE 0x000188 0x00000188 0x00000188 0x00038 0x00038 R 0x4
|
||||
EXIDX 0x0001c0 0x000001c0 0x000001c0 0x00030 0x00030 R 0x4
|
||||
|
||||
Section to Segment mapping:
|
||||
Segment Sections...
|
||||
00
|
||||
01 .interp
|
||||
02 .interp .note.android.ident .note.gnu.build-id .ARM.exidx .dynsym .gnu.version .gnu.version_r .gnu.hash .dynstr .rel.dyn .relr.dyn .rel.plt
|
||||
03 .text .plt
|
||||
04 .preinit_array .init_array .fini_array .dynamic .got .got.plt
|
||||
05 .dynamic
|
||||
06 .preinit_array .init_array .fini_array .dynamic .got .got.plt
|
||||
07
|
||||
08 .note.android.ident .note.gnu.build-id
|
||||
09 .ARM.exidx
|
||||
" "" ""
|
||||
|
||||
# binutils doesn't line up the column headers for 64-bit ELF files.
|
||||
# TODO: binutils readelf lies about trailing NULL entires binutils ld produces
|
||||
NOSPACE=1 toyonly testing "-d" "readelf -dW $elf-full" "
|
||||
Dynamic section at offset 0xd98 contains 33 entries:
|
||||
Tag Type Name/Value
|
||||
0x0000000000000001 (NEEDED) Shared library: [libc.so]
|
||||
0x0000000000000001 (NEEDED) Shared library: [libm.so]
|
||||
0x0000000000000001 (NEEDED) Shared library: [libdl.so]
|
||||
0x0000000000000020 (PREINIT_ARRAY) 0x10d68
|
||||
0x0000000000000021 (PREINIT_ARRAYSZ) 0x10
|
||||
0x0000000000000019 (INIT_ARRAY) 0x10d78
|
||||
0x000000000000001b (INIT_ARRAYSZ) 16 (bytes)
|
||||
0x000000000000001a (FINI_ARRAY) 0x10d88
|
||||
0x000000000000001c (FINI_ARRAYSZ) 16 (bytes)
|
||||
0x0000000000000004 (HASH) 0x310
|
||||
0x0000000000000005 (STRTAB) 0x490
|
||||
0x0000000000000006 (SYMTAB) 0x358
|
||||
0x000000000000000a (STRSZ) 151 (bytes)
|
||||
0x000000000000000b (SYMENT) 24 (bytes)
|
||||
0x0000000000000015 (DEBUG) 0x0
|
||||
0x0000000000000003 (PLTGOT) 0x10fa8
|
||||
0x0000000000000002 (PLTRELSZ) 72 (bytes)
|
||||
0x0000000000000014 (PLTREL) RELA
|
||||
0x0000000000000017 (JMPREL) 0x5c8
|
||||
0x0000000000000007 (RELA) 0x568
|
||||
0x0000000000000008 (RELASZ) 96 (bytes)
|
||||
0x0000000000000009 (RELAENT) 24 (bytes)
|
||||
0x000000000000001e (FLAGS) BIND_NOW
|
||||
0x000000006ffffffb (FLAGS_1) Flags: NOW
|
||||
0x000000006ffffffe (VERNEED) 0x548
|
||||
0x000000006fffffff (VERNEEDNUM) 1
|
||||
0x000000006ffffff0 (VERSYM) 0x528
|
||||
0x000000006ffffff9 (RELACOUNT) 4
|
||||
0x0000000000000000 (NULL) 0x0
|
||||
0x0000000000000000 (NULL) 0x0
|
||||
0x0000000000000000 (NULL) 0x0
|
||||
0x0000000000000000 (NULL) 0x0
|
||||
0x0000000000000000 (NULL) 0x0
|
||||
" "" ""
|
||||
|
||||
# toybox does a better job of decoding Android's ELF notes than binutils.
|
||||
toyonly testing "-n" "readelf -nW $elf-short" "
|
||||
Displaying notes found in: .note.android.ident
|
||||
Owner Data size Description
|
||||
Android 0x00000004 NT_VERSION API level 28
|
||||
|
||||
Displaying notes found in: .note.gnu.build-id
|
||||
Owner Data size Description
|
||||
GNU 0x00000010 NT_GNU_BUILD_ID da6a5f4ca8da163b9339326e626d8a3c
|
||||
" "" ""
|
||||
|
||||
testing "-p" "readelf -p22 $elf-short" "
|
||||
String dump of section '.shstrtab':
|
||||
[ 1] .preinit_array
|
||||
[ 10] .init_array
|
||||
[ 1c] .fini_array
|
||||
[ 28] .ARM.exidx
|
||||
[ 33] .text
|
||||
[ 39] .got
|
||||
[ 3e] .note.android.ident
|
||||
[ 52] .got.plt
|
||||
[ 5b] .rel.plt
|
||||
[ 64] .ARM.attributes
|
||||
[ 74] .dynstr
|
||||
[ 7c] .gnu.version_r
|
||||
[ 8b] .interp
|
||||
[ 93] .relr.dyn
|
||||
[ 9d] .rel.dyn
|
||||
[ a6] .gnu.version
|
||||
[ b3] .dynsym
|
||||
[ bb] .gnu.hash
|
||||
[ c5] .note.gnu.build-id
|
||||
[ d8] .dynamic
|
||||
[ e1] .shstrtab
|
||||
[ eb] .gnu_debugdata
|
||||
|
||||
" "" ""
|
||||
|
||||
testing "-x" "readelf -x22 $elf-short" "
|
||||
Hex dump of section '.shstrtab':
|
||||
0x00000000 002e7072 65696e69 745f6172 72617900 ..preinit_array.
|
||||
0x00000010 2e696e69 745f6172 72617900 2e66696e .init_array..fin
|
||||
0x00000020 695f6172 72617900 2e41524d 2e657869 i_array..ARM.exi
|
||||
0x00000030 6478002e 74657874 002e676f 74002e6e dx..text..got..n
|
||||
0x00000040 6f74652e 616e6472 6f69642e 6964656e ote.android.iden
|
||||
0x00000050 74002e67 6f742e70 6c74002e 72656c2e t..got.plt..rel.
|
||||
0x00000060 706c7400 2e41524d 2e617474 72696275 plt..ARM.attribu
|
||||
0x00000070 74657300 2e64796e 73747200 2e676e75 tes..dynstr..gnu
|
||||
0x00000080 2e766572 73696f6e 5f72002e 696e7465 .version_r..inte
|
||||
0x00000090 7270002e 72656c72 2e64796e 002e7265 rp..relr.dyn..re
|
||||
0x000000a0 6c2e6479 6e002e67 6e752e76 65727369 l.dyn..gnu.versi
|
||||
0x000000b0 6f6e002e 64796e73 796d002e 676e752e on..dynsym..gnu.
|
||||
0x000000c0 68617368 002e6e6f 74652e67 6e752e62 hash..note.gnu.b
|
||||
0x000000d0 75696c64 2d696400 2e64796e 616d6963 uild-id..dynamic
|
||||
0x000000e0 002e7368 73747274 6162002e 676e755f ..shstrtab..gnu_
|
||||
0x000000f0 64656275 67646174 61000000 000000 debugdata......
|
||||
|
||||
" "" ""
|
||||
|
||||
# TODO: remove the sed when we handle symbol versions
|
||||
testing "-s" "readelf -s $elf-short | sed s/@.*//" "
|
||||
Symbol table '.dynsym' contains 11 entries:
|
||||
Num: Value Size Type Bind Vis Ndx Name
|
||||
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
|
||||
1: 00000000 0 FUNC GLOBAL DEFAULT UND __libc_init
|
||||
2: 00000000 0 FUNC GLOBAL DEFAULT UND __stack_chk_fail
|
||||
3: 00000000 0 OBJECT GLOBAL DEFAULT UND __stack_chk_guard
|
||||
4: 00000000 0 FUNC GLOBAL DEFAULT UND memset
|
||||
5: 000010d8 12 FUNC GLOBAL DEFAULT 13 __aeabi_memclr
|
||||
6: 000010d8 12 FUNC GLOBAL DEFAULT 13 __aeabi_memclr4
|
||||
7: 000010d8 12 FUNC GLOBAL DEFAULT 13 __aeabi_memclr8
|
||||
8: 000010c8 16 FUNC GLOBAL DEFAULT 13 __aeabi_memset
|
||||
9: 000010c8 16 FUNC GLOBAL DEFAULT 13 __aeabi_memset4
|
||||
10: 000010c8 16 FUNC GLOBAL DEFAULT 13 __aeabi_memset8
|
||||
" "" ""
|
||||
+8
-3
@@ -31,13 +31,17 @@ testing "link->link (recursive)" "readlink link" "link\n" "" ""
|
||||
testing "-f link->link (recursive)" \
|
||||
"readlink -f link 2>/dev/null || echo yes" "yes\n" "" ""
|
||||
|
||||
testing "-q notlink" "readlink -q file || echo yes" "yes\n" "" ""
|
||||
testing "-q link" "readlink -q link && echo yes" "yes\n" "" ""
|
||||
testing "-q notlink" "readlink -q file 2>&1 || echo yes" "yes\n" "" ""
|
||||
testing "-q link" "readlink -q link && echo yes" "link\nyes\n" "" ""
|
||||
testing "-q notfound" "readlink -q notfound || echo yes" "yes\n" "" ""
|
||||
testing "-e found" "readlink -e file" "$APWD/file\n" "" ""
|
||||
testing "-e notfound" \
|
||||
"readlink -e notfound 2>/dev/null || echo yes" "yes\n" "" ""
|
||||
testing "-nf ." "readlink -nf ." "$APWD" "" ""
|
||||
# -n means no newline at _end_. I.E. on last argument.
|
||||
toyonly testcmd '-nf multiple args' '-n link link' "link\nlink" '' ''
|
||||
testcmd '-nz' '-nz link' 'link' '' ''
|
||||
testcmd '-z' '-z link' 'link\0' '' ''
|
||||
|
||||
mkdir sub &&
|
||||
ln -s . here &&
|
||||
@@ -51,7 +55,8 @@ testing "-f /dev/null/file" \
|
||||
"readlink -f /dev/null/file 2>/dev/null || echo yes" "yes\n" "" ""
|
||||
testing "-m missing/dir" "readlink -m sub/two/three" "$APWD/sub/two/three\n" "" ""
|
||||
testing "-m missing/../elsewhere" "readlink -m sub/two/../../three" "$APWD/three\n" "" ""
|
||||
testing "-m file/dir" "readlink -m sub/bang/two 2>/dev/null || echo err" "err\n" "" ""
|
||||
# TODO: host bug? That's not missing, that's "cannot exist".
|
||||
toyonly testing "-m file/dir" "readlink -m sub/bang/two 2>/dev/null || echo err" "err\n" "" ""
|
||||
rm link
|
||||
ln -sf / link || exit 1
|
||||
testing "-f link->/" "readlink -e link/dev" "/dev\n" "" ""
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
#!/bin/bash
|
||||
|
||||
[ -f testing.sh ] && . testing.sh
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
TOP="$(readlink -f .)"
|
||||
export PWD
|
||||
|
||||
touch file
|
||||
mkdir -p one/two/three
|
||||
ln -s ./one uno
|
||||
ln -s one/two dos
|
||||
|
||||
testcmd '' '.' "$TOP\n" '' ''
|
||||
testcmd 'missing' 'missing' "$TOP/missing\n" '' ''
|
||||
testcmd 'missing2' 'missing/sub 2>/dev/null || echo err' 'err\n' '' ''
|
||||
testcmd '-z' '-z . | tr "\0" X' "${TOP}X" '' ''
|
||||
testcmd 'file' 'file' "$TOP/file\n" '' ''
|
||||
testcmd 'dir' 'one/two/three' "$TOP/one/two/three\n" '' ''
|
||||
testcmd '--relative-to' '. --relative-to=one/two/three' '../../..\n' '' ''
|
||||
testcmd '--relative-to2' \
|
||||
'-m --relative-to=missing/that/ uno/../dos/linux/../../bingeley/bongeley/beep' \
|
||||
'../../one/bingeley/bongeley/beep\n' '' ''
|
||||
testcmd '--relative-to3' '-m walrus --relative-to walrus' '.\n' '' ''
|
||||
testcmd '--relative-to4' '"$PWD" --relative-to one' '..\n' '' ''
|
||||
testcmd '--relative-to5' '--relative-to "$PWD" one' 'one\n' '' ''
|
||||
testcmd 'relative-to missing' \
|
||||
'--relative-to nothing/potato . 2>/dev/null || echo fail' 'fail\n' '' ''
|
||||
testcmd 'relative-to missing -m' \
|
||||
'-m --relative-to nothing/potato .' '../..\n' '' ''
|
||||
testcmd '--relative-base' 'one one/two one/two/three --relative-base=one/two' \
|
||||
"$TOP/one\n.\nthree\n" '' ''
|
||||
testcmd '--relative-base stomps --relative-to' \
|
||||
'--relative-to=.. --relative-base=one/two one' "$TOP/one\n" '' ''
|
||||
testcmd '-m with relative-base1' '-m --relative-base wurble wurble/poing' \
|
||||
'poing\n' '' ''
|
||||
testcmd '-m with relative-base2' '-sm --relative-base wurble .' "$PWD\n" '' ''
|
||||
testcmd '-m with relative-base3' '-m --relative-base wurble wurble wurble/' \
|
||||
'.\n.\n' '' ''
|
||||
testcmd 'missing defaults to -m' 'missing' "$TOP/missing\n" '' ''
|
||||
testcmd 'missing -e' '-e missing 2>/dev/null || echo ok' 'ok\n' '' ''
|
||||
testcmd '-L' '-L dos/../one' "$TOP/one\n" '' ''
|
||||
|
||||
# -s vs -L
|
||||
ln -s .. parent
|
||||
testcmd "-s isn't L" '-s --relative-to=. parent' 'parent\n' '' ''
|
||||
testcmd "-L isn't s" '-L --relative-to=. parent' '..\n' '' ''
|
||||
|
||||
# The -s tests use $PWD instead of $TOP because symlinks in path _to_ here
|
||||
# should not be resolved either. The shell exports $PWD: use it.
|
||||
testcmd '-s' '-s uno/two' "$PWD/uno/two\n" '' ''
|
||||
testcmd '-s link/..' '-es dos/three' "$PWD/dos/three\n" '' ''
|
||||
testcmd '-s .. eats symlink' '-s dos/..' "$PWD\n" '' ''
|
||||
# In toybox this test is consistent with the previous one
|
||||
toyonly testing '-s .. eats symlink in $PWD' \
|
||||
'cd dos && realpath -s ..' "$PWD\n" '' ''
|
||||
# Logically -es means the _symlink_ should exist, but match behavior...
|
||||
ln -s missing dangling
|
||||
testcmd '-es dangling symlink' '-es dangling 2>/dev/null || echo ok' \
|
||||
'ok\n' '' ''
|
||||
testcmd '-ms' '-ms dangling/../dos/../one/two' "$PWD/one/two\n" '' ''
|
||||
ln -s ../two/.. one/two/ichi
|
||||
testcmd '-es' '-es one/two/ichi/two/ichi/two' "$PWD/one/two/ichi/two/ichi/two\n" '' ''
|
||||
|
||||
rm -rf file one uno dos
|
||||
+7
-7
@@ -7,19 +7,19 @@
|
||||
echo -e "one" > file1
|
||||
echo -e "two" > file2
|
||||
testing "rev" "rev && echo yes" "orez\nyes\n" "" "zero\n"
|
||||
testing "-" "rev - && echo yes" "orez\nyes\n" "" "zero\n"
|
||||
toyonly testing "-" "rev - && echo yes" "orez\nyes\n" "" "zero\n"
|
||||
testing "file1 file2" "rev file1 file2" "eno\nowt\n" "" ""
|
||||
testing "- file" "rev - file1" "orez\neno\n" "" "zero\n"
|
||||
testing "file -" "rev file1 -" "eno\norez\n" "" "zero\n"
|
||||
testing "no trailing newline" "rev -" "cba\nfed\n" "" "abc\ndef"
|
||||
toyonly testing "- file" "rev - file1" "orez\neno\n" "" "zero\n"
|
||||
toyonly testing "file -" "rev file1 -" "eno\norez\n" "" "zero\n"
|
||||
toyonly testing "no trailing newline" "rev input" "cba\nfed\n" "abc\ndef" ""
|
||||
|
||||
testing "file1 notfound file2" \
|
||||
"rev file1 notfound file2 2>stderr && echo ok ; cat stderr; rm stderr" \
|
||||
"eno\nowt\nrev: notfound: No such file or directory\n" "" ""
|
||||
"rev file1 notfound file2 2>stderr && echo ok ; grep -o 'notfound: No such file or directory' stderr; rm stderr" \
|
||||
"eno\nowt\nnotfound: No such file or directory\n" "" ""
|
||||
|
||||
testing "different input sizes"\
|
||||
"rev"\
|
||||
"\n1\n21\n321\n4321\n54321\n4321\n321\n21\n1\n\n"\
|
||||
"" "\n1\n12\n123\n1234\n12345\n1234\n123\n12\n1\n\n"
|
||||
|
||||
rm file1 file2
|
||||
rm file1 file2
|
||||
|
||||
+13
-5
@@ -11,6 +11,8 @@ echo "abcdefghijklmnopqrstuvwxyz" > file.txt
|
||||
testing "text-file" "rm file.txt && [ ! -e file.txt ] && echo 'yes'" "yes\n" "" ""
|
||||
rm -f file*
|
||||
|
||||
testing "-i nonexistent" "</dev/zero rm -i file.txt 2>/dev/null || echo 'yes'" "yes\n" "" ""
|
||||
|
||||
mkdir dir
|
||||
testing "empty directory" "rm -r dir && [ ! -d dir ] && echo 'yes'" "yes\n" "" ""
|
||||
rm -rf dir
|
||||
@@ -51,10 +53,16 @@ chmod 777 one 2>/dev/null ; rm -rf one
|
||||
|
||||
mkdir -p d1
|
||||
touch d1/f1.txt d1/f2.txt
|
||||
testing "-rv dir" \
|
||||
"rm -rv d1 | sort" "rm 'd1/f1.txt'\nrm 'd1/f2.txt'\nrmdir 'd1'\n" "" ""
|
||||
testing "-rv dir" "rm -rv d1 | sed 's/emoved/m/;s/ directory/dir/' | sort" \
|
||||
"rm 'd1/f1.txt'\nrm 'd1/f2.txt'\nrmdir 'd1'\n" "" ""
|
||||
rm -rf d1
|
||||
|
||||
touch "'"
|
||||
testing "-v \\'" "rm -v \\'" "rm '''\n" "" "" # TODO: coreutils escapes quote
|
||||
rm -f \'
|
||||
touch "meep"
|
||||
testing "-v" "rm -v meep | sed 's/emoved/m/'" "rm 'meep'\n" "" ""
|
||||
rm -f meep
|
||||
|
||||
skipnot [ $(id -u) -eq 0 ]
|
||||
testing "-f <readonly_filesystem>/<missing_file>" \
|
||||
"rm -rf mnt_point && mkdir -p mnt_point &&
|
||||
mount -t tmpfs -o ro none ./mnt_point && rm -f mnt_point/missing_file &&
|
||||
echo yes; umount ./mnt_point; rm -rf mnt_point" "yes\n" "" ""
|
||||
|
||||
@@ -40,6 +40,10 @@ testing "-p part of path" \
|
||||
"yes\n" "" ""
|
||||
rm -rf temp
|
||||
|
||||
skipnot [ $UID -eq 0 ]
|
||||
testing '-p abspath' \
|
||||
'mkdir -p /test/2/3 && rmdir -p /test/2/3 && [ ! -e /test ] && echo yes' \
|
||||
'yes\n' '' ''
|
||||
|
||||
mkdir -p one/two/three
|
||||
testing "-p one/two/three" \
|
||||
|
||||
+99
-71
@@ -2,87 +2,83 @@
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
testing 'as cat' 'sed ""' "one\ntwo\nthree" "" "one\ntwo\nthree"
|
||||
testcmd 'as cat' '""' "one\ntwo\nthree" "" "one\ntwo\nthree"
|
||||
# This segfaults ubuntu 12.04's sed. No really.
|
||||
SKIP_HOST=1 testing 'sed - - twice' 'sed "" - -' "hello\n" "" "hello\n"
|
||||
testing '-n' 'sed -n ""' "" "" "one\ntwo\nthree"
|
||||
testing '-n p' 'sed -n p' "one\ntwo\nthree" "" "one\ntwo\nthree"
|
||||
testing 'explicit pattern' 'sed -e p -n' "one\ntwo\nthree" "" \
|
||||
"one\ntwo\nthree"
|
||||
testcmd '- - twice' '"" - -' "hello\n" "" "hello\n"
|
||||
testcmd '-n' '-n ""' "" "" "one\ntwo\nthree"
|
||||
testcmd '-n p' '-n p' "one\ntwo\nthree" "" "one\ntwo\nthree"
|
||||
testcmd 'explicit pattern' '-e p -n' "one\ntwo\nthree" "" "one\ntwo\nthree"
|
||||
|
||||
# Exploring the wonders of sed addressing modes
|
||||
testing '' 'sed -n 1p' "one\n" "" "one\ntwo\nthree"
|
||||
testing '' 'sed 2p' "one\ntwo\ntwo\nthree" "" "one\ntwo\nthree"
|
||||
testing '' 'sed -n 2p' "two\n" "" "one\ntwo\nthree"
|
||||
testing '-n $p' 'sed -n \$p' "three" "" "one\ntwo\nthree"
|
||||
testing 'as cat #2' "sed -n '1,\$p'" "one\ntwo\nthree" "" "one\ntwo\nthree"
|
||||
testing 'no input means no last line' "sed '\$a boing'" "" "" ""
|
||||
testing '-n $,$p' 'sed -n \$,\$p' 'three' '' 'one\ntwo\nthree'
|
||||
testing '' 'sed -n 1,2p' "one\ntwo\n" "" "one\ntwo\nthree"
|
||||
testing '' 'sed -n 2,3p' "two\nthree" "" "one\ntwo\nthree"
|
||||
testing '' 'sed -n 2,1p' "two\n" "" "one\ntwo\nthree"
|
||||
testing '$ with 2 inputs' 'sed -n \$p - input' "four\n" "four\n" \
|
||||
"one\ntwo\nthree"
|
||||
testing '' 'sed -n /two/p' "two\n" "" "one\ntwo\nthree"
|
||||
testing '' 'sed -n 1,/two/p' 'one\ntwo\n' '' 'one\ntwo\nthree'
|
||||
testing '' 'sed -n /one/,2p' 'one\ntwo\n' '' 'one\ntwo\nthree'
|
||||
testing '' 'sed -n 1,/one/p' 'one\ntwo\nthree' '' 'one\ntwo\nthree'
|
||||
testing '' 'sed -n /one/,1p' 'one\n' '' 'one\ntwo\nthree'
|
||||
testing 'sed -n /two/,$p' 'sed -n /two/,\$p' 'two\nthree' '' 'one\ntwo\nthree'
|
||||
|
||||
testcmd '' '-n 1p' "one\n" "" "one\ntwo\nthree"
|
||||
testcmd '' '2p' "one\ntwo\ntwo\nthree" "" "one\ntwo\nthree"
|
||||
testcmd '' '-n 2p' "two\n" "" "one\ntwo\nthree"
|
||||
testcmd '-n $p' '-n \$p' "three" "" "one\ntwo\nthree"
|
||||
testcmd 'as cat #2' "-n '1,\$p'" "one\ntwo\nthree" "" "one\ntwo\nthree"
|
||||
testcmd 'no input means no last line' "'\$a boing'" "" "" ""
|
||||
testcmd '-n $,$p' '-n \$,\$p' 'three' '' 'one\ntwo\nthree'
|
||||
testcmd '' '-n 1,2p' "one\ntwo\n" "" "one\ntwo\nthree"
|
||||
testcmd '' '-n 2,3p' "two\nthree" "" "one\ntwo\nthree"
|
||||
testcmd '' '-n 2,1p' "two\n" "" "one\ntwo\nthree"
|
||||
testcmd '$ with 2 inputs' '-n \$p - input' "four\n" "four\n" "one\ntwo\nthree"
|
||||
testcmd '' '-n /two/p' "two\n" "" "one\ntwo\nthree"
|
||||
testcmd '' '-n 1,/two/p' 'one\ntwo\n' '' 'one\ntwo\nthree'
|
||||
testcmd '' '-n /one/,2p' 'one\ntwo\n' '' 'one\ntwo\nthree'
|
||||
testcmd '' '-n 1,/one/p' 'one\ntwo\nthree' '' 'one\ntwo\nthree'
|
||||
testcmd '' '-n /one/,1p' 'one\n' '' 'one\ntwo\nthree'
|
||||
testcmd '-n /two/,$p' '-n /two/,\$p' 'two\nthree' '' 'one\ntwo\nthree'
|
||||
|
||||
# Fun with newlines!
|
||||
testing '' 'sed -n 3p' "three" "" "one\ntwo\nthree"
|
||||
testing 'prodigal newline' "sed -n '1,\$p' - input" \
|
||||
testcmd '' '-n 3p' "three" "" "one\ntwo\nthree"
|
||||
testcmd 'prodigal newline' "-n '1,\$p' - input" \
|
||||
"one\ntwo\nthree\nfour\n" "four\n" "one\ntwo\nthree"
|
||||
testing 'Newline only added if further output' "sed -n 3p - input" "three" \
|
||||
testcmd 'Newline only added if further output' "-n 3p - input" "three" \
|
||||
"four\n" "one\ntwo\nthree"
|
||||
|
||||
# Fun with match delimiters and escapes
|
||||
testing 'match \t tab' "sed -n '/\t/p'" "\tx\n" "" "\tx\n"
|
||||
testing 'match t delim disables \t tab' "sed -n '\t\txtp'" "" "" "\tx\n"
|
||||
testing 'match t delim makes \t literal t' \
|
||||
"sed -n '\t\txtp'" "tx\n" "" "tx\n"
|
||||
testing 'match n delim' "sed -n '\n\txnp'" "\tx\n" "" "\tx\n"
|
||||
testing 'match n delim disables \n newline' "sed -n '\n\nxnp'" "" "" "\nx\n"
|
||||
SKIP_HOST=1 testing 'match \n literal n' "sed -n '\n\nxnp'" "nx\n" "" "nx\n"
|
||||
testing 'end match does not check starting match line' \
|
||||
"sed -n '/two/,/two/p'" "two\nthree" "" "one\ntwo\nthree"
|
||||
testing 'end match/start match mixing number/letter' \
|
||||
"sed -n '2,/two/p'" "two\nthree" "" "one\ntwo\nthree"
|
||||
testing 'num then regex' 'sed -n 2,/d/p' 'b\nc\nd\n' '' 'a\nb\nc\nd\ne\nf\n'
|
||||
testing 'regex then num' 'sed -n /b/,4p' 'b\nc\nd\n' '' 'a\nb\nc\nd\ne\nf\n'
|
||||
testing 'multiple regex address match' 'sed -n /on/,/off/p' \
|
||||
testcmd 'match \t tab' "-n '/\t/p'" "\tx\n" "" "\tx\n"
|
||||
testcmd 'match t delim disables \t tab' "-n '\t\txtp'" "" "" "\tx\n"
|
||||
testcmd 'match t delim makes \t literal t' "-n '\t\txtp'" "tx\n" "" "tx\n"
|
||||
testcmd 'match n delim' "-n '\n\txnp'" "\tx\n" "" "\tx\n"
|
||||
testcmd 'match n delim disables \n newline' "-n '\n\nxnp'" "" "" "\nx\n"
|
||||
toyonly testcmd 'match \n literal n' "-n '\n\nxnp'" "nx\n" "" "nx\n"
|
||||
testcmd 'end match does not check starting match line' \
|
||||
"-n '/two/,/two/p'" "two\nthree" "" "one\ntwo\nthree"
|
||||
testcmd 'end match/start match mixing number/letter' \
|
||||
"-n '2,/two/p'" "two\nthree" "" "one\ntwo\nthree"
|
||||
testcmd 'num then regex' '-n 2,/d/p' 'b\nc\nd\n' '' 'a\nb\nc\nd\ne\nf\n'
|
||||
testcmd 'regex then num' '-n /b/,4p' 'b\nc\nd\n' '' 'a\nb\nc\nd\ne\nf\n'
|
||||
testcmd 'multiple regex address match' '-n /on/,/off/p' \
|
||||
'bone\nturtle\scoff\ntron\nlurid\noffer\n' "" \
|
||||
'zap\nbone\nturtle\scoff\nfred\ntron\nlurid\noffer\nbecause\n'
|
||||
testing 'regex address overlap' 'sed -n /on/,/off/p' "on\nzap\noffon\n" "" \
|
||||
testcmd 'regex address overlap' '-n /on/,/off/p' "on\nzap\noffon\n" "" \
|
||||
'on\nzap\noffon\nping\noff\n'
|
||||
testing 'getdelim with nested [:blah:]' 'sed -n "sa\a[a[:space:]bc]*aXXagp"' \
|
||||
testcmd 'getdelim with nested [:blah:]' '-n "sa\a[a[:space:]bc]*aXXagp"' \
|
||||
"ABXXCDXXEFXXGHXXIXX" "" "ABaaCDa EFaa aGHa a Ia "
|
||||
testing '[ in [[]' "sed 's@[[]@X@g'" "X" "" "["
|
||||
testing '[[] with ] as delimiter' "sed 's][[]]X]g'" "X" "" "["
|
||||
testing '[[] with [ as delimiter' "sed 's[\[\[][X['" "X" "" "["
|
||||
testcmd '[ in [[]' "'s@[[]@X@g'" "X" "" "["
|
||||
testcmd '[[] with ] as delimiter' "'s][[]]X]g'" "X" "" "["
|
||||
testcmd '[[] with [ as delimiter' "'s[\[\[][X['" "X" "" "["
|
||||
|
||||
# gGhHlnNpPqrstwxy:=
|
||||
# s///#comment
|
||||
# abcdDi
|
||||
|
||||
testing 'prodigaler newline' 'sed -e a\\ -e woo' 'one\nwoo\n' '' 'one'
|
||||
testing "aci" \
|
||||
"sed -e '3a boom' -e '/hre/i bang' -e '3a whack' -e '3c bong'" \
|
||||
testcmd 'prodigaler newline' '-e a\\ -e woo' 'one\nwoo\n' '' 'one'
|
||||
testcmd "aci" "-e '3a boom' -e '/hre/i bang' -e '3a whack' -e '3c bong'" \
|
||||
"one\ntwo\nbang\nbong\nboom\nwhack\nfour\n" "" \
|
||||
"one\ntwo\nthree\nfour\n"
|
||||
testing "b loop" "sed ':woo;=;b woo' | head -n 5" '1\n1\n1\n1\n1\n' "" "X"
|
||||
testing "b skip" "sed -n '2b zap;d;:zap;p'" "two\n" "" "one\ntwo\nthree"
|
||||
testing "b end" "sed -n '2b;p'" "one\nthree" "" "one\ntwo\nthree"
|
||||
testing "c range" "sed '2,4c blah'" "one\nblah\nfive\nsix" "" \
|
||||
testcmd "b loop" "':woo;=;b woo' | head -n 5" '1\n1\n1\n1\n1\n' "" "X"
|
||||
testcmd "b skip" "-n '2b zap;d;:zap;p'" "two\n" "" "one\ntwo\nthree"
|
||||
testcmd "b end" "-n '2b;p'" "one\nthree" "" "one\ntwo\nthree"
|
||||
testcmd "c range" "'2,4c blah'" "one\nblah\nfive\nsix" "" \
|
||||
"one\ntwo\nthree\nfour\nfive\nsix"
|
||||
testing "c {range}" "sed -e '2,4{c blah' -e '}'" \
|
||||
"one\nblah\nblah\nblah\nfive\nsix" \
|
||||
testcmd "c {range}" "-e '2,4{c blah' -e '}'" "one\nblah\nblah\nblah\nfive\nsix"\
|
||||
"" "one\ntwo\nthree\nfour\nfive\nsix"
|
||||
testing "c multiple continuation" \
|
||||
"sed -e 'c\\' -e 'two\\' -e ''" "two\n\n" "" "hello"
|
||||
SKIP_HOST=1 testing "c empty continuation" "sed -e 'c\\'" "\n" "" "hello"
|
||||
testcmd "c multiple continuation" "-e 'c\\' -e 'two\\' -e ''" "two\n\n" "" \
|
||||
"hello"
|
||||
testcmd 'multiline continuations' '-e c\\ -e line1\\ -e line2' 'line1\nline2\n'\
|
||||
'' 'one\n'
|
||||
toyonly testing "c empty continuation" "sed -e 'c\\'" "\n" "" "hello"
|
||||
testing "D further processing depends on whether line is blank" \
|
||||
"sed -e '/one/,/three/{' -e 'i meep' -e'N;2D;}'" \
|
||||
"meep\nmeep\ntwo\nthree\n" "" "one\ntwo\nthree\n"
|
||||
@@ -115,6 +111,7 @@ testing 'empty match after nonempty match' "sed -e 's/a*/c/g'" 'cbcncgc' \
|
||||
testing 'empty match' "sed -e 's/[^ac]*/A/g'" 'AaAcA' '' 'abcde'
|
||||
testing 's///#comment' "sed -e 's/TWO/four/i#comment'" "one\nfour\nthree" \
|
||||
"" "one\ntwo\nthree"
|
||||
testing 's///num off end' 'sed -e s/e//2' 'e\n' '' 'e\n'
|
||||
|
||||
testing 'N flushes pending a and advances match counter' \
|
||||
"sed -e 'a woo' -e 'N;\$p'" 'woo\none\ntwo\none\ntwo' "" 'one\ntwo'
|
||||
@@ -128,6 +125,9 @@ testing "blank pattern repeats last pattern" \
|
||||
"one two three\nabcthreedef four five\nfive six seven\n" "" \
|
||||
"one two three\nthree four five\nfive six seven\n"
|
||||
|
||||
testcmd "interleave -e and -f" "-e 'a abc' -f input -e 'a ghi'" \
|
||||
"hello\nabc\ndef\nghi\n" "a def" "hello\n"
|
||||
|
||||
# Different ways of parsing line continuations
|
||||
|
||||
testing "" "sed -e '1a\' -e 'huh'" "meep\nhuh\n" "" "meep"
|
||||
@@ -138,7 +138,7 @@ hello'" "merp\nhello\n" "" "merp"
|
||||
|
||||
testing "" "sed -e '/x/c\' -e 'y'" 'y\n' '' 'x\n'
|
||||
testing "" "sed -e 's/a[([]*b/X/'" 'X' '' 'a[(b'
|
||||
testing "" "sed 'y/a\\bc/de\f/'" "db\f" "" "abc"
|
||||
toyonly testing "" "sed 'y/a\\bc/de\f/'" "db\f" "" "abc"
|
||||
testing "[a-a] (for perl)" "sed '"'s/\([^a-zA-Z0-9.:_\-\/]\)/\\\1/g'"'" \
|
||||
'he\ llo' "" "he llo"
|
||||
|
||||
@@ -150,7 +150,7 @@ testing "trailing a\ (for debian)" "sed 'a\\'" "hello\n" "" "hello"
|
||||
|
||||
# You have to match the first line of a range in order to activate
|
||||
# the range, numeric and ascii work the same way
|
||||
testing "skip start of range" "sed -e n -e '1,2s/b/c/'" "a\nb\n" "" "a\nb\n"
|
||||
toyonly testing "skip start of range" "sed -e n -e '1,2s/b/c/'" "a\nb\n" "" "a\nb\n"
|
||||
testing "range +1" "sed -ne '/blah/,+1p'" "blah\n6\n" "" \
|
||||
"1\n2\n3\n4\n5\nblah\n6\n7\n8\n9\n"
|
||||
testing "range +0" "sed -ne '/blah/,+0p'" "blah\n" "" \
|
||||
@@ -158,10 +158,8 @@ testing "range +0" "sed -ne '/blah/,+0p'" "blah\n" "" \
|
||||
testing "range +3" "sed -ne '2,+3p'" "2\n3\n4\n5\n" "" \
|
||||
"1\n2\n3\n4\n5\nblah\n6\n7\n8\n9\n"
|
||||
|
||||
#echo meep | sed/sed -e '1a\' -e 'huh'
|
||||
#echo blah | sed/sed -f <(echo -e "1a\\\\\nboom")
|
||||
#echo merp | sed/sed "1a\\
|
||||
#hello"
|
||||
testing "not -s" "sed -n 1p input -" "one" "one" "two"
|
||||
testing "-s" "sed -sn 1p input -" "one\ntwo" "one\n" "two"
|
||||
|
||||
testing "bonus backslashes" \
|
||||
"sed -e 'a \l \x\' -e \"\$(echo -e 'ab\\\nc')\"" \
|
||||
@@ -171,21 +169,51 @@ testing "bonus backslashes" \
|
||||
testing "end b with }" "sed -n '/START/{:a;n;/END/q;p;ba}'" "b\nc\n" \
|
||||
"" "a\nSTART\nb\nc\nEND\nd"
|
||||
|
||||
testing '-z' 'sed -z "s/\n/-/g"' "a-b-c" "" "a\nb\nc"
|
||||
testcmd '-z' '-z "s/\n/-/g"' "a-b-c" "" "a\nb\nc"
|
||||
testcmd '-z N' '-z N' 'one\0two\0' '' 'one\0two\0'
|
||||
testcmd 'p noeol' '-z p' 'one\0one' '' 'one'
|
||||
testcmd '-z N noeol' '-z N' 'one\0two' '' 'one\0two'
|
||||
testcmd '-z S' "-z 'N;P'" 'one\0one\0two' '' 'one\0two'
|
||||
testcmd '-z D' "-z 'N;D'" 'two' '' 'one\0two'
|
||||
testcmd '-z G' "-z 'h;G'" 'one\0one' '' 'one'
|
||||
testcmd '-z H' "-z 'H;g'" '\0one' '' 'one'
|
||||
toyonly testcmd '-z x NOEOL' '-z ax' 'abc\0x\0def\0x\0' '' 'abc\0def'
|
||||
testcmd 's after NUL' 's/t/x/' 'one\0xwo' '' 'one\0two'
|
||||
testcmd '^ not trigger after NUL' 's/^t/x/' 'one\0two' '' 'one\0two'
|
||||
|
||||
# toybox handling of empty capturing groups broke minjail. Check that we
|
||||
# correctly replace an empty capturing group with the empty string:
|
||||
testing '\n with empty capture' \
|
||||
'sed -E "s/(ARM_)?(NR_)([a-z]*) (.*)/\1\2\3/"' "NR_read" "" "NR_read foo"
|
||||
testcmd '\n with empty capture' \
|
||||
'-E "s/(ARM_)?(NR_)([a-z]*) (.*)/\1\2\3/"' "NR_read" "" "NR_read foo"
|
||||
# ...but also that we report an error for a backreference to a group that
|
||||
# isn't in the pattern:
|
||||
testing '\n too high' \
|
||||
'sed -E "s/(.*)/\2/p" 2>/dev/null || echo OK' "OK\n" "" "foo"
|
||||
testcmd '\n too high' '-E "s/(.*)/\2/p" 2>/dev/null || echo OK' "OK\n" "" "foo"
|
||||
|
||||
toyonly testcmd 's///x' '"s/(hello )?(world)/\2/x"' "world" "" "hello world"
|
||||
|
||||
SKIP=1
|
||||
# Performance test
|
||||
X=x; Y=20; while [ $Y -gt 0 ]; do X=$X$X; Y=$(($Y-1)); done
|
||||
testing 'megabyte s/x/y/g (5 sec timeout)' "timeout 5 sed 's/x/y/g' | sha1sum" \
|
||||
testing 'megabyte s/x/y/g (20 sec timeout)' \
|
||||
"timeout 20 sed 's/x/y/g' | sha1sum" \
|
||||
'138c1fa7c3f64186203b0192fb4abdb33cb4e98a -\n' '' "$X\n"
|
||||
unset X Y
|
||||
|
||||
testcmd "w doesn't blank" "-e 'w one' -e 'w one' -e d; cat one" \
|
||||
'hello\nhello\n' '' 'hello\n'
|
||||
|
||||
testcmd 's i and I' 's/o/0/ig' "f00l F00L" "" "fool FOOL"
|
||||
|
||||
testcmd 's l ignores posix' "-n 'N;l'" 'one\\ntwo$\n' '' 'one\ntwo\n'
|
||||
testcmd 's l loses missing newline' "-n 'N;l'" 'one\\ntwo$\n' '' 'one\ntwo'
|
||||
testcmd 's -z l' "-zn 'N;l'" 'one\\000two$\0' '' 'one\0two\0'
|
||||
testcmd 's -z l missing newline' "-zn 'N;l'" 'one\\000two$\0' '' 'one\0two'
|
||||
|
||||
testcmd 'count match' '"s/./&X/4"' '0123X45\n' '' '012345\n'
|
||||
|
||||
# -i with $ last line test
|
||||
|
||||
#echo meep | sed/sed -e '1a\' -e 'huh'
|
||||
#echo blah | sed/sed -f <(echo -e "1a\\\\\nboom")
|
||||
#echo merp | sed/sed "1a\\
|
||||
#hello"
|
||||
|
||||
@@ -69,3 +69,10 @@ testing "invalid increment" "seq 1 1f 1 2>/dev/null || echo y" "y\n" "" ""
|
||||
|
||||
# TODO: busybox fails this too, but GNU seems to not use double for large ints.
|
||||
#testing "too large for double" "seq -s, 9007199254740991 1 9007199254740992" "9007199254740992\n" "" ""
|
||||
|
||||
testing "INT_MIN" "seq -2147483648 -2147483647" "-2147483648\n-2147483647\n"\
|
||||
"" ""
|
||||
|
||||
# macOS doesn't include a timeout(1), nor a good alternative.
|
||||
skipnot [ "$(uname)" != "Darwin" ]
|
||||
testing "fast path" "timeout 10 seq 10000000 > /dev/null" "" "" ""
|
||||
|
||||
+10
-3
@@ -4,6 +4,13 @@
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
function clean()
|
||||
{
|
||||
# The filesystem may include some extended attributes by default (for
|
||||
# instance, security.selinux). Skip them.
|
||||
grep -v "security\."
|
||||
}
|
||||
|
||||
mkdir attrs
|
||||
touch attrs/file
|
||||
setfattr -n user.empty attrs/file
|
||||
@@ -11,11 +18,11 @@ setfattr -n user.data -v hello attrs/file
|
||||
setfattr -n user.delete-me -v hello attrs/file
|
||||
|
||||
testing "-x" \
|
||||
"setfattr -x user.delete-me attrs/file && getfattr attrs/file" \
|
||||
"setfattr -x user.delete-me attrs/file && getfattr attrs/file | clean" \
|
||||
"# file: attrs/file\nuser.data\nuser.empty\n\n" "" ""
|
||||
testing "-n" "setfattr -n user.new attrs/file && getfattr -d attrs/file" \
|
||||
testing "-n" "setfattr -n user.new attrs/file && getfattr -d attrs/file | clean" \
|
||||
"# file: attrs/file\nuser.data=\"hello\"\nuser.empty\nuser.new\n\n" "" ""
|
||||
testing "-n -v" "setfattr -n user.new -v data attrs/file && getfattr -d attrs/file" \
|
||||
testing "-n -v" "setfattr -n user.new -v data attrs/file && getfattr -d attrs/file | clean" \
|
||||
"# file: attrs/file\nuser.data=\"hello\"\nuser.empty\nuser.new=\"data\"\n\n" "" ""
|
||||
|
||||
rm -rf attrs
|
||||
|
||||
+801
-65
@@ -1,76 +1,812 @@
|
||||
#!/bin/bash
|
||||
#!/bin/echo no
|
||||
|
||||
[ -f testing.sh ] && . testing.sh
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
# TODO make fake pty wrapper for test infrastructure
|
||||
|
||||
if [ -z "$(which bash)" ]
|
||||
then
|
||||
echo "$SHOWSKIP: no bash alias"
|
||||
return 2>/dev/null
|
||||
exit
|
||||
fi
|
||||
# testing "name" "command" "result" "infile" "stdin"
|
||||
# texpect "name" "command" [R]I/O/E"string" X[ERR]
|
||||
|
||||
shellit()
|
||||
{
|
||||
EVAL="bash -c" testing "$2" "$1 printf %s $2" "$3" "$4" "$5"
|
||||
# Use "bash" name for host, "sh" for toybox. (/bin/sh is often defective.)
|
||||
[ -z "$SH" ] && { [ -z "$TEST_HOST" ] && SH="sh" || export SH="bash" ; }
|
||||
# The expected prompt is different for root vs normal user
|
||||
[ $UID -eq 0 ] && P='# ' || P='$ '
|
||||
# insulate shell child process to get predictable results
|
||||
SS="env -i PATH=${PATH@Q} PS1='\\$ ' $SH --noediting --noprofile --norc -is"
|
||||
|
||||
[ -z "$TEST_HOST" ] && : ${BROKEN=true}
|
||||
# Wrap txpect for shell testing
|
||||
shxpect() {
|
||||
X="$1"
|
||||
shift
|
||||
txpect "$X" "$SS" E"$P" "$@" X0
|
||||
}
|
||||
|
||||
# $'' expands special chars but doesn't do so inside double quotes.
|
||||
shxpect "prompt and exit" I$'exit\n'
|
||||
shxpect "prompt and echo" I$'echo hello\n' O$'hello\n' E"$P"
|
||||
shxpect "redir" I$'cat<<<hello\n' O$'hello\n' E"$P"
|
||||
shxpect "redirect err" I$'echo > /dev/full\n' E E"$P" X1
|
||||
shxpect "wait for <(exit)" I$'cat <(echo hello 1>&2)\n' E$'hello\n' E"$P"
|
||||
|
||||
shellit "" "\$'a\\tb'" "a\tb" "" ""
|
||||
shellit "" "\"\$'a\\tb'\"" '$'"'"'a\\tb'"'" "" ""
|
||||
# Test shell command line (-c and how scripts run) before changing EVAL
|
||||
testing '-c "" exit status 0' '$SH -c "" && echo $?' '0\n' '' ''
|
||||
testing '-c args' "\$SH -c 'echo \$0,\$1,\$2,\$3' one two three four five" \
|
||||
"one,two,three,four\n" "" ""
|
||||
testing '-c args2' "\$SH -c 'echo \${10}' a b c d e f g h i j k l" "k\n" "" ""
|
||||
testing '-c arg split' \
|
||||
"$SH -c 'for i in a\"\$@\"b;do echo =\$i=;done;echo \$0' 123 456 789" \
|
||||
"=a456=\n=789b=\n123\n" "" ""
|
||||
testing '-c arg split2' \
|
||||
"$SH -c 'for i in a\"\$* \$@\"b; do echo =\$i=;done' one two three four five"\
|
||||
"=atwo three four five two=\n=three=\n=four=\n=fiveb=\n" "" ""
|
||||
testing '-c arg count' "$SH -c 'echo \$#' 9 8 7 6 1 2 3 4" "7\n" "" ""
|
||||
testing 'trailing \' "$SH -c 'echo \'" '\\\n' '' ''
|
||||
testing "trailing \\ in ''" "$SH -c \$'echo \\'one\\\\\\ntwo\\''" \
|
||||
'one\\\ntwo\n' '' ''
|
||||
testing 'trailing \ in ""' "$SH -c \$'echo \"one\\\\\\ntwo\"'" 'onetwo\n' \
|
||||
'' ''
|
||||
testing 'vanishing \' "$SH -c \$'echo \\\\\\n a'" 'a\n' '' ''
|
||||
testing 'command\ arg' "$SH -c \$'echo\\\\\\n abc'" 'abc\n' '' ''
|
||||
testing "exec3" '$C -c "{ exec readlink /proc/self/fd/0;} < /proc/self/exe"' \
|
||||
"$(readlink -f $C)\n" "" ""
|
||||
testing 'arg shift' "$SH -c '"'for i in "" 2 1 1 1; do echo $? $1; shift $i; done'"' one two three four five" \
|
||||
"0 two\n0 three\n0 five\n0\n1\n" "" ""
|
||||
testing '(subshell)' '$SH -c "(echo hello)"' 'hello\n' '' ''
|
||||
testing 'syntax' '$SH -c "if true; then echo hello | fi" 2>/dev/null || echo x'\
|
||||
'x\n' '' ''
|
||||
testing 'syntax2' '$SH -c "for;i 0" 2>&1 | { grep -qi syntax && echo yes; }' \
|
||||
'yes\n' '' ''
|
||||
|
||||
# $(( )) tests
|
||||
# The bash man page is lying when it says $_ starts with an absolute path.
|
||||
ln -s "$(which $SH)" bash
|
||||
testing 'non-absolute $_' "./bash -c 'echo \$_'" './bash\n' '' ''
|
||||
rm bash
|
||||
|
||||
shellit 'x=1;' '$((-x))' '-1' '' ''
|
||||
shellit 'x=0;' '$((x++)); echo $x' '01\n' '' ''
|
||||
shellit 'x=0;' '$((++x))' '1' '' ''
|
||||
shellit 'x=0;' '$((~x))' '-1' '' ''
|
||||
shellit 'x=1;' '$((!x))' '0' '' ''
|
||||
shellit 'x=0;' '$((!x))' '1' '' ''
|
||||
shellit 'x=2;' '$((2*x))' '4' '' ''
|
||||
shellit 'x=9;' '$((x/4))' '2' '' ''
|
||||
shellit 'x=9;' '$((x%4))' '1' '' ''
|
||||
shellit 'x=4;' '$((x+2))' '6' '' ''
|
||||
shellit 'x=4;' '$((x-2))' '2' '' ''
|
||||
shellit 'x=4;' '$((1<<x))' '16' '' ''
|
||||
shellit 'x=4;' '$((x>>1))' '2' '' ''
|
||||
shellit '' '$((3**4))' '81' '' ''
|
||||
shellit '' '$((3<=4))' '1' '' ''
|
||||
shellit '' '$((3>=4))' '0' '' ''
|
||||
shellit '' '$((3<4))' '1' '' ''
|
||||
shellit '' '$((3>4))' '0' '' ''
|
||||
shellit '' '$((3==4))' '0' '' ''
|
||||
shellit '' '$((3!=4))' '1' '' ''
|
||||
shellit '' '$((6&4))' '4' '' ''
|
||||
shellit '' '$((4|2))' '6' '' ''
|
||||
shellit '' '$((6&&2))' '1' '' ''
|
||||
shellit '' '$((6||4))' '1' '' ''
|
||||
shellit '' '$((1?2:3))' '2' '' ''
|
||||
shellit 'x=2;' '$((x=3)); echo $x' '33\n' '' ''
|
||||
shellit 'x=2;' '$((x*=3)); echo $x' '66\n' '' ''
|
||||
shellit 'x=5;' '$((x/=2)); echo $x' '22\n' '' ''
|
||||
shellit 'x=9;' '$((x%=5)); echo $x' '44\n' '' ''
|
||||
shellit 'x=9;' '$((x-=3)); echo $x' '66\n' '' ''
|
||||
shellit 'x=3;' '$((x+=2)); echo $x' '55\n' '' ''
|
||||
shellit 'x=7;' '$((x&=13)); echo $x' '55\n' '' ''
|
||||
shellit 'x=5;' '$((x|=12)); echo $x' '1313\n' '' ''
|
||||
shellit 'x=5;' '$((x^=12)); echo $x' '99\n' '' ''
|
||||
shellit 'x=2;' '$((x<<=2)); echo $x' '88\n' '' ''
|
||||
shellit 'x=12;' '$((x>>=2)); echo $x' '33\n' '' ''
|
||||
shellit 'x=2;' '$((x++,5)); echo $x' '53\n' '' ''
|
||||
testing 'exec exitval' "$SH -c 'exec echo hello' && echo \$?" "hello\n0\n" "" ""
|
||||
testing 'simple script' '$SH input' 'input\n' 'echo $0' ''
|
||||
testing 'simple script2' '$SH ./input two;echo $?' './input+two\n42\n' \
|
||||
'\necho $0+$1\n\nexit 42' ''
|
||||
# this segfaults bash
|
||||
toyonly testing 'recursion guard' \
|
||||
'$SH input 2>/dev/null; [ $? -lt 128 ] && echo pass' 'pass\n' \
|
||||
'source input' ''
|
||||
testing '$LINENO 1' "$SH input" "1\n" 'echo $LINENO' ''
|
||||
|
||||
# echo $(ls -l #comment)
|
||||
# cat -</dev/null
|
||||
# cat -|xargs echo
|
||||
# cat -(ls)
|
||||
# echo -!
|
||||
# echo -{
|
||||
# echo -(
|
||||
# (echo -)
|
||||
# echo $
|
||||
# "echo \$(echo \"hello\nworld\")"
|
||||
# "echo \"one ;\ntwo\""
|
||||
# echo $(ls -l &)
|
||||
# echo one < /dev/null two
|
||||
mkdir sub
|
||||
echo echo hello > sub/script
|
||||
$BROKEN testing 'simple script in $PATH' "PATH='$PWD/sub:$PATH' $SH script" \
|
||||
'hello\n' '' ''
|
||||
rm -rf sub
|
||||
|
||||
testing "script file" "chmod +x input; ./input" "hello\n" "#!$C\necho hello" ""
|
||||
testing 'IFS $*' "$SH -c 'IFS=xy; echo \"\$*\"' one two tyree" "twoxtyree\n" \
|
||||
"" ""
|
||||
# Without the \n\n bash 5 emits SHLVL=0
|
||||
testing 'default exports' \
|
||||
"env -i \"$(which $SH)\" --noprofile --norc -c \$'env\n\n' | sort" \
|
||||
"PWD=$(pwd)\nSHLVL=1\n_=$(which env)\n" "" ""
|
||||
# toysh order of operations not matching bash
|
||||
#testing "leading assignment fail" \
|
||||
# "{ \$SH -c 'X=\${a?blah} > walroid';ls walroid;} 2>/dev/null" '' '' ''
|
||||
testing "lineno" "$SH input" "5 one\n6 one\n5 two\n6 two\n" \
|
||||
'#!/bin/bash\n\nfor i in one two\ndo\n echo $LINENO $i\n echo $LINENO $i\ndone\n' ""
|
||||
testing "eval0" "$SH -c 'eval echo \$*' one two three" "two three\n" "" ""
|
||||
|
||||
#########################################################################
|
||||
# Change EVAL to call sh -c for us, using "bash" explicitly for the host.
|
||||
export EVAL="timeout 10 $SH -c"
|
||||
|
||||
# From here on, tests run within the new shell by default.
|
||||
|
||||
testing 'return code' 'if false; then echo true; fi; echo $?' '0\n' '' ''
|
||||
testing 'return code 2' 'if true; then false; fi; echo $?' '1\n' '' ''
|
||||
testing 'return code 3' 'x=0; while [ $((x++)) -lt 2 ]; do echo $x; done; echo $?' '1\n2\n0\n' '' ''
|
||||
testing 'return code 4' 'false; A=B; echo $?' '0\n' '' ''
|
||||
testing 'local var +whiteout' \
|
||||
'l=X;x(){ local l=47; echo $l;unset l; echo l=$l;};x;echo $l' '47\nl=\nX\n' \
|
||||
'' ''
|
||||
testing 'escape passthrough' 'echo -e "a\nb\nc\td"' 'a\nb\nc\td\n' '' ''
|
||||
|
||||
testing 'trailing $ is literal' 'echo $' '$\n' '' ''
|
||||
testing 'work after HERE' $'cat<<0;echo hello\npotato\n0' 'potato\nhello\n' '' ''
|
||||
testing '<<\EOF' $'(cat<<EOF\n$PATH\nEOF\necho "$PATH") | sort -u | wc -l' \
|
||||
'1\n' '' ''
|
||||
testing "<<EOF''" $'(cat<<EOF\'\'\n$PATH\nEOF\necho "$PATH") | sort -u | wc -l'\
|
||||
'2\n' '' ''
|
||||
testing '<<\EOF' $'(cat<<\\EOF\n$PATH\nEOF\necho "$PATH") | sort -u | wc -l' \
|
||||
'2\n' '' ''
|
||||
testing '<< \' $'cat<<EOF\nabc\\\ndef\nEOF\n' 'abcdef\n' '' ''
|
||||
testing '<< "\"' $'cat<<\\EOF\nabc\\\ndef\nEOF\n' 'abc\\\ndef\n' '' ''
|
||||
testing '<<""' $'cat<<"";echo hello\npotato\n\necho huh' 'potato\nhello\nhuh\n'\
|
||||
'' ''
|
||||
$BROKEN testing '<< trailing \' $'cat<<EOF 2>/dev/null\nabcde\nnext\\\nEOF\nEOF' \
|
||||
'abcde\nnextEOF\n' '' ''
|
||||
$BROKEN testing '<< trailing \ 2' $'cat<<EOF\nabcde\nEO\\\nF\necho hello' \
|
||||
'abcde\nhello\n' '' ''
|
||||
testing '<< $(a)' $'cat<<$(a)\nx\n$(a)' 'x\n' '' ''
|
||||
testing 'HERE straddle' $'cat<<EOF;if true\nhello\nEOF\nthen echo also; fi' \
|
||||
'hello\nalso\n' '' ''
|
||||
$BROKEN testing '\\n in <<EOF' $'cat<<EO\\\nF\n$PATH\nEOF\n' "$PATH\n" "" ""
|
||||
testing '\\n in <<EOF with ""' $'cat<<EO\\\nF""\n$PATH\nEOF\n' '$PATH\n' '' ''
|
||||
$BROKEN testing '\\n in HERE terminator' $'cat<<EOF\nabc\nE\\\nOF\necho hello\n' \
|
||||
'abc\nhello\n' '' ''
|
||||
ln -s "$(which echo)" echo2
|
||||
testing "undelimited redirect doesn't eat prefix" './echo2</dev/null hello' \
|
||||
'hello\n' '' ''
|
||||
rm -f echo2
|
||||
testing 'prefix assignment is local' '{ echo $ABC; } {ABC}</dev/null; echo $3'\
|
||||
'10\n\n' '' ''
|
||||
testing 'double quotes' 'echo \x "\x" "\\" "\$" "\`"' 'x \x \ $ `\n' '' ''
|
||||
testing 'quoted line escapes' $'echo "\\\none" \'\\\ntwo\'' 'one \\\ntwo\n' '' ''
|
||||
testing 'escape makes argument' 'echo \ | wc -c' '2\n' '' ''
|
||||
|
||||
# TODO testing 'empty +() is literal' 'echo +()' '+()\n' '' ''
|
||||
|
||||
# shxpect "EOF" I$'<<EOF;echo hello'
|
||||
shxpect 'queued work after HERE' I$'<<0;echo hello\n' E"> " I$'0\n' O$'hello\n'
|
||||
shxpect '$_ preserved on assignment error' I$'true hello; a=1 b=2 c=${}\n' \
|
||||
E E"$P" I$'echo $_\n' O$'hello\n'
|
||||
shxpect '$_ preserved on prefix error' I$'true hello; a=1 b=2 c=${} true\n' \
|
||||
E E"$P" I$'echo $_\n' O$'hello\n'
|
||||
shxpect '$_ preserved on exec error' I$'true hello; ${}\n' \
|
||||
E E"$P" I$'echo $_\n' O$'hello\n'
|
||||
shxpect '$_ abspath on exec' I$'env | grep ^_=\n' O$'_=/usr/bin/env\n'
|
||||
testing '$_ literal after exec' 'env >/dev/null; echo $_' 'env\n' '' ''
|
||||
shxpect '$_ no path for builtin' I$'true; echo $_\n' O$'true\n'
|
||||
$BROKEN testing 'prefix is local for builtins' 'abc=123; abc=def unset abc; echo $abc' \
|
||||
'123\n' '' ''
|
||||
$BROKEN testing 'prefix localizes magic vars' \
|
||||
'SECONDS=123; SECONDS=345 true; echo $SECONDS' '123\n' '' ''
|
||||
shxpect 'body evaluated before variable exports' I$'a=x${} y${}\n' RE'y${}' X1
|
||||
testing '$NOTHING clears $_' 'true; $NOTHING; echo $_' '\n' '' ''
|
||||
testing 'assignment with redirect is persistent, not prefix' \
|
||||
'ABC=DEF > potato && rm potato && echo $ABC' 'DEF\n' '' ''
|
||||
$BROKEN testing '$_ with functions' 'true; x(){ echo $_;}; x abc; echo $_' \
|
||||
'true\nabc\n' '' ''
|
||||
|
||||
mkdir -p one/two/three
|
||||
testing 'cd in renamed dir' \
|
||||
'cd one/two/three && mv ../../../{one,four} && cd .. && echo ${PWD: -9:9}' \
|
||||
'/four/two\n' '' ''
|
||||
rm -rf one
|
||||
|
||||
testing "smoketest" "echo hello" "hello\n" "" ""
|
||||
testing "assignment" 'x=y; echo $x' 'y\n' '' ''
|
||||
testing "+= assignment" 'x+=abc; y=def; y+=$x; echo $y' 'defabc\n' '' ''
|
||||
testing "eval" "eval echo hello" "hello\n" "" ""
|
||||
testing "eval2" "eval 'echo hello'; echo $?" "hello\n0\n" "" ""
|
||||
testing "eval3" 'X="echo hello"; eval "$X"' "hello\n" "" ""
|
||||
testing "eval4" 'eval printf '=%s=' \" hello \"' "= hello =" "" ""
|
||||
NOSPACE=1 testing "eval5" 'eval echo \" hello \" | wc' ' 1 1 8' "" ""
|
||||
$BROKEN testing 'eval6' $'false; eval \'echo $?\'' '1\n' '' ''
|
||||
testing 'eval7' $'eval \'false\'; echo $?' '1\n' '' ''
|
||||
testing 'eval8' $'false; eval ''; echo $?' '0\n' '' ''
|
||||
$BROKEN testing 'eval9' $'A=echo; false; eval \'$A $?\'' '1\n' '' ''
|
||||
testing "exec" "exec echo hello" "hello\n" "" ""
|
||||
testing "exec2" "exec echo hello; echo $?" "hello\n" "" ""
|
||||
|
||||
# ; | && ||
|
||||
testing "semicolon" "echo one;echo two" "one\ntwo\n" "" ""
|
||||
testing "simple pipe" "echo hello | cat" "hello\n" "" ""
|
||||
testing "&&" "true && echo hello" "hello\n" "" ""
|
||||
testing "&&2" "false && echo hello" "" "" ""
|
||||
testing "||" "true || echo hello" "" "" ""
|
||||
testing "||2" "false || echo hello" "hello\n" "" ""
|
||||
testing "&& ||" "true && false && potato || echo hello" "hello\n" "" ""
|
||||
testing "&& after function" "x(){ false;};x && echo yes" "" "" ""
|
||||
testing "|| after function" "x(){ false;};x || echo yes" "yes\n" "" ""
|
||||
|
||||
# redirection
|
||||
|
||||
testing "redir1" "cat < input" "hello\n" "hello\n" ""
|
||||
testing "redir2" "echo blah >out; cat out" "blah\n" "" ""
|
||||
testing "redir3" "echo more >>out; cat out" "blah\nmore\n" "" ""
|
||||
testing "redir4" "touch /not/exist 2>out||grep -o /not/exist out" \
|
||||
"/not/exist\n" "" ""
|
||||
testing "redir5" "ls out /not/exist &> out2 || wc -l < out2" "2\n" "" ""
|
||||
testing "redir6" "ls out /not/exist &>>-abc || wc -l < ./-abc" "2\n" "" ""
|
||||
testing "redir7" "ls out /not/exist |& wc -l" "2\n" "" ""
|
||||
testing "redir8" 'echo -n $(<input)' "boing" "boing\n" ""
|
||||
shxpect "redir9" I$'echo hello > out 2>/does/not/exist\n' E E"$P" \
|
||||
I$'wc -l < out\n' O$'0\n'
|
||||
testing "redir10" 'echo hello 3<&3' "hello\n" "" ""
|
||||
testing "redir11" 'if :;then echo one;fi {abc}<input; cat <&$abc' \
|
||||
"one\npotato\n" "potato\n" ""
|
||||
rm -f out out2 ./-abc
|
||||
|
||||
# expansion
|
||||
|
||||
testing "tilde expansion" "echo ~" "$HOME\n" "" ""
|
||||
testing "tilde2" "echo ~/dir" "$HOME/dir\n" "" ""
|
||||
testing "bracket expansion" \
|
||||
"echo {A{a,b}B{c,d}C}" "{AaBcC} {AaBdC} {AbBcC} {AbBdC}\n" "" ""
|
||||
testing "brackets2" "echo {A{a,b}B{c,d}C,D}" "AaBcC AaBdC AbBcC AbBdC D\n" "" ""
|
||||
testing "brackets3" 'echo {A"b,c"D}' "{Ab,cD}\n" "" ""
|
||||
testing "brackets4" 'echo {A"bc",D}' "Abc D\n" "" ""
|
||||
testing "brackets5" 'echo {A,B,C' "{A,B,C\n" "" ""
|
||||
testing "brackets6" 'echo {{{{A,B},C}D},E}' "{AD} {BD} {CD} E\n" "" ""
|
||||
testing "brackets7" 'echo {{{a,b},c,{d,e}},f}' "a b c d e f\n" "" ""
|
||||
testing "brackets8" 'echo A{a{b,c{B,C}D}d{e,f},g{h,i}j}E' \
|
||||
"AabdeE AabdfE AacBDdeE AacBDdfE AacCDdeE AacCDdfE AghjE AgijE\n" "" ""
|
||||
testing "brackets9" 'echo A{B{C,D}E{N,O},F{G,H}I}J{K,L}M' \
|
||||
"ABCENJKM ABCENJLM ABCEOJKM ABCEOJLM ABDENJKM ABDENJLM ABDEOJKM ABDEOJLM AFGIJKM AFGIJLM AFHIJKM AFHIJLM\n" "" ""
|
||||
for i in /root /var/root /; do [ -e $i ] && EXPECT=$i && break; done
|
||||
testing "bracket+tilde" "echo {~,~root}/pwd" "$HOME/pwd $EXPECT/pwd\n" "" ""
|
||||
|
||||
# Slices
|
||||
|
||||
testing '${x#prefix}' 'x=abcde; echo ${x#abc}' 'de\n' '' ''
|
||||
testing '${x#short} ${x##long}' 'x=banana; echo ${x#b*n} ${x##b*n}' \
|
||||
'ana a\n' '' ''
|
||||
toyonly testing '${x#utf8}' 'x=aそcde; echo ${x##a?c}' 'de\n' '' ''
|
||||
testing '${x%y}' 'x=potato; echo ${x%t*o} ${x%%t*o}' 'pota po\n' '' ''
|
||||
testing 'x=${x%y}' 'x=potato; x=${x%t*o}; echo $x' 'pota\n' '' ''
|
||||
testing '${x%glob}' 'x=abc-def; echo ${x%-*f} ${x-*c}' 'abc abc-def\n' '' ''
|
||||
testing 'x=${x//y}' 'x=potato; x=${x//ta}; echo $x' 'poto\n' '' ''
|
||||
testing '${x^y}' 'x=aaaaa; echo ${x^a}' 'Aaaaa\n' '' ''
|
||||
testing '${x^^y}' 'x=abccdec; echo ${x^^c}; x=abcdec; echo ${x^^c}' \
|
||||
'abCCdeC\nabCdeC\n' '' ''
|
||||
testing '${x,y}' 'x=BBB; echo ${x,B}' 'bBB\n' '' ''
|
||||
testing '${x,,y}' 'x=POTATO; echo ${x,,} ${x,,?} ${x,,*} ${x,,T}' \
|
||||
'potato potato potato POtAtO\n' '' ''
|
||||
|
||||
mkdir -p abc/def/ghi
|
||||
touch www
|
||||
testing 'wildcards' 'echo w[v-x]w w[x-v]w abc/*/ghi' \
|
||||
'www w[x-v]w abc/def/ghi\n' '' ''
|
||||
testing 'hidden wildcards' \
|
||||
'touch .abc abc && echo *bc && echo and && echo .*bc' \
|
||||
'abc\nand\n.abc\n' '' ''
|
||||
|
||||
testing "backtick1" 'x=fred; echo `echo $x`' 'fred\n' "" ""
|
||||
testing "backtick2" 'x=fred; echo `x=y; echo $x`; echo $x' 'y\nfred\n' "" ""
|
||||
testing '$(( ) )' 'echo ab$((echo hello) | tr e x)cd' "abhxllocd\n" "" ""
|
||||
$BROKEN testing '$((x=y)) lifetime' 'a=boing; echo $a $a$((a=4))$a $a' 'boing boing44 4\n' '' ''
|
||||
|
||||
testing 'quote' "echo \"'\"" "'\n" "" ""
|
||||
|
||||
testing "math" 'echo $((1+2))' '3\n' '' ''
|
||||
testing "[oldmath]" 'echo $[1+2]' '3\n' '' ''
|
||||
testing "math basic priority" 'echo $((1+2*3**4))' '163\n' '' ''
|
||||
testing "math paren" 'echo $(((1+2)*3))' '9\n' '' ''
|
||||
testing "math spaces" 'echo $(( ( 1 + 2 ) * 7 - 5 ** 2 ))' '-4\n' '' ''
|
||||
testing "((<)) isn't redirect" '((1<2)) </dev/null && echo yes' 'yes\n' '' ''
|
||||
testing "((>)) isn't redirect" '((1>2)) </dev/null || echo yes' 'yes\n' '' ''
|
||||
testing "((not math) )" '((echo hello) )' 'hello\n' '' ''
|
||||
testing "preincrement" 'echo $((++x)); echo $x' '1\n1\n' '' ''
|
||||
testing "preincrement vs prefix plus" 'echo $((+++x)); echo $x' '1\n1\n' '' ''
|
||||
testing "predecrement" 'echo $((--x)); echo $x' '-1\n-1\n' '' ''
|
||||
testing "predecrement vs prefix minus" 'echo $((---x)); echo $x' '1\n-1\n' '' ''
|
||||
testing "minus-minus-minus" 'echo $((x---7)); echo $x' '-7\n-1\n' '' ''
|
||||
testing "x---y is x-- -y not x- --y" 'x=1 y=1; echo $((x---y)) $x $y' '0 0 1\n'\
|
||||
'' ''
|
||||
$BROKEN testing "nesting ? :" \
|
||||
'for((i=0;i<8;i++)); do echo $((i&1?i&2?1:i&4?2:3:4));done' \
|
||||
'4\n3\n4\n1\n4\n2\n4\n1\n' '' ''
|
||||
testing "inherited assignment suppression" 'echo $((0 ? (x++) : 2)); echo $x' \
|
||||
"2\n\n" "" ""
|
||||
testing "boolean vs logical" 'echo $((2|4&&8))' '1\n' '' ''
|
||||
testing "&& vs || priority" \
|
||||
'echo $((w++||x++&&y++||z++)) w=$w x=$x y=$y z=$z' \
|
||||
'0 w=1 x=1 y= z=1\n' '' ''
|
||||
testing "|| vs && priority" \
|
||||
'echo $((w++&&x++||y++&&z++)) w=$w x=$x y=$y z=$z' \
|
||||
'0 w=1 x= y=1 z=\n' '' ''
|
||||
$BROKEN shxpect '/0' I$'echo $((1/0)); echo here\n' E E"$P" I$'echo $?\n' O$'1\n'
|
||||
$BROKEN shxpect '%0' I$'echo $((1%0)); echo here\n' E E"$P" I$'echo $?\n' O$'1\n'
|
||||
$BROKEN shxpect '/=0' I$'echo $((x/=0)); echo here\n' E E"$P" I$'echo $?\n' O$'1\n'
|
||||
$BROKEN shxpect '%=0' I$'echo $((x%=0)); echo here\n' E E"$P" I$'echo $?\n' O$'1\n'
|
||||
|
||||
# Loops and flow control
|
||||
testing "case" 'for i in A C J B; do case "$i" in A) echo got A ;; B) echo and B ;; C) echo then C ;; *) echo default ;; esac; done' \
|
||||
"got A\nthen C\ndefault\nand B\n" "" ""
|
||||
testing 'case;;&' 'case wow in w?w) echo ok;;& wow) echo no; esac' 'ok\nno\n' \
|
||||
"" ""
|
||||
testing "case newlines" \
|
||||
$'case i\n\nin\n\na) echo one\n\n;;\n\ni)\n\necho two\n\n;;\n\nesac' \
|
||||
"two\n" "" ""
|
||||
testing "case block" \
|
||||
$'case X in\n X) printf %s "X" || { echo potato;} ;;\nesac' 'X' '' ''
|
||||
testing 'loop in && ||' \
|
||||
'false && for i in a b c; do echo $i; done || echo no' 'no\n' '' ''
|
||||
testing "continue" 'for i in a b c; do for j in d e f; do echo $i $j; continue 2; done; done' \
|
||||
"a d\nb d\nc d\n" "" ""
|
||||
$BROKEN testing "piped loops that don't exit" \
|
||||
'while X=$(($X+1)); do echo $X; done | while read i; do echo $i; done | head -n 5' \
|
||||
'1\n2\n3\n4\n5\n' '' ''
|
||||
|
||||
# <glinda>A variable occurred</glinda>
|
||||
|
||||
testing "expand" 'echo $PWD' "$(pwd)\n" "" ""
|
||||
testing "expand2" 'echo "$PWD"' "$(pwd)\n" "" ""
|
||||
testing "expand3" 'echo "$"PWD' '$PWD\n' "" ""
|
||||
testing "expand4" 'P=x; echo "$P"WD' 'xWD\n' "" ""
|
||||
testing "dequote" "echo one 'two' ''three 'fo'ur '\\'" \
|
||||
'one two three four \\\n' '' ''
|
||||
|
||||
testing "leading variable assignment" 'abc=def env | grep ^abc=; echo $abc' \
|
||||
"abc=def\n\n" "" ""
|
||||
testing "leading variable assignments" \
|
||||
"abc=def ghi=jkl env | egrep '^(abc|ghi)=' | sort; echo \$abc \$ghi" \
|
||||
"abc=def\nghi=jkl\n\n" "" ""
|
||||
$BROKEN testing "leading assignment occurs after parsing" \
|
||||
'abc=def; abc=ghi echo $abc' "def\n" "" ""
|
||||
testing "leading assignment space" 'X="abc def"; Y=$X; echo "$Y"' \
|
||||
"abc def\n" "" ""
|
||||
testing "leading assignment space2" \
|
||||
'chicken() { X="$@"; }; chicken a b c d e; echo "$X"' 'a b c d e\n' '' ''
|
||||
testing "leading assignment fail2" \
|
||||
"{ 1blah=123 echo hello;} 2>/dev/null || echo no" "no\n" "" ""
|
||||
testing "leading assignment redirect" \
|
||||
"blah=123 echo hello > walrus && ls walrus" "walrus\n" "" ""
|
||||
rm -f walrus
|
||||
|
||||
testing "{1..5}" "echo {1..5}" "1 2 3 4 5\n" "" ""
|
||||
testing "{5..1}" "echo {5..1}" "5 4 3 2 1\n" "" ""
|
||||
testing "{5..1..2}" "echo {5..1..2}" "5 3 1\n" "" ""
|
||||
testing "{a..z..-3}" "echo {a..z..-3}" "a d g j m p s v y\n" "" ""
|
||||
|
||||
mkfifo POIT
|
||||
testing 'background curly block' \
|
||||
'{ sed s/ll/xx/ POIT; }& echo hello > POIT; wait && echo yes' \
|
||||
'hexxo\nyes\n' '' ''
|
||||
rm -f POIT
|
||||
|
||||
$BROKEN testing 'background pipe block' \
|
||||
'if true; then { sleep .25;bzcat "$FILES"/blkid/ntfs.bz2; }& fi | wc -c' \
|
||||
'8388608\n' '' ''
|
||||
$BROKEN testing 'background variable assignment' 'X=x; X=y & echo $X' 'x\n' '' ''
|
||||
|
||||
#$ IFS=x X=xyxz; for i in abc${X}def; do echo =$i=; done
|
||||
#=abc=
|
||||
#=y=
|
||||
#=zdef=
|
||||
|
||||
testing "IFS whitespace before/after" \
|
||||
'IFS=" x"; A=" x " B=" x" C="x " D=x E=" "; for i in $A $B $C $D L$A L$B L$C L$D $A= $B= $C= $D= L$A= L$B= L$C= L$D=; do echo -n {$i}; done' \
|
||||
"{}{}{}{}{L}{L}{L}{L}{}{=}{}{=}{}{=}{}{=}{L}{=}{L}{=}{L}{=}{L}{=}" "" ""
|
||||
testing "quotes and whitespace" \
|
||||
'A=" abc def "; for i in ""$A""; do echo =$i=; done' \
|
||||
"==\n=abc=\n=def=\n==\n" "" ""
|
||||
testing "quotes and whitespace2" \
|
||||
'A=" abc def "; for i in """"$A""; do echo =$i=; done' \
|
||||
"==\n=abc=\n=def=\n==\n" "" ""
|
||||
testing "quotes and whitespace3" \
|
||||
'A=" abc def "; for i in ""x""$A""; do echo =$i=; done' \
|
||||
"=x=\n=abc=\n=def=\n==\n" "" ""
|
||||
|
||||
testing "IFS" 'IFS=x; A=abx; echo -n "$A"' "abx" "" ""
|
||||
testing "IFS2" 'IFS=x; A=abx; echo -n $A' "ab" "" ""
|
||||
testing "IFS3" 'IFS=x; echo "$(echo abx)"' "abx\n" "" ""
|
||||
testing "IFS4" 'IFS=x; echo $(echo abx)y' "ab y\n" "" ""
|
||||
testing "IFS5" 'IFS=xy; for i in abcxdefyghi; do echo =$i=; done' \
|
||||
"=abc def ghi=\n" "" ""
|
||||
testing "curly bracket whitespace" 'for i in {$,} ""{$,}; do echo ="$i"=; done'\
|
||||
'=$=\n=$=\n==\n' '' ''
|
||||
|
||||
testing 'empty $! is blank' 'echo $!' "\n" "" ""
|
||||
$BROKEN testing '$! = jobs -p' 'true & [ $(jobs -p) = $! ] && echo yes' "yes\n" "" ""
|
||||
|
||||
testing '$*' 'cc(){ for i in $*;do echo =$i=;done;};cc "" "" "" "" ""' \
|
||||
"" "" ""
|
||||
testing '$*2' 'cc(){ for i in "$*";do echo =$i=;done;};cc ""' \
|
||||
"==\n" "" ""
|
||||
testing '$*3... Flame. Flames. Flames, on the side of my face...' \
|
||||
'cc(){ for i in "$*";do echo =$i=;done;};cc "" ""' "= =\n" "" ""
|
||||
$BROKEN testing 'why... oh.' \
|
||||
'cc() { echo ="$*"=; for i in =$*=; do echo -$i-; done;}; cc "" ""; echo and; cc ""' \
|
||||
'= =\n-=-\n-=-\nand\n==\n-==-\n' "" ""
|
||||
testing 'really?' 'cc() { for i in $*; do echo -$i-; done;}; cc "" "" ""' \
|
||||
"" "" ""
|
||||
testing 'Sigh.' 'cc() { echo =$1$2=;}; cc "" ""' "==\n" "" ""
|
||||
testing '$*4' 'cc(){ for i in "$*";do echo =$i=;done;};cc "" "" "" "" ""' \
|
||||
"= =\n" "" ""
|
||||
testing '$*5' 'cc(){ for i in "$*";do echo =$i=;done;};cc "" "abc" ""' \
|
||||
"= abc =\n" "" ""
|
||||
|
||||
# creating empty arguments without quotes
|
||||
testing '$* + IFS' \
|
||||
'IFS=x; cc(){ for i in $*; do echo =$i=;done;};cc xabcxx' \
|
||||
"==\n=abc=\n==\n" "" ""
|
||||
testing '$@' 'cc(){ for i in "$@";do echo =$i=;done;};cc "" "" "" "" ""' \
|
||||
"==\n==\n==\n==\n==\n" "" ""
|
||||
testing "IFS10" 'IFS=bcd; A=abcde; for i in $A; do echo =$i=; done' \
|
||||
"=a=\n==\n==\n=e=\n" "" ""
|
||||
$BROKEN testing "IFS11" \
|
||||
'IFS=x; chicken() { for i in $@$@; do echo =$i=; done;}; chicken one "" abc dxf ghi' \
|
||||
"=one=\n==\n=abc=\n=d=\n=f=\n=ghione=\n==\n=abc=\n=d=\n=f=\n=ghi=\n" "" ""
|
||||
testing "IFS12" 'IFS=3;chicken(){ return 3;}; chicken;echo 3$?3' '3 3\n' "" ""
|
||||
|
||||
testing "IFS combinations" \
|
||||
'IFS=" x"; A=" x " B=" x" C="x " D=x E=" "; for i in $A $B $C $D L$A L$B L$C L$D $A= $B= $C= $D= L$A= L$B= L$C= L$D=; do echo -n {$i}; done' \
|
||||
"{}{}{}{}{L}{L}{L}{L}{}{=}{}{=}{}{=}{}{=}{L}{=}{L}{=}{L}{=}{L}{=}" "" ""
|
||||
|
||||
$BROKEN testing "! isn't special" "echo !" "!\n" "" ""
|
||||
testing "! by itself" '!; echo $?' "1\n" "" ""
|
||||
testing "! true" '! true; echo $?' "1\n" "" ""
|
||||
testing "! ! true" '! ! true; echo $?' "0\n" "" ""
|
||||
testing "! syntax err" '! echo 2>/dev/null < doesnotexist; echo $?' "0\n" "" ""
|
||||
|
||||
# The bash man page doesn't say quote removal here, and yet:
|
||||
testing "case quoting" 'case a in "a") echo hello;; esac' 'hello\n' "" ""
|
||||
|
||||
testing "subshell splitting" 'for i in $(true); do echo =$i=; done' "" "" ""
|
||||
testing "subshell split 2" 'for i in $(echo "one two thr"); do echo =$i=; done'\
|
||||
"=one=\n=two=\n=thr=\n" "" ""
|
||||
|
||||
# variable assignment argument splitting only performed for "$@"
|
||||
testing "assignment nosplit" 'X="one two"; Y=$X; echo $Y' "one two\n" "" ""
|
||||
testing "argument splitting" \
|
||||
'chicken() { for i in a"$@"b;do echo =$i=;done;}; chicken 123 456 789' \
|
||||
"=a123=\n=456=\n=789b=\n" "" ""
|
||||
testing "assignment nosplit2" 'pop(){ X="$@";};pop one two three; echo $X' \
|
||||
"one two three\n" "" ""
|
||||
|
||||
#testing "leading assignments don't affect current line" \
|
||||
# 'VAR=12345 echo ${VAR}a' "a\n" "" ""
|
||||
#testing "can't have space before first : but yes around arguments" \
|
||||
# 'BLAH=abcdefghi; echo ${BLAH: 1 : 3 }' "bcd\n" "" ""
|
||||
|
||||
testing "subshell exit err" '(exit 42); echo $?' "42\n" "" ""
|
||||
|
||||
# Same thing twice, but how do we cmp if exec exited?
|
||||
#testing 'exec and $$' testing 'echo $$;exec readlink /proc/self'
|
||||
|
||||
X="$(realpath $(which readlink))"
|
||||
testing "exec in paren" \
|
||||
'(exec readlink /proc/self/exe);echo hello' "$X\nhello\n" "" ""
|
||||
testing "exec in brackets" \
|
||||
"{ exec readlink /proc/self/exe;};echo hi" "$X\n" "" ""
|
||||
|
||||
NOSPACE=1 testing "curly brackets and pipe" \
|
||||
'{ echo one; echo two ; } | tee blah.txt; wc blah.txt' \
|
||||
"one\ntwo\n2 2 8 blah.txt\n" "" ""
|
||||
NOSPACE=1 testing "parentheses and pipe" \
|
||||
'(echo two;echo three)|tee blah.txt;wc blah.txt' \
|
||||
"two\nthree\n2 2 10 blah.txt\n" "" ""
|
||||
$BROKEN testing "pipe into parentheses" \
|
||||
'echo hello | (read i <input; echo $i; read i; echo $i)' \
|
||||
"there\nhello\n" "there\n" ""
|
||||
|
||||
$BROKEN testing "\$''" $'echo $\'abc\\\'def\\nghi\'' "abc'def\nghi\n" '' ''
|
||||
testing "shift shift" 'shift; shift; shift; echo $? hello' "1 hello\n" "" ""
|
||||
testing 'search cross $*' 'chicken() { echo ${*/b c/ghi}; }; chicken a b c d' \
|
||||
"a b c d\n" "" ""
|
||||
testing 'eval $IFS' 'IFS=x; X=x; eval abc=a${X}b 2>/dev/null; echo $abc' \
|
||||
"\n" '' ''
|
||||
$BROKEN testing '${@:3:5}' 'chicken() { for i in "${@:3:5}"; do echo =$i=; done; } ; chicken ab cd ef gh ij kl mn op qr' \
|
||||
'=ef=\n=gh=\n=ij=\n=kl=\n=mn=\n' '' ''
|
||||
$BROKEN testing '${*:3:5}' 'chicken() { for i in "${*:3:5}"; do unset IFS; echo =$i=; done; } ; IFS=x chicken ab cd ef gh ij kl mn op qr' \
|
||||
'=efxghxijxklxmn=\n' '' ''
|
||||
testing 'sequence check' 'IFS=x; X=abxcd; echo ${X/bxc/g}' 'agd\n' '' ''
|
||||
|
||||
# TODO: The txpect plumbing does not work right yet even on TEST_HOST
|
||||
#txpect "backtick0" "$SS" "E$P" 'IX=fred; echo `echo \\\\$x`'$'\n' 'Ofred' "E$P" X0
|
||||
#txpect "backtick1" "$SS" "E$P" 'IX=fred; echo `echo $x`'$'\n' 'Ofred'$'\n' "E$P" X0
|
||||
#txpect "backtick2" "$SS" "E$P" 'IX=fred; echo `x=y; echo $x`' $'Oy\n' "E$P" X0
|
||||
|
||||
shxpect '${ with newline' I$'HELLO=abc; echo ${HELLO/b/\n' E"> " I$'}\n' O$'a c\n'
|
||||
|
||||
testing 'here0' 'cat<<<hello' 'hello\n' '' ''
|
||||
shxpect 'here1' I$'POTATO=123; cat << EOF\n' E"> " \
|
||||
I$'$POTATO\n' E"> " I$'EOF\n' O$'123\n'
|
||||
shxpect 'here2' I$'POTATO=123; cat << E"O"F\n' E"> " \
|
||||
I$'$POTATO\n' E"> " I$'EOF\n' O$'$POTATO\n'
|
||||
testing 'here3' 'abc(){ cat <<< x"$@"yz;};abc one two "three four"' \
|
||||
"xone two three fouryz\n" "" ""
|
||||
testing 'here4' 'for i in one two three; do cat <<< "ab${i}de"; done' \
|
||||
'abonede\nabtwode\nabthreede\n' '' ''
|
||||
testing 'here5' $'cat << EOF && cat << EOF2\nEOF2\nEOF\nEOF\nEOF2' \
|
||||
'EOF2\nEOF\n' '' ''
|
||||
# Nothing is actually quoted, but there are quotes, therefore...
|
||||
testing 'here6' $'cat << EOF""\n$POTATO\nEOF' '$POTATO\n' '' ''
|
||||
# Not ambiguous when split, unlike <$FILENAME redirects
|
||||
$BROKEN testing 'here7' 'ABC="abc def"; cat <<< $ABC' 'abc def\n' '' ''
|
||||
# What does HERE expansion _not_ expand?
|
||||
testing 'here8' $'ABC="x y"\ncat << EOF\n~root/{"$ABC",def}\nEOF' \
|
||||
'~root/{"x y",def}\n' '' ''
|
||||
testing '<<- eats leading tabs before expansion, but not after' \
|
||||
$'A=$\'\\tone\'; cat <<- EOF\n\t\t$A\n\ttwo\nEOF' "\tone\ntwo\n" '' ''
|
||||
|
||||
testing '${var}' 'X=abcdef; echo ${X}' 'abcdef\n' '' ''
|
||||
testing '${#}' 'X=abcdef; echo ${#X}' "6\n" "" ""
|
||||
testing 'empty ${}' '{ echo ${};} 2>&1 | grep -o bad' 'bad\n' '' ''
|
||||
$BROKEN shxpect 'empty ${} syntax err abort' I$'echo ${}; echo hello\n' \
|
||||
E I$'echo and\n' O$'and\n'
|
||||
$BROKEN testing '${$b}' '{ echo ${$b};} 2>&1 | grep -o bad' 'bad\n' '' ''
|
||||
testing '${!PATH*}' 'echo ${!PATH*}' 'PATH\n' '' ''
|
||||
testing '${!PATH@}' 'echo ${!PATH@}' 'PATH\n' '' ''
|
||||
#testing '${!PATH[@]}' 'echo ${!PATH[@]}' '0\n' '' ''
|
||||
testing '${!x}' 'X=abcdef Y=X; echo ${!Y}' 'abcdef\n' '' ''
|
||||
testing '${!x@}' 'ABC=def; def=ghi; echo ${!ABC@}' 'ABC\n' '' ''
|
||||
$BROKEN testing '${!x} err' '{ X=abcdef Y=X:2; echo ${!Y}; echo bang;} 2>/dev/null' \
|
||||
'' '' ''
|
||||
testing '${!x*}' 'abcdef=1 abc=2 abcq=; echo "${!abc@}" | tr " " \\n | sort' \
|
||||
'abc\nabcdef\nabcq\n' '' ''
|
||||
testing '${!x*} none' 'echo "${!abc*}"' '\n' '' ''
|
||||
$BROKEN testing '${!x*} err' '{ echo "${!abc*x}"; echo boing;} 2>/dev/null' '' '' ''
|
||||
# TODO bash 5.x broke this
|
||||
#testing '${!none@Q}' 'echo ${X@Q} ${!X@Q}; X=ABC; echo ${!X@Q}' '\n\n' '' ''
|
||||
$BROKEN testing '${!x@Q}' 'ABC=123 X=ABC; echo ${!X@Q}' "'123'\n" '' ''
|
||||
$BROKEN testing '${#@Q}' 'echo ${#@Q}' "'0'\n" '' ''
|
||||
$BROKEN testing '${!*}' 'xx() { echo ${!*};}; fruit=123; xx fruit' '123\n' '' ''
|
||||
$BROKEN testing '${!*} indirect' 'xx() { echo ${!a@Q};}; a=@; xx one two three' \
|
||||
"'one' 'two' 'three'\n" '' ''
|
||||
$BROKEN testing '${!x@ } match' \
|
||||
'{ ABC=def; def=ghi; echo ${!ABC@ }; } 2>&1 | grep -o bad' 'bad\n' '' ''
|
||||
# Bash added an error for this between 4.4 and 5.x.
|
||||
#testing '${!x@ } no match no err' 'echo ${!ABC@ }def' 'def\n' '' ''
|
||||
$BROKEN testing '${!x@ } no match no err2' 'ABC=def; echo ${!ABC@ }ghi' 'ghi\n' '' ''
|
||||
toyonly testing '${#x::}' 'ABC=abcdefghijklmno; echo ${#ABC:1:2}' '5\n' '' ''
|
||||
# TODO: ${!abc@x} does _not_ error? And ${PWD@q}
|
||||
testing '$""' 'ABC=def; echo $"$ABC"' 'def\n' '' ''
|
||||
testing '"$""" does not nest' 'echo "$"abc""' '$abc\n' '' ''
|
||||
$BROKEN testing '${\}}' 'ABC=ab}cd; echo ${ABC/\}/x}' 'abxcd\n' '' ''
|
||||
testing 'bad ${^}' '{ echo ${^};} 2>&1 | grep -o bad' 'bad\n' '' ''
|
||||
shxpect '${:} empty len is err' I$'ABC=def; echo ${ABC:}\n' RE'ABC' X
|
||||
testing '${::} both empty=0' 'ABC=def; echo ${ABC::}' '\n' '' ''
|
||||
testing '${::} first empty' 'ABC=def; echo ${ABC: : 2 }' 'de\n' '' ''
|
||||
testing '${::} second empty' 'ABC=def; echo ${ABC: 2 : }' '\n' '' ''
|
||||
testing '${:}' 'ABC=def; echo ${ABC:1}' 'ef\n' '' ''
|
||||
testing '${a: }' 'ABC=def; echo ${ABC: 1}' 'ef\n' '' ''
|
||||
$BROKEN testing '${a :}' 'ABC=def; { echo ${ABC :1};} 2>&1 | grep -o bad' 'bad\n' '' ''
|
||||
testing '${::}' 'ABC=defghi; echo ${ABC:1:2}' 'ef\n' '' ''
|
||||
testing '${: : }' 'ABC=defghi; echo ${ABC: 1 : 2 }' 'ef\n' '' ''
|
||||
testing '${::} indirect' \
|
||||
'ABC=defghi:1:2; ( echo ${!ABC};) 2>input; [ -s input ] && echo yes' \
|
||||
'yes\n' '' ''
|
||||
testing '${::-}' 'ABC=defghi; echo ${ABC:1:-2}' 'efg\n' '' ''
|
||||
testing '${:-:-}' 'ABC=defghi; echo ${ABC:-3:2}' 'defghi\n' '' ''
|
||||
testing '${:-:-}2' 'echo ${ABC:-3:2}' '3:2\n' '' ''
|
||||
testing '${: -:}' 'ABC=defghi; echo ${ABC: -3:2}' 'gh\n' '' ''
|
||||
testing '${@%}' 'chicken() { for i in "${@%abc}"; do echo "=$i="; done;}; chicken 1abc 2abc 3abc' '=1=\n=2=\n=3=\n' '' ''
|
||||
testing '${*%}' 'chicken() { for i in "${*%abc}"; do echo "=$i="; done;}; chicken 1abc 2abc 3abc' '=1 2 3=\n' '' ''
|
||||
$BROKEN testing '${@@Q}' 'xx() { echo "${@@Q}"; }; xx one two three' \
|
||||
"'one' 'two' 'three'\n" '' ''
|
||||
|
||||
shxpect '${/newline/}' I$'x=$\'\na\';echo ${x/\n' E'> ' I$'/b}\n' O$'ba\n' E'> '
|
||||
|
||||
shxpect 'line continuation' I$'echo "hello" \\\n' E'> ' I$'> blah\n' E"$P" \
|
||||
I$'wc blah\n' O$'1 1 6 blah\n'
|
||||
shxpect 'line continuation2' I$'echo ABC\\\n' E'> ' I$'DEF\n' O$'ABCDEF\n'
|
||||
testing "line continuation3" $'ec\\\nho hello' 'hello\n' '' ''
|
||||
testing "line continuation4" $'if true | \\\n(true);then echo true;fi' 'true\n' '' ''
|
||||
$BROKEN testing "line continuation5" $'XYZ=xyz; echo "abc$\\\nXYZ"' 'abcxyz\n' '' ''
|
||||
|
||||
# Race condition (in bash, but not in toysh) can say 43.
|
||||
$BROKEN testing 'SECONDS' 'readonly SECONDS=41; sleep 1; echo $SECONDS' '42\n' '' ''
|
||||
# testing 'SECONDS2' 'readonly SECONDS; SECONDS=0; echo $SECONDS' '' '' '' #bash!
|
||||
$BROKEN testing 'SECONDS2' 'SECONDS=123+456; echo $SECONDS' '0\n' '' '' #bash!!
|
||||
testing '$LINENO 2' $'echo $LINENO\necho $LINENO' '1\n2\n' '' ''
|
||||
testing '$EUID' 'echo $EUID' "$(id -u)\n" '' ''
|
||||
testing '$UID' 'echo $UID' "$(id -ur)\n" '' ''
|
||||
|
||||
$BROKEN testing 'readonly leading assignment' \
|
||||
'{ readonly abc=123;abc=def echo hello; echo $?;} 2>output; grep -o readonly output' \
|
||||
'hello\n0\nreadonly\n' '' ''
|
||||
$BROKEN testing 'readonly leading assignment2' \
|
||||
'readonly boink=123; export boink; { boink=234 env | grep ^boink=;} 2>/dev/null; echo $?' 'boink=123\n0\n' '' ''
|
||||
$BROKEN testing 'readonly for' \
|
||||
'readonly i; for i in one two three; do echo $i; done 2>/dev/null; echo $?' \
|
||||
'1\n' '' ''
|
||||
$BROKEN testing 'readonly {}<' \
|
||||
'readonly i; echo hello 2>/dev/null {i}</dev/null; echo $?' '1\n' '' ''
|
||||
testing '$_ 1' 'echo walrus; echo $_' 'walrus\nwalrus\n' '' ''
|
||||
testing '$_ 2' 'unset _; echo $_' '_\n' '' ''
|
||||
|
||||
# wildcards
|
||||
|
||||
touch walrus wallpapers
|
||||
testing 'IFS wildcards' \
|
||||
'IFS=xy; ABC=abcywal*sxdef; echo $ABC | tr " " "\n" | sort' \
|
||||
'abc\ndef\nwallpapers\nwalrus\n' '' ''
|
||||
rm -f walrus wallpapers
|
||||
|
||||
# Force parsing granularity via interactive shxpect because bash parses all
|
||||
# of sh -c "str" in one go, meaning the "shopt -s extglob" won't take effect
|
||||
$BROKEN shxpect 'IFS +(extglob)' I$'shopt -s extglob\n' E"$P" \
|
||||
I$'IFS=x; ABC=cxd; for i in +($ABC); do echo =$i=; done\n' \
|
||||
O$'=+(c=\n' O$'=d)=\n'
|
||||
|
||||
touch abc\)d
|
||||
$BROKEN shxpect 'IFS +(extglob) 2' I$'shopt -s extglob\n' E"$P" \
|
||||
I$'ABC="c?d"; for i in ab+($ABC); do echo =$i=; done\n' \
|
||||
O$'=abc)d=\n'
|
||||
rm abc\)d
|
||||
|
||||
$BROKEN shxpect '[+(]) overlap priority' I$'shopt -s extglob\n' E"$P" \
|
||||
I$'touch "AB[DEF]"; echo AB[+(DEF]) AB[+(DEF)? AB+([DEF)]\n' \
|
||||
O$'AB[+(DEF]) AB[DEF] AB+([DEF)]\n' \
|
||||
I$'X="("; Y=")"; echo AB[+${X}DEF${Y}?\n' O$'AB[DEF]\n'
|
||||
|
||||
# TODO: syntax error takes out ': ${a?b}; echo $?' (I.E. never runs echo)
|
||||
shxpect '${a?b} sets err, stops cmdline eval' \
|
||||
I$': ${a?b} ${c:=d}\n' E E"$P" I$'echo $?$c\n' O$'1\n'
|
||||
|
||||
$BROKEN shxpect 'trace redirect' I$'set -x; echo one\n' E$'+ echo one\n'"$P" O$'one\n' \
|
||||
I$'echo two 2>/dev/null\n' O$'two\n' E$'+ echo two\n'"$P" \
|
||||
I$'{ echo three; } 2>/dev/null\n' O$'three\n' E"$P"
|
||||
shxpect 'set -u' I$'set -u; echo $walrus\n' REwalrus X
|
||||
|
||||
testing 'source file' 'source input' 'hello\n' 'echo hello \\\n' ''
|
||||
testing '. file' '. input' 'hello\n' 'echo hello \\\n' ''
|
||||
testing 'source no newline' 'source input' 'hello \\\n' 'echo hello \\' ''
|
||||
testing 'source continues' 'echo hello; source <(echo false); echo $?' \
|
||||
'hello\n1\n' '' ''
|
||||
testing 'source returns' 'source <(echo return 37); echo $?' '37\n' '' ''
|
||||
testing 'source is live' \
|
||||
'for i in one two three; do echo "echo $i" > input; source input; done' \
|
||||
'one\ntwo\nthree\n' 'x' ''
|
||||
testing 'source is live in functions' \
|
||||
'func() { source input; }; for i in one two three; do echo echo $i > input; func; done' \
|
||||
'one\ntwo\nthree\n' 'x' ''
|
||||
testing 'subshell inheritance' \
|
||||
'func() { source input; cat <(echo $xx; xx=456; echo $xx); echo $xx;}; echo local xx=123 > input; func; echo $xx' \
|
||||
'123\n456\n123\n\n' 'x' ''
|
||||
$BROKEN testing 'semicolon vs newline' \
|
||||
'source input 2>/dev/null || echo yes' 'one\nyes\n' \
|
||||
'echo one\necho two; echo |' ''
|
||||
$BROKEN testing 'syntax err pops to source but encapsulating function continues' \
|
||||
'func() { echo one; source <(echo -e "echo hello\necho |") 2>/dev/null; echo three;}; func; echo four' \
|
||||
'one\nhello\nthree\nfour\n' '' ''
|
||||
$BROKEN testing '"exit shell" means exit eval but encapsulating function continues' \
|
||||
'func() { eval "echo one; echo \${?potato}; echo and" 2>/dev/null; echo plus;}; func; echo then' \
|
||||
'one\nplus\nthen\n' '' ''
|
||||
$BROKEN testing 'return needs function or source' \
|
||||
'cat <(return 0 2>/dev/null; echo $?); echo after' '2\nafter\n' '' ''
|
||||
testing 'return nests' 'y(){ x; return $((3+$?));};x(){ return 5; };y;echo $?' \
|
||||
'8\n' '' ''
|
||||
|
||||
shxpect "functions need block" I$'x() echo;\n' RE'[Ss]yntax [Ee]rror' X2
|
||||
testing 'functions() {} in same PID' \
|
||||
'{ echo $BASHPID; chicken() { echo $BASHPID;}; chicken;} | sort -u | wc -l' '1\n' '' ''
|
||||
testing 'functions() () different PID' \
|
||||
'{ echo $BASHPID; chicken() ( echo $BASHPID;); chicken;} | sort -u | wc -l' '2\n' '' ''
|
||||
testing 'function() just wants any block span' \
|
||||
'func() if true; then echo hello; fi; echo one; func; echo two' \
|
||||
'one\nhello\ntwo\n' '' ''
|
||||
testing 'function alternate syntax' \
|
||||
'function func if true; then echo hello; fi; echo one; func; echo two' \
|
||||
'one\nhello\ntwo\n' '' ''
|
||||
testing 'function syntax 3' \
|
||||
'function func ( ) if true; then echo hello; fi; echo one; func; echo two' \
|
||||
'one\nhello\ntwo\n' '' ''
|
||||
testing 'function nested parentheses' \
|
||||
'( potato() { echo aaa; }; potato )' 'aaa\n' '' ''
|
||||
shxpect 'local creates a whiteout' \
|
||||
I$'func() { local potato; echo ${potato?bang}; }; potato=123; func\n' \
|
||||
E E"$P" I$'echo $?\n' O$'1\n'
|
||||
testing 'local replaces/preserves magic type' \
|
||||
'x() { local RANDOM=potato; echo $RANDOM;};x;echo -e "$RANDOM\n$RANDOM"|wc -l'\
|
||||
'potato\n2\n' '' ''
|
||||
|
||||
$BROKEN testing '$$ is parent shell' \
|
||||
'{ echo $$; (echo $$) } | sort -u | wc -l' "1\n" "" ""
|
||||
$BROKEN testing '$PPID is parent shell' \
|
||||
'{ echo $PPID; (echo $PPID) } | sort -u | wc -l' "1\n" "" ""
|
||||
$BROKEN testing '$BASHPID is current PID' \
|
||||
'{ echo $BASHPID; (echo $BASHPID) } | sort -u | wc -l' "2\n" "" ""
|
||||
|
||||
testing 'unexport supports +=' 'export -n ABC+=DEF; declare -p ABC' \
|
||||
'declare -- ABC="DEF"\n' '' ''
|
||||
$BROKEN testing 'unexport existing +=' \
|
||||
'export ABC=XYZ; export -n ABC+=DEF; declare -p ABC' \
|
||||
'declare -- ABC="XYZDEF"\n' '' ''
|
||||
|
||||
$BROKEN testing '$!' '{ echo $BASHPID & echo $!; echo ${!};} | sort -u | wc -l' '1\n' \
|
||||
'' ''
|
||||
|
||||
shxpect 'blank line preserves $?' \
|
||||
I$'false\n' E"$P" I$'\n' E"$P" I$'echo $?\n' O$'1\n'
|
||||
testing 'NOP line clears $?' 'false;$NOTHING;echo $?' '0\n' '' ''
|
||||
$BROKEN testing 'run "$@"' 'false;"$@";echo $?' '0\n' '' ''
|
||||
|
||||
# "Word splitting... not performed on the words between the [[ and ]]"
|
||||
testing '[[split1]]' 'A="1 -lt 2"; [[ $A ]] && echo yes' 'yes\n' '' ''
|
||||
testing '[[split2]]' 'A="2 -lt 1"; [[ $A ]] && echo yes' 'yes\n' '' ''
|
||||
testing '[[split3]]' \
|
||||
'A="2 -lt 1"; [[ -e $A ]] && echo one; touch "$A" && [[ -e $A ]] && echo two'\
|
||||
'two\n' '' ''
|
||||
rm -f '2 -lt 1'
|
||||
testing '[[split4]]' \
|
||||
'[[ $(cat) == "a b" ]] <<< "a b" > potato && rm potato && echo ok' \
|
||||
'ok\n' '' ''
|
||||
$BROKEN testing '[[split5]]' \
|
||||
'[[ $(cat) == "a b" ]] < <(echo a b) > potato && rm potato && echo ok' \
|
||||
'ok\n' '' ''
|
||||
# And token parsing leaking through: 1>2 is an error, 1 >2 is not
|
||||
testing '[[1>2]] is not a redirect' '[[ 1 >2 ]] || [ -e 2 ] || echo yup' \
|
||||
'yup\n' '' ''
|
||||
testing "[[1 >0]] doesn't need that second space" \
|
||||
'[[ 1 >0 ]] && { [ -e 2 ] || echo yup; }' 'yup\n' '' ''
|
||||
testing '[[1<2]] is alphabetical, not numeric' '[[ 123 < 19 ]] && echo yes' \
|
||||
'yes\n' '' ''
|
||||
testing '[[~]]' '[[ ~ == $HOME ]] && echo yes' 'yes\n' '' ''
|
||||
|
||||
# The trailing space is because the \n gets stripped off otherwise
|
||||
testing 'quoting contexts nest' \
|
||||
$'echo -n "$(echo "hello $(eval $\'echo -\\\\\\ne \\\'world\\n \\\'\')")"' \
|
||||
'hello world\n ' '' ''
|
||||
testing "\$'' suppresses variable expansion" \
|
||||
$'echo $\'$(abc\'' '$(abc\n' '' ''
|
||||
|
||||
testing 'if; is a syntax error but if $EMPTY; is not' \
|
||||
'if $NONE; then echo hello; fi' 'hello\n' '' ''
|
||||
|
||||
# TODO finish variable list from shell init
|
||||
|
||||
# $# $? $- $! $0 # $$
|
||||
# always exported: PWD SHLVL _
|
||||
# ./bash -c 'echo $_' prints $BASH, but PATH search shows path? Hmmm...
|
||||
# ro: UID PPID EUID $
|
||||
# IFS LINENO
|
||||
# PATH HOME SHELL USER LOGNAME SHLVL HOSTNAME HOSTTYPE MACHTYPE OSTYPE OLDPWD
|
||||
# PS0 PS1='$ ' PS2='> ' PS3 PS4 BASH BASH_VERSION
|
||||
# ENV - if [ -n "$ENV" ]; then . "$ENV"; fi # BASH_ENV - synonym for ENV
|
||||
# FUNCNEST - maximum function nesting level (abort when above)
|
||||
# REPLY - set by input with no args
|
||||
# OPTARG OPTIND - set by getopts builtin
|
||||
# OPTERR
|
||||
|
||||
# maybe not: EXECIGNORE, FIGNORE, GLOBIGNORE
|
||||
|
||||
#BASH_SUBSHELL - SHLVL synonym
|
||||
#BASH_EXECUTION_STRING - -c argument
|
||||
#
|
||||
#automatically set:
|
||||
#OPTARG - set by getopts builtin
|
||||
#OPTIND - set by getopts builtin
|
||||
#
|
||||
#PROMPT_COMMAND PROMPT_DIRTRIM PS0 PS1 PS2 PS3 PS4
|
||||
#
|
||||
#unsettable (assignments ignored before then)
|
||||
#LINENO SECONDS RANDOM
|
||||
#GROUPS - id -g
|
||||
#HISTCMD - history number
|
||||
#
|
||||
#TMOUT - used by read
|
||||
|
||||
# does not match: ./sh -c 'echo {a..Z}' becomes a ` _ ^ ] \ [ Z
|
||||
|
||||
# commit ec6639407b9e
|
||||
#- IS_TOYBOX_RE='(toybox|This is not GNU).*'
|
||||
#- [[ "$IS_TOYBOX" =~ $IS_TOYBOX_RE ]] || SKIPNEXT=1
|
||||
#+ case "$IS_TOYBOX" in
|
||||
#+ toybox*) ;;
|
||||
#+ This\ is\ not\ GNU*) ;;
|
||||
#+ *) SKIPNEXT=1 ;;
|
||||
#+ esac
|
||||
|
||||
# TODO: categorize tests
|
||||
|
||||
# TODO https://mywiki.wooledge.org/BashFAQ
|
||||
# http://tiswww.case.edu/php/chet/bash/FAQ
|
||||
# https://mywiki.wooledge.org/BashPitfalls#set_-euo_pipefail
|
||||
|
||||
# // ${#} ${#x} ${#@} ${#x[@]} ${#!} ${!#}
|
||||
# // ${!} ${!@} ${!@Q} ${!x} ${!x@} ${!x@Q} ${!x#} ${!x[} ${!x[*]}
|
||||
|
||||
# Looked like a prefix but wasn't: three chars (@ # -) are both paremeter name
|
||||
# and slice operator. When immediately followed by } it's parameter, otherwise
|
||||
# we did NOT have a prefix and it's an operator.
|
||||
#
|
||||
# ${#-} ${#-abc}
|
||||
# ${##} ${##0}
|
||||
# ${#@} ${#@Q}
|
||||
#
|
||||
# backslash not discarded: echo "abc\"def"
|
||||
|
||||
# ${x:-y} use default
|
||||
# ${x:=y} assign default (error if positional)
|
||||
# ${x:?y} err if null
|
||||
# ${x:+y} alt value
|
||||
# ${x:off} ${x:off:len} off<0 from end (must ": -"), len<0 also from end must
|
||||
# 0-based indexing
|
||||
# ${@:off:len} positional parameters, off -1 = len, -len is error
|
||||
# 1-based indexing
|
||||
|
||||
# [] wins over +()
|
||||
# touch 'AB[DEF]'; echo AB[+(DEF]) AB[+(DEF)?
|
||||
# AB[+(DEF]) AB[DEF]
|
||||
|
||||
# Testing shell corner cases _within_ a shell script is kind of hard.
|
||||
|
||||
+58
-45
@@ -6,52 +6,65 @@
|
||||
|
||||
# These tests are based on RFC3174 which were based on FIPS PUB 180-1
|
||||
|
||||
testing "TEST1" \
|
||||
"sha1sum" \
|
||||
"a9993e364706816aba3e25717850c26c9cd0d89d -\n" \
|
||||
"" "abc"
|
||||
case "$CMDNAME" in
|
||||
sha1sum)
|
||||
ABC=a9993e364706816aba3e25717850c26c9cd0d89d
|
||||
ABCLONG=84983e441c3bd26ebaae4aa1f95129e5e54670f1
|
||||
MILNUL=34aa973cd4c4daa4f61eeb2bdbad27316534016f
|
||||
DIGITS=dea356a2cddd90c7a7ecedc5ebb563934f460452
|
||||
DEF=589c22335a381f122d129225f5c0ba3056ed5811
|
||||
SEQ=f70b7b8768a1183d6d1cd79d3b076d9eb5156350
|
||||
;; sha224sum)
|
||||
ABC=23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7
|
||||
ABCLONG=75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525
|
||||
MILNUL=20794655980c91d8bbb4c1ea97618a4bf03f42581948b2ee4ee7ad67
|
||||
DIGITS=567f69f168cd7844e65259ce658fe7aadfa25216e68eca0eb7ab8262
|
||||
DEF=b6773126557f37fbc9b24e7b6adedc05d3eb3923fe3feeb369812d16
|
||||
SEQ=d8b406f661bc690a1f58241f37c94e04d0a1af74af867b877778f18e
|
||||
;; sha256sum)
|
||||
ABC=ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
|
||||
ABCLONG=248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1
|
||||
MILNUL=cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0
|
||||
DIGITS=594847328451bdfa85056225462cc1d867d877fb388df0ce35f25ab5562bfbb5
|
||||
DEF=cb8379ac2098aa165029e3938a51da0bcecfc008fd6795f401178647f96c5b34
|
||||
SEQ=8060aa0ac20a3e5db2b67325c98a0122f2d09a612574458225dcb9a086f87cc3
|
||||
;; sha384sum)
|
||||
ABC=cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7
|
||||
ABCLONG=3391fdddfc8dc7393707a65b1b4709397cf8b1d162af05abfe8f450de5f36bc6b0455a8520bc4e6f5fe95b1fe3c8452b
|
||||
MILNUL=9d0e1809716474cb086e834e310a4a1ced149e9c00f248527972cec5704c2a5b07b8b3dc38ecc4ebae97ddd87f3d8985
|
||||
DIGITS=2fc64a4f500ddb6828f6a3430b8dd72a368eb7f3a8322a70bc84275b9c0b3ab00d27a5cc3c2d224aa6b61a0d79fb4596
|
||||
DEF=180c325cccb299e76ec6c03a5b5a7755af8ef499906dbf531f18d0ca509e4871b0805cac0f122b962d54badc6119f3cf
|
||||
SEQ=7d2a49098f0df0f3c152ca9916a3864542258b2bd487e00ea33cb68e7d27c5c0f25b540d29f62fb33720846073c51b66
|
||||
;; sha512sum)
|
||||
ABC=ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f
|
||||
ABCLONG=204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445
|
||||
MILNUL=e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973ebde0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b
|
||||
DIGITS=89d05ba632c699c31231ded4ffc127d5a894dad412c0e024db872d1abd2ba8141a0f85072a9be1e2aa04cf33c765cb510813a39cd5a84c4acaa64d3f3fb7bae9
|
||||
DEF=40a855bf0a93c1019d75dd5b59cd8157608811dd75c5977e07f3bc4be0cad98b22dde4db9ddb429fc2ad3cf9ca379fedf6c1dc4d4bb8829f10c2f0ee04a66663
|
||||
SEQ=3000c8961bb83de289fa8b407d0ea23f53a57ea11ddb0f782a4ccc0f586780822946053132794b177823c2974873d5dfb2ab1b6c45ae3328e2e703ca907f54d7
|
||||
;; sha3sum)
|
||||
ABC=e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf
|
||||
ABCLONG=8a24108b154ada21c9fd5574494479ba5c7e7ab76ef264ead0fcce33
|
||||
MILNUL=d69335b93325192e516a912e6d19a15cb51c6ed5c15243e7a7fd653c
|
||||
DIGITS=c97e9b948bcd69bbc0e76b39fc82df963ae61665ee12099b6631ffe6
|
||||
DEF=52edc03c27124c2b83ebfd66f0669b6af40b44d4644c12d16b41f46b
|
||||
SEQ=7049c446c0fb287872536a7737f61f9ac7100f8e6b421d11011505fb
|
||||
;;
|
||||
esac
|
||||
|
||||
testing "TEST2" \
|
||||
"sha1sum" \
|
||||
"84983e441c3bd26ebaae4aa1f95129e5e54670f1 -\n" \
|
||||
testcmd "abc" "" "$ABC -\n" "" "abc"
|
||||
testcmd "longer str" "" "$ABCLONG -\n"\
|
||||
"" "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
|
||||
testing "a million nulls" \
|
||||
'dd if=/dev/zero bs=1000 count=1000 2>/dev/null|tr \\0 a|$CMDNAME' \
|
||||
"$MILNUL -\n" "" ""
|
||||
testing "digits" 'for i in `seq 80`; do echo -n 01234567 ; done | $CMDNAME' \
|
||||
"$DIGITS -\n" "" ""
|
||||
testing "seq 10000" "seq 10000 | $CMDNAME" "$SEQ -\n" "" ""
|
||||
|
||||
testing "TEST3" \
|
||||
'dd if=/dev/zero bs=1000 count=1000 2>/dev/null | tr \\0 a | sha1sum' \
|
||||
"34aa973cd4c4daa4f61eeb2bdbad27316534016f -\n" \
|
||||
"" ""
|
||||
|
||||
testing "TEST4" \
|
||||
'for i in `seq 1 10`; do echo -n 0123456701234567012345670123456701234567012345670123456701234567 ; done | sha1sum' \
|
||||
"dea356a2cddd90c7a7ecedc5ebb563934f460452 -\n" \
|
||||
"" ""
|
||||
|
||||
echo -n "abc" > file1
|
||||
echo -n "def" > file2
|
||||
testing "sha1sum" \
|
||||
"sha1sum" \
|
||||
"a9993e364706816aba3e25717850c26c9cd0d89d -\n" \
|
||||
"" "abc"
|
||||
|
||||
testing "-" \
|
||||
"sha1sum -" \
|
||||
"a9993e364706816aba3e25717850c26c9cd0d89d -\n" \
|
||||
"" "abc"
|
||||
|
||||
testing "file" \
|
||||
"sha1sum file1" \
|
||||
"a9993e364706816aba3e25717850c26c9cd0d89d file1\n" \
|
||||
"" ""
|
||||
|
||||
testing "file1 file2" \
|
||||
"sha1sum file1 file2" \
|
||||
"a9993e364706816aba3e25717850c26c9cd0d89d file1\n589c22335a381f122d129225f5c0ba3056ed5811 file2\n" \
|
||||
"" ""
|
||||
|
||||
testing "file1 file2 -" \
|
||||
"sha1sum file1 file2 -" \
|
||||
"a9993e364706816aba3e25717850c26c9cd0d89d file1\n589c22335a381f122d129225f5c0ba3056ed5811 file2\na9993e364706816aba3e25717850c26c9cd0d89d -\n" \
|
||||
"" "abc"
|
||||
|
||||
rm -f file1 file2
|
||||
|
||||
testcmd "file" "input" "$ABC input\n" "abc" ""
|
||||
testcmd "file1 file2" "input file2" "$ABC input\n$DEF file2\n" "abc" ""
|
||||
testcmd "file1 file2 -" "input file2 -" "$ABC input\n$DEF file2\n$ABC -\n" \
|
||||
"abc" "abc"
|
||||
rm -f file2
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
sha1sum.test
|
||||
@@ -0,0 +1 @@
|
||||
sha1sum.test
|
||||
@@ -0,0 +1 @@
|
||||
sha1sum.test
|
||||
@@ -0,0 +1 @@
|
||||
sha1sum.test
|
||||
@@ -0,0 +1 @@
|
||||
sha1sum.test
|
||||
@@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
|
||||
[ -f testing.sh ] && . testing.sh
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
# This is basically a test of lib/args.c argument parsing
|
||||
|
||||
out() { printf 'Ran skeleton\n%sOther globals should start zeroed: 0' "$@";}
|
||||
testcmd "baseline " "" "$(out '')\n" "" ""
|
||||
testcmd "unknown" "-z |& grep -o Unknown" "Unknown\n" "" ""
|
||||
testcmd "passthrough args" "bingeley bongeley beep" \
|
||||
"$(out 'optarg=bingeley\noptarg=bongeley\noptarg=beep\n')\n" "" ""
|
||||
testcmd "" "-a" "$(out 'flags=1\nSaw a\n')\n" "" ""
|
||||
testcmd "" "-b |& grep -o Missing" "Missing\n" "" ""
|
||||
testcmd "" "-b abc" "$(out 'flags=2\nb=abc\n')\n" "" ""
|
||||
testcmd "" "-c nondigit |& grep -o integer" "integer\n" "" ""
|
||||
testcmd "" "-c 123" "$(out 'flags=4\nc=123\n')\n" "" ""
|
||||
testcmd "" "-c 1m" "$(out 'flags=4\nc=1048576\n')\n" "" ""
|
||||
testcmd "" "-d one -d two -d 3,4" "$(out 'flags=8\nd=one\nd=two\nd=3,4\n')\n" \
|
||||
"" ""
|
||||
testcmd "" "-e" "$(out 'flags=10\ne was seen 1 times\n')\n" "" ""
|
||||
testcmd "" "-ee -e -ae" "$(out 'flags=11\nSaw a\ne was seen 4 times\n')\n" \
|
||||
"" ""
|
||||
testcmd "mixed" "123 -c 456 789" \
|
||||
"$(out 'flags=4\nc=456\noptarg=123\noptarg=789\n')\n" "" ""
|
||||
# ala date -I
|
||||
testcmd "':;' short attached" "-fabc" "$(out 'flags=20\nf=abc\n')\n" "" ""
|
||||
testcmd "':;' short detached" "-f abc" "$(out 'flags=20\noptarg=abc\n')\n" "" ""
|
||||
testcmd "':;' long" "--lo abc" "$(out 'flags=20\noptarg=abc\n')\n" "" ""
|
||||
testcmd "':;' long=x" "--long=abc" "$(out 'flags=20\nf=abc\n')\n" "" ""
|
||||
testcmd "':;' long=" "--long=" "$(out 'flags=20\nf=\n')\n" "" ""
|
||||
testcmd "':;' long detached" "--long abc" "$(out 'flags=20\noptarg=abc\n')\n" "" ""
|
||||
# ala kill -stop
|
||||
testcmd "': ' short attached" "-gabc 2>/dev/null || echo yup" "yup\n" "" ""
|
||||
testcmd "': ' short detached" "-g abc" "$(out 'flags=40\ng=abc\n')\n" "" ""
|
||||
testcmd "': ' long" "--glong abc" "$(out 'flags=40\ng=abc\n')\n" "" ""
|
||||
testcmd "': ' long=x" "--gl=abc" "$(out 'flags=40\ng=abc\n')\n" "" ""
|
||||
testcmd "': ' long=" "--gl=" "$(out 'flags=40\ng=\n')\n" "" ""
|
||||
# ala unshare -fim
|
||||
testcmd "':; ' short attached" "-habc" "$(out 'flags=83\nSaw a\nb=c\n')\n" "" ""
|
||||
testcmd "':; ' short detached" "-h abc" "$(out 'flags=80\noptarg=abc\n')\n" "" ""
|
||||
testcmd "':; ' long=x" "--h=abc" "$(out 'flags=80\nh=abc\n')\n" "" ""
|
||||
testcmd "':; ' long=" "--h=" "$(out 'flags=80\nh=\n')\n" "" ""
|
||||
testcmd "':; ' long detached" "--hlong abc" "$(out 'flags=80\noptarg=abc\n')\n" "" ""
|
||||
+31
-5
@@ -88,7 +88,7 @@ testing "key edge case with -t" "sort -n -k4 -t/" \
|
||||
/usr/lib/prebaseconfig.d/6
|
||||
"
|
||||
|
||||
testing "-x" "sort -x" "010\na0\n 0c0\n" "" "a0\n010\n 0c0\n"
|
||||
toyonly testing "-x" "sort -x" "010\na0\n 0c0\n" "" "a0\n010\n 0c0\n"
|
||||
|
||||
# Test that -f applies to key or fallback independently
|
||||
|
||||
@@ -97,14 +97,40 @@ testing "" "sort -k2,2" "a B C\na B a\nA b b\n" "" "a B a\nA b b\na B C\n"
|
||||
testing "" "sort -f -k2,2" "A b b\na B C\na B a\n" "" "a B a\nA b b\na B C\n"
|
||||
testing "" "sort -t, -k3n" "3,4,1,2\n4,1,2,3\n1,2,3,4\n2,3,4,1\n" "" \
|
||||
"1,2,3,4\n2,3,4,1\n4,1,2,3\n3,4,1,2\n"
|
||||
testing "-kx" "sort -k1,1x" "3\na\n0c\n" "" "0c\na\n3\n"
|
||||
toyonly testing "-kx" "sort -k1,1x" "3\na\n0c\n" "" "0c\na\n3\n"
|
||||
|
||||
testing "" "sort -V" "toy-2.37.tar.gz\ntoy-3.4.tar.gz\ntoy-3.12.tar.gz\ntoy-4.16-rc2.tar.gz\ntoy-4.16.tar.gz\n" "" \
|
||||
"toy-3.12.tar.gz\ntoy-2.37.tar.gz\ntoy-3.4.tar.gz\ntoy-4.16-rc2.tar.gz\ntoy-4.16.tar.gz"
|
||||
# This has irredeemable version skew on the host and no standard defining it.
|
||||
# testing "-V" "LANG=c sort -V" \
|
||||
# "toy-2.37.tar.gz\ntoy-3.4.tar.gz\ntoy-3.12.tar.gz\ntoy-4.16-rc2.tar.gz\ntoy-4.16.tar.gz\n" "" \
|
||||
# "toy-3.12.tar.gz\ntoy-2.37.tar.gz\ntoy-3.4.tar.gz\ntoy-4.16-rc2.tar.gz\ntoy-4.16.tar.gz"
|
||||
|
||||
optional SORT_FLOAT
|
||||
testcmd "-c" "-c 2>&1 | grep -o [0-9]*" "3\n" "" "a\nb\na\nc"
|
||||
testcmd "-uc" "-uc 2>&1 | grep -o [0-9]*" "3\n" "" "a\nb\nb\nc"
|
||||
testcmd "-C 1" "-C || echo yes" "yes\n" "" "one\ntwo\nthree"
|
||||
testcmd "-C 2" "-C && echo yes" "yes\n" "" "a\nb\nc\n"
|
||||
|
||||
toyonly testcmd 'negative -k' '-k-2,-2 -k-1r' 'a b z\nd e q\nx e a\nb m n\n' \
|
||||
'' 'a b z\nd e q\nb m n\nx e a\n'
|
||||
toyonly testcmd 'negative -k2' '-k-2' 'a b z\nx e a\nd e q\nb m n\n' \
|
||||
'' 'a b z\nd e q\nb m n\nx e a\n'
|
||||
|
||||
testcmd 'missing key becomes ""' '-k3r' 'm n o\ng h i\na b c\nd e\nj k\n' \
|
||||
'' 'a b c\nd e\ng h i\nj k\nm n o\n'
|
||||
toyonly testcmd 'negative straddle' '-k-1r' 'm n o\nj k\ng h i\nd e\na b c\n' \
|
||||
'' 'a b c\nd e\ng h i\nj k\nm n o\n'
|
||||
toyonly testcmd 'missing negative' '-k-3r' 'm n o\ng h i\na b c\nd e\nj k\n' \
|
||||
'' 'a b c\nd e\ng h i\nj k\nm n o\n'
|
||||
|
||||
optional TOYBOX_FLOAT
|
||||
|
||||
# not numbers < NaN < -infinity < numbers < +infinity
|
||||
testing "-g" "sort -g" \
|
||||
"bork\nNaN\n-inf\n0.4\n1.222\n01.37\n2.1\n+infinity\n" "" \
|
||||
"01.37\n1.222\n2.1\n0.4\nNaN\nbork\n-inf\n+infinity\n"
|
||||
|
||||
# -n without number sorts as leading zero, but fallback is whole string
|
||||
testcmd '-n without number sorts as leading zero' '-n' \
|
||||
'-1\n0A\n0D\nC\n1z\n3b\n' '' '1z\n0D\n3b\nC\n-1\n0A\n'
|
||||
|
||||
testcmd '-u implies -s' '-uk2,2n' 'zero 1\nthree 2\nfour 3\n' '' \
|
||||
'zero 1\none 1\nfour 3\ntwo 1\nthree 2\nalso 1'
|
||||
|
||||
+11
-7
@@ -5,21 +5,21 @@
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
testing "split" "seq 1 12345 | split && ls xa[a-z] | wc -l" "13\n" "" ""
|
||||
rm xa[a-z]
|
||||
rm -f xa[a-z]
|
||||
|
||||
testing "-" "seq 1 12345 | split - && ls xa[a-z] | wc -l" "13\n" "" ""
|
||||
rm xa[a-z]
|
||||
rm -f xa[a-z]
|
||||
|
||||
seq 1 12345 > file
|
||||
testing "file" "split file && ls xa[a-z] | wc -l" "13\n" "" ""
|
||||
rm xa[a-z]
|
||||
rm -f xa[a-z]
|
||||
|
||||
testing "-l" "split file -l 10k && wc -l xab" "2105 xab\n" "" ""
|
||||
rm xa[ab]
|
||||
toyonly testing "-l" "split file -l 10k && wc -l xab" "2105 xab\n" "" ""
|
||||
rm -f xa[ab]
|
||||
|
||||
testing "suffix exhaustion" \
|
||||
"split file -l 10 -a 1 walrus 2>/dev/null || ls walrus* | wc -l" "26\n" "" ""
|
||||
rm walrus*
|
||||
rm -f walrus*
|
||||
|
||||
testing "bytes" \
|
||||
"seq 1 20000 | split -b 100 -a 3 - whang && ls whang* | wc -l && wc -c whangbpw" "1089\n94 whangbpw\n" "" ""
|
||||
@@ -27,5 +27,9 @@ testing "bytes" \
|
||||
testing "reassembly" \
|
||||
'ls whang* | sort | xargs cat > reassembled && seq 1 20000 | diff -u reassembled - && echo yes' \
|
||||
"yes\n" "" ""
|
||||
rm -f file whang* reassembled
|
||||
|
||||
testing "-n" "split -n 3 input; md5sum xaa xab xac" \
|
||||
"494bb8fb423bfa1a5fd66dd0b98f866d xaa\n449acfdbc692780de30a2df05c5d32aa xab\n15ab4be57aebe9a1e445195d5094036c xac\n" \
|
||||
"$(seq 1 10000)" ""
|
||||
|
||||
rm file whang* reassembled
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
|
||||
[ -f testing.sh ] && . testing.sh
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
TZ=utc touch -at 200001010101.01 file
|
||||
testcmd "as echo" "-c hello file" "hello\n" "" ""
|
||||
testcmd "lone %" "-c % file" "%\n" "" ""
|
||||
testcmd "%% escapes" "-c '%% and %% then %%' file" "% and % then %\n" "" ""
|
||||
testcmd "%unknown = ?" "-c %q% file" "?%\n" "" ""
|
||||
|
||||
TZ=utc testcmd "%x" "-c %x file" "2000-01-01 01:01:01.000000000 +0000\n" "" ""
|
||||
TZ=utc testcmd "%X" "-c %X file" "946688461\n" "" ""
|
||||
|
||||
TZ=utc touch -mt 200002020202.02 file
|
||||
TZ=utc testcmd "%y" "-c %y file" "2000-02-02 02:02:02.000000000 +0000\n" "" ""
|
||||
TZ=utc testcmd "%Y" "-c %Y file" "949456922\n" "" ""
|
||||
@@ -73,3 +73,9 @@ testing "-f one two three" \
|
||||
'tail -f one two three & sleep .25 ; echo more >> three ; echo also >> one; sleep .25; kill $! >/dev/null' \
|
||||
"==> one <==\nuno\n\n==> two <==\ndos\n\n==> three <==\ntres\nmore\n\n==> one <==\nalso\n" "" ""
|
||||
rm one two three
|
||||
|
||||
testing "-F" "tail -s .1 -F walrus 2>/dev/null & sleep .2; echo hello > walrus;
|
||||
sleep .2; truncate -s 0 walrus; sleep .2; echo potato >> walrus; sleep .2;
|
||||
echo hello >> walrus; sleep .2; rm walrus; sleep .2; echo done > walrus;
|
||||
sleep .5; kill %1" "hello\npotato\nhello\ndone\n" "" ""
|
||||
rm -f walrus
|
||||
|
||||
+319
-123
@@ -4,150 +4,163 @@
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
# For reproducibility: UTC and umask 0002
|
||||
|
||||
OLDTZ="$TZ"
|
||||
# For reproducibility: TZ=UTC, umask 0002, override ownership and timestamp
|
||||
export TZ=utc
|
||||
OLDUMASK=$(umask)
|
||||
umask 0002
|
||||
TAR='tar c --owner root --group sys --mtime @1234567890'
|
||||
|
||||
# 255 bytes, longest VFS name
|
||||
LONG=0123456789abcdef0123456789abcdef
|
||||
LONG=$LONG$LONG$LONG$LONG$LONG$LONG$LONG$LONG
|
||||
LONG=${LONG:1:255}
|
||||
|
||||
# Reproducible tarballs: override ownership and timestamp.
|
||||
TAR='tar c --owner root --group root --mtime @1234567890'
|
||||
# We check both sha1sum (to ensure binary identical output) and list contents.
|
||||
|
||||
# Also amount of trailing NUL padding varies (1024 bytes is minimum,
|
||||
# gnu/dammit does more) so look at first N 512-byte frames when
|
||||
# analyzing header content.
|
||||
# Check hash of first N 512 byte frames to ensure result is binary identical.
|
||||
function SUM()
|
||||
{
|
||||
if [ -n "$TARHD" ]; then
|
||||
# (Android's shell doesn't support process substitution.)
|
||||
mkfifo xxd-pipe
|
||||
xxd <xxd-pipe & pid=$!
|
||||
tee xxd-pipe | head -c $(($1*512)) | sha1sum | sed "s/ .*//"
|
||||
rm xxd-pipe
|
||||
wait $pid
|
||||
else
|
||||
head -c $(($1*512)) | sha1sum | sed "s/ .*//"
|
||||
fi
|
||||
# Different tars add variable trailing NUL padding (1024 bytes is just
|
||||
# minimum) so look at first N 512-byte frames when analyzing header content.
|
||||
tee save.dat | head -c $(($1*512)) | sha1sum | sed "s/ .*//"
|
||||
}
|
||||
|
||||
# List tarball contents, converting variable tabs into one space
|
||||
function LST()
|
||||
{
|
||||
tar tv "$@" | sed 's/[ \t][ \t]*/ /g'
|
||||
}
|
||||
|
||||
# Check that stored empty file is binary identical and decodes as expected.
|
||||
touch file
|
||||
testing "create file" "$TAR file | SUM 3" \
|
||||
"fecaecba936e604bb115627a6ef4db7c7a3a8f81\n" "" ""
|
||||
|
||||
testing "store file" "$TAR file | SUM 3" \
|
||||
"2735f3a18d770dd0d7145d76108532f72bef9927\n" "" ""
|
||||
testing "pass file" "$TAR file | LST" \
|
||||
"-rw-rw-r-- root/root 0 2009-02-13 23:31 file\n" "" ""
|
||||
"-rw-rw-r-- root/sys 0 2009-02-13 23:31 file\n" "" ""
|
||||
|
||||
# The kernel has two hardwired meaningful UIDs: 0 (root) and 65534 (nobody).
|
||||
# (Technically changeable via /proc/sys/*/overflowuid but nobody ever does)
|
||||
skipnot id nobody >/dev/null
|
||||
testing "pass user" "tar -c --owner nobody --group root --mtime @0 file | LST" \
|
||||
"-rw-rw-r-- nobody/root 0 1970-01-01 00:00 file\n" "" ""
|
||||
# (We assume that if we have the nobody user, we also have the group, in the
|
||||
# absence of a good portable way to test for the existence of a named group.)
|
||||
skipnot id nobody >/dev/null
|
||||
testing "pass group" "tar c --owner root --group nobody --mtime @0 file | LST" \
|
||||
"-rw-rw-r-- root/nobody 0 1970-01-01 00:00 file\n" "" ""
|
||||
# Two files from -T list
|
||||
touch file1 file2
|
||||
testing "-T newline" "$TAR -T input | LST" \
|
||||
"-rw-rw-r-- root/sys 0 2009-02-13 23:31 file1\n-rw-rw-r-- root/sys 0 2009-02-13 23:31 file2\n" "file1\nfile2\n" ""
|
||||
testing "-T null" "$TAR --null -T input | LST" \
|
||||
"-rw-rw-r-- root/sys 0 2009-02-13 23:31 file1\n-rw-rw-r-- root/sys 0 2009-02-13 23:31 file2\n" "file1\0file2\0" ""
|
||||
|
||||
# User "root" is UID 0 and group "sys" is GID 3 (on Linux, BSD, and Mac),
|
||||
# inherited from Bell Labs Unix v7
|
||||
|
||||
# Note: testing both "tar c" and "tar -c" here.
|
||||
testing "specify UID, fetch GID" "tar -c --owner nobody:65534 --mtime @0 file | LST" \
|
||||
"-rw-rw-r-- nobody/$(stat -c %G file) 0 1970-01-01 00:00 file\n" "" ""
|
||||
testing "fetch UID, specify GID" "tar c --group nobody:65534 --mtime @0 file | LST" \
|
||||
"-rw-rw-r-- $(stat -c %U file)/nobody 0 1970-01-01 00:00 file\n" "" ""
|
||||
|
||||
# Large values switch from ascii numbers to a binary format.
|
||||
testing "huge values" "tar c --owner 9999999 --group 8888888 --mtime @0 file | SUM 3" \
|
||||
"396b07fd2f80eeb312462e3bfb7dc1325dc6bcfb\n" "" ""
|
||||
|
||||
testcmd "longname" "tf $FILES/tar/long_path.tar" \
|
||||
"$(printf 'long file name%86cTRAILING' ' ' | tr ' ' _)\n" "" ""
|
||||
|
||||
touch -t 198701231234.56 file
|
||||
testing "pass mtime" \
|
||||
"tar c --owner root --group root file | LST --full-time" \
|
||||
"-rw-rw-r-- root/root 0 1987-01-23 12:34:56 file\n" "" ""
|
||||
"tar c --owner root --group sys file | LST --full-time" \
|
||||
"-rw-rw-r-- root/sys 0 1987-01-23 12:34:56 file\n" "" ""
|
||||
|
||||
testing "adjust mode" \
|
||||
"tar c --owner root --group root --mode a+x file | LST --full-time" \
|
||||
"-rwxrwxr-x root/root 0 1987-01-23 12:34:56 file\n" "" ""
|
||||
"tar c --owner root --group sys --mode a+x file | LST --full-time" \
|
||||
"-rwxrwxr-x root/sys 0 1987-01-23 12:34:56 file\n" "" ""
|
||||
|
||||
mkdir dir
|
||||
testing "create dir" "$TAR dir | SUM 3" \
|
||||
"05739c423d7d4a7f12b3dbb7c94149acb2bb4f8d\n" "" ""
|
||||
|
||||
testing "store dir" "$TAR dir | SUM 3" \
|
||||
"85add1060cfe831ca0cdc945158efe6db485b81e\n" "" ""
|
||||
testing "pass dir" "$TAR dir | LST" \
|
||||
"drwxrwxr-x root/root 0 2009-02-13 23:31 dir/\n" "" ""
|
||||
"drwxrwxr-x root/sys 0 2009-02-13 23:31 dir/\n" "" ""
|
||||
|
||||
# note: does _not_ include dir entry in archive, just file
|
||||
touch dir/file
|
||||
testing "create file in dir" "$TAR dir/file | SUM 3" \
|
||||
"2d7b96c7025987215f5a41f10eaa84311160afdb\n" "" ""
|
||||
testing "store file in dir" "$TAR dir/file | SUM 3" \
|
||||
"d9e7fb3884430d29e7eed0dc04a2593dd260df14\n" "" ""
|
||||
|
||||
# Tests recursion without worrying about content order
|
||||
testing "create dir and dir/file" "$TAR dir | SUM 3" \
|
||||
"0bcc8005a3e07eb63c9b735267aecc5b774795d7\n" "" ""
|
||||
# Test recursion with one file so filesystem sort order can't change result
|
||||
testing "store dir and dir/file" "$TAR dir | SUM 3" \
|
||||
"a4e35f87e28c4565b60ba01dbe79e431914f8788\n" "" ""
|
||||
|
||||
testing "pass dir/file" "$TAR dir | LST" \
|
||||
"drwxrwxr-x root/root 0 2009-02-13 23:31 dir/\n-rw-rw-r-- root/root 0 2009-02-13 23:31 dir/file\n" "" ""
|
||||
"drwxrwxr-x root/sys 0 2009-02-13 23:31 dir/\n-rw-rw-r-- root/sys 0 2009-02-13 23:31 dir/file\n" "" ""
|
||||
|
||||
echo boing > dir/that
|
||||
testing "tar C" "$TAR -C dir that | SUM 3" \
|
||||
"f0deff71bf4858eb0c5f49d99d052f12f1831feb\n" "" ""
|
||||
"d469d4bc06def2d8808400ba30025ca295d05e4f\n" "" ""
|
||||
|
||||
# / and .. only stripped from name, not symlink target.
|
||||
ln -s ../name.././.. dir/link
|
||||
testing "create symlink" "$TAR dir/link | SUM 3" \
|
||||
"7324cafbd9aeec5036b6efc54d741f11528aeb10\n" "" ""
|
||||
|
||||
# Also two explicit targets
|
||||
ln dir/file dir/hardlink
|
||||
testing "create hardlink" "$TAR dir/file dir/hardlink | SUM 3" \
|
||||
"c5383651f8c03ec0fe15e8a9e28a4e8e5273990d\n" "" ""
|
||||
testing "store hardlink" "$TAR dir/file dir/hardlink | SUM 3" \
|
||||
"519de8abd1b32debd495a0fc1d96082184abbdcc\n" "" ""
|
||||
|
||||
ln dir/link dir/hlink
|
||||
testing "create hardlink to symlink" "$TAR dir/link dir/hlink | SUM 3" \
|
||||
"3bc16f8fb6fc8b05f691da8caf989a70ee99284a\n" "" ""
|
||||
|
||||
skipnot mkfifo dir/fifo
|
||||
skipnot mkfifo dir/fifo 2>/dev/null
|
||||
testing "create dir/fifo" "$TAR dir/fifo | SUM 3" \
|
||||
"bd1365db6e8ead4c813333f9666994c1899924d9\n" "" ""
|
||||
"cad477bd0fc5173d0a43f4774f514035456960e6\n" "" ""
|
||||
|
||||
# test L and K records
|
||||
|
||||
# 4+96=100 (biggest short name), 4+97=101 (shortest long name)
|
||||
touch dir/${LONG:1:96} dir/${LONG:1:97}
|
||||
testing "create long fname" "$TAR dir/${LONG:1:97} dir/${LONG:1:96} | SUM 3" \
|
||||
"99348686fe9c9bf80f5740f1fc0c6f32f2021e3d\n" "" ""
|
||||
"d70018505fa5df19ae73498cfc74d0281601e42e\n" "" ""
|
||||
|
||||
ln -s dir/${LONG:1:96} dir/lshort
|
||||
ln -s dir/${LONG:1:97} dir/llong
|
||||
testing "create long symlnk" "$TAR dir/lshort dir/llong | SUM 3" \
|
||||
"8a5d652dc85f252a2e3b3f47d1ecd699e98a5f4b\n" "" ""
|
||||
# MacOS X has different symlink permissions, skip these tests there
|
||||
[ "$(uname)" == Darwin ] && SKIP=999
|
||||
|
||||
ln -s $LONG dir/${LONG:5}
|
||||
testing "create long->long" "$TAR dir/${LONG:5} | SUM 7" \
|
||||
"543116b8e690a116a559ab5b673f9b6d6601c925\n" "" ""
|
||||
# absolute and relative link names, broken and not
|
||||
# / and .. only stripped from name, not symlink target.
|
||||
ln -s ../name.././.. dir/link
|
||||
testing "create symlink" "$TAR dir/link | SUM 3" \
|
||||
"f841bf9d757c655c5d37f30be62acb7ae24f433c\n" "" ""
|
||||
|
||||
ln -s file dir/linkok
|
||||
testing "create symlink" "$TAR dir/linkok | SUM 3" \
|
||||
"55652846506cf0a9d43b3ef03ccf9e98123befaf\n" "" ""
|
||||
ln dir/link dir/hlink
|
||||
testing "create hardlink to symlink" "$TAR dir/link dir/hlink | SUM 3" \
|
||||
"de571a6dbf09e1485e513ad13a178b1729267452\n" "" ""
|
||||
|
||||
ln -s dir/${LONG:1:96} dir/lshort
|
||||
ln -s dir/${LONG:1:97} dir/llong
|
||||
testing "create long symlink" "$TAR dir/lshort dir/llong | SUM 3" \
|
||||
"07eaf397634b5443dbf2d3ec38a4302150fcfe82\n" "" ""
|
||||
|
||||
skipnot ln -s $LONG dir/${LONG:5} 2>/dev/null
|
||||
testing "create long->long" "$TAR dir/${LONG:5} | SUM 7" \
|
||||
"b9e24f53e27496c5125445230d201b4a36ff7398\n" "" ""
|
||||
|
||||
# absolute and relative link names, broken and not
|
||||
ln -s file dir/linkok
|
||||
testing "create symlink" "$TAR dir/linkok | SUM 3" \
|
||||
"f5669cfd179ddcdd5ca9f8a1561a99e11e0a08b1\n" "" ""
|
||||
|
||||
SKIP=0 # End of tests that don't match MacOS symlink permissions
|
||||
|
||||
symlink_perms=lrwxrwxrwx
|
||||
[ "$(uname)" == "Darwin" ] && symlink_perms=lrwxrwxr-x
|
||||
|
||||
ln -s /dev/null dir/linknull
|
||||
testing "pass absolute symlink" "$TAR dir/linknull | LST" \
|
||||
"lrwxrwxrwx root/root 0 2009-02-13 23:31 dir/linknull -> /dev/null\n" "" ""
|
||||
"$symlink_perms root/sys 0 2009-02-13 23:31 dir/linknull -> /dev/null\n" "" ""
|
||||
|
||||
ln -s rel/broken dir/relbrok
|
||||
testing "pass broken symlink" "$TAR dir/relbrok | LST" \
|
||||
"lrwxrwxrwx root/root 0 2009-02-13 23:31 dir/relbrok -> rel/broken\n" "" ""
|
||||
"$symlink_perms root/sys 0 2009-02-13 23:31 dir/relbrok -> rel/broken\n" "" ""
|
||||
|
||||
ln -s /does/not/exist dir/linkabsbrok
|
||||
testing "pass broken absolute symlink" "$TAR dir/linkabsbrok | LST" \
|
||||
"lrwxrwxrwx root/root 0 2009-02-13 23:31 dir/linkabsbrok -> /does/not/exist\n" \
|
||||
"$symlink_perms root/sys 0 2009-02-13 23:31 dir/linkabsbrok -> /does/not/exist\n" \
|
||||
"" ""
|
||||
|
||||
# this expects devtmpfs values
|
||||
nulldev=1,3 # devtmpfs values
|
||||
[ "$(uname)" == "Darwin" ] && nulldev=3,2
|
||||
|
||||
testing "pass /dev/null" \
|
||||
"tar c --mtime @0 /dev/null 2>/dev/null | LST" \
|
||||
"crw-rw-rw- root/root 1,3 1970-01-01 00:00 dev/null\n" "" ""
|
||||
"crw-rw-rw- $(stat -c %U/%G /dev/null) $nulldev 1970-01-01 00:00 dev/null\n" \
|
||||
"" ""
|
||||
testing "--absolute-names" \
|
||||
"tar c --mtime @0 --absolute-names /dev/null 2>/dev/null | LST" \
|
||||
"crw-rw-rw- $(stat -c %U/%G /dev/null) $nulldev 1970-01-01 00:00 /dev/null\n"\
|
||||
"" ""
|
||||
|
||||
# compression types
|
||||
testing "autodetect gzip" 'LST -f "$FILES"/tar/tar.tgz' \
|
||||
@@ -158,22 +171,31 @@ testing "manually specify bz2" 'LST -jf "$FILES"/tar/tar.tbz2' \
|
||||
"drwxr-x--- enh/eng 0 2017-05-13 01:05 dir/\n-rw-r----- enh/eng 12 2017-05-13 01:05 dir/file\n" \
|
||||
"" ""
|
||||
|
||||
skipnot mknod dir/char c 12 34
|
||||
testing "character special" "tar --mtime @0 -cf test.tar dir/char && rm -f dir/char && tar xf test.tar && ls -l dir/char" \
|
||||
"crw-rw---- 1 root root 12, 34 1970-01-01 00:00 dir/char\n" "" ""
|
||||
# -I
|
||||
testing "-I gzip c" "$TAR -Igzip file | file - | grep -o 'gzip compressed'" \
|
||||
"gzip compressed\n" "" ""
|
||||
testing "-I gzip t" 'LST -Igzip -f "$FILES"/tar/tar.tgz' \
|
||||
"drwxr-x--- enh/eng 0 2017-05-13 01:05 dir/\n-rw-r----- enh/eng 12 2017-05-13 01:05 dir/file\n" \
|
||||
"" ""
|
||||
|
||||
skipnot mknod dir/block b 23 45
|
||||
testing "block special" "tar --mtime @0 -cf test.tar dir/block && rm -f dir/block && tar xf test.tar && ls -l dir/block" \
|
||||
"brw-rw---- 1 root root 23, 45 1970-01-01 00:00 dir/block\n" "" ""
|
||||
skipnot mknod -m 660 dir/char c 12 34 2>/dev/null && chgrp sys dir/char
|
||||
NOSPACE=1 testing "character special" "tar --mtime @0 -cf test.tar dir/char && rm -f dir/char && tar xf test.tar && ls -l --full-time dir/char" \
|
||||
"crw-rw---- 1 root sys 12, 34 1970-01-01 00:00:00.000000000 +0000 dir/char\n"\
|
||||
"" ""
|
||||
|
||||
skipnot chown nobody dir/file
|
||||
skipnot mknod -m 660 dir/block b 23 45 2>/dev/null && chgrp sys dir/block
|
||||
NOSPACE=1 testing "block special" "tar --mtime @0 -cf test.tar dir/block && rm -f dir/block && tar xf test.tar && ls -l --full-time dir/block" \
|
||||
"brw-rw---- 1 root sys 23, 45 1970-01-01 00:00:00.000000000 +0000 dir/block\n"\
|
||||
"" ""
|
||||
|
||||
skipnot chown nobody:nogroup dir/file 2>/dev/null
|
||||
testing "ownership" "$TAR dir/file | SUM 3" \
|
||||
"2d7b96c7025987215f5a41f10eaa84311160afdb\n" "" ""
|
||||
|
||||
mkdir -p dd/sub/blah &&
|
||||
tar cf test.tar dd/sub/blah &&
|
||||
rm -rf dd/sub &&
|
||||
ln -s ../.. dd/sub || SKIPNEXT=1
|
||||
skipnot ln -s ../.. dd/sub
|
||||
toyonly testing "symlink out of cwd" \
|
||||
"tar xf test.tar 2> /dev/null || echo yes ; [ ! -e dd/sub/blah ] && echo yes" \
|
||||
"yes\nyes\n" "" ""
|
||||
@@ -205,47 +227,224 @@ toyonly testing "cat tbz | extract dir/file (autodetect)" \
|
||||
"dir/\ndir/file\ndrwxr-x--- 1494637555 dd/dir\n-rw-r----- 1494637555 dd/dir/file\n" \
|
||||
"" ""
|
||||
|
||||
yes | (dd bs=$((1<<16)) count=1; dd bs=8192 seek=14 count=1; dd bs=4096 seek=64 count=5) 2>/dev/null > fweep
|
||||
testing "sparse without overflow" "$TAR --sparse fweep | SUM 3" \
|
||||
"e1560110293247934493626d564c8f03c357cec5\n" "" ""
|
||||
mkdir path && ln -s "$(which gzip)" "$(which tar)" path/ && [ -x path/gzip ] ||
|
||||
((++SKIP))
|
||||
toyonly testing "autodetect falls back to gzip -d when no zcat" \
|
||||
"PATH=path; tar tf $FILES/tar/tar.tgz" "dir/\ndir/file\n" "" ""
|
||||
rm -rf path
|
||||
|
||||
rm fweep
|
||||
for i in 1 3 5 7 9 14 27 36 128 256 300 304
|
||||
do
|
||||
dd if=/dev/zero of=fweep bs=65536 seek=$i count=1 2>/dev/null
|
||||
done
|
||||
# TODO: run sparse tests on tmpfs mount? (Request filesystem type?)
|
||||
# Only run sparse tests if filesystem can handle sparse files @4k granularity
|
||||
dd if=/dev/zero bs=4k count=1 seek=1 of=blah.img 2>/dev/null
|
||||
[ $(du blah.img | sed 's/[ \t].*//') -ne 4 ] && SKIP=999
|
||||
rm -f blah.img
|
||||
[ "$(uname)" == "Darwin" ] && SKIP=999
|
||||
|
||||
testing "sparse single overflow" "$TAR --sparse fweep | SUM 6" \
|
||||
"063fc6519ea2607763bc591cc90dd15ac2b43eb8\n" "" ""
|
||||
yes | head -n $((1<<18)) > bang
|
||||
{
|
||||
dd bs=$((1<<16)) count=1 status=none
|
||||
dd bs=8192 seek=14 count=1 status=none
|
||||
dd bs=4096 seek=64 count=5 status=none
|
||||
} < bang > fweep
|
||||
testing "sparse without overflow" "$TAR --sparse fweep | SUM 3" \
|
||||
"50dc56c3c7eed163f0f37c0cfc2562852a612ad0\n" "" ""
|
||||
rm bang fweep
|
||||
|
||||
rm fweep
|
||||
for i in $(seq 8 3 200)
|
||||
do
|
||||
dd if=/dev/zero of=fweep bs=65536 seek=$i count=1 2>/dev/null
|
||||
dd if=/dev/zero of=fweep2 bs=65536 seek=$i count=1 2>/dev/null
|
||||
done
|
||||
truncate -s 20m fweep2
|
||||
for i in 1 3 5 7 9 14 27 36 128 256 300 304
|
||||
do
|
||||
dd if=/dev/zero of=fweep bs=65536 seek=$i count=1 2>/dev/null
|
||||
done
|
||||
testing "sparse single overflow" "$TAR --sparse fweep | SUM 6" \
|
||||
"81d59c3a7470201f92d60e63a43318ddde893f6d\n" "" ""
|
||||
rm fweep
|
||||
|
||||
testing "sparse double overflow" "$TAR --sparse fweep | SUM 7" \
|
||||
"f1fe57f8313a9d682ec9013a80f3798910b6ff51\n" "" ""
|
||||
for i in $(seq 8 3 200)
|
||||
do
|
||||
dd if=/dev/zero of=fweep bs=65536 seek=$i count=1 2>/dev/null
|
||||
dd if=/dev/zero of=fweep2 bs=65536 seek=$i count=1 2>/dev/null
|
||||
done
|
||||
truncate -s 20m fweep2
|
||||
testing "sparse double overflow" "$TAR --sparse fweep | SUM 7" \
|
||||
"024aacd955e45f89bafedb3f37c8d39b4d556471\n" "" ""
|
||||
|
||||
tar c --sparse fweep > fweep.tar
|
||||
rm fweep
|
||||
testing "sparse extract" "tar xf fweep.tar && $TAR --sparse fweep | SUM 4" \
|
||||
"38dc57b8b95632a287db843c214b5c96d1cfe415\n" "" ""
|
||||
testing "sparse tvf" "tar tvf fweep.tar | grep -wq 13172736 && echo right size"\
|
||||
"right size\n" "" ""
|
||||
rm fweep fweep.tar
|
||||
tar c --sparse fweep > fweep.tar
|
||||
rm fweep
|
||||
testing "sparse extract" "tar xf fweep.tar && $TAR --sparse fweep | SUM 4" \
|
||||
"b949d3a3b4c6457c873f1ea9918fd9029c5ed4b3\n" "" ""
|
||||
testing "sparse tvf" \
|
||||
"tar tvf fweep.tar | grep -wq 13172736 && echo right size" "right size\n" \
|
||||
"" ""
|
||||
rm fweep fweep.tar
|
||||
|
||||
tar c --sparse fweep2 > fweep2.tar
|
||||
rm fweep2
|
||||
testing "sparse extract hole at end" \
|
||||
"tar xf fweep2.tar && $TAR --sparse fweep2 | SUM 4" \
|
||||
"791060574c569e5c059e2b90c1961a3575898f97\n" "" ""
|
||||
rm fweep2 fweep2.tar
|
||||
tar c --sparse fweep2 > fweep2.tar
|
||||
rm fweep2
|
||||
testing "sparse extract hole at end" \
|
||||
"tar xf fweep2.tar && $TAR --sparse fweep2 | SUM 4" \
|
||||
"807664bcad0e827793318ff742991d6f006b2127\n" "" ""
|
||||
rm fweep2 fweep2.tar
|
||||
|
||||
testcmd 'extract obsolete sparse format' \
|
||||
'xf "$FILES"/tar/oldsparse.tgz && sha1sum hello-sparse.c | head -c 12' \
|
||||
'9714dc7ac8c0' '' ''
|
||||
rm -f hello-sparse.c
|
||||
|
||||
SKIP=0 # End of sparse tests
|
||||
|
||||
mkdir -p links
|
||||
touch links/orig
|
||||
ln links/{orig,link1}
|
||||
ln links/{orig,link2}
|
||||
testcmd 'links' '-cf test.tar links' '' '' ''
|
||||
rm -rf links
|
||||
|
||||
mkdir links
|
||||
for i in {0..12}; do touch links/orig$i; ln links/{orig,link}$i; done
|
||||
testcmd 'links2' '-cf test.tar links' '' '' ''
|
||||
rm -rf links
|
||||
|
||||
install -m 000 -d folder/skip/oof &&
|
||||
testcmd 'exclude' '--exclude skip -cvf tar.tar folder && echo yes' \
|
||||
'folder/\nyes\n' '' ''
|
||||
rm -rf folder tar.tar
|
||||
|
||||
mkdir -p one/two; echo hello > one/two/three; tar czf test.tar one/two/three
|
||||
rm one/two/three; mkdir one/two/three
|
||||
testcmd 'replace dir with file' '-xf test.tar && cat one/two/three' \
|
||||
'hello\n' '' ''
|
||||
rm -rf one test.tar
|
||||
|
||||
mkdir ..dotsdir
|
||||
testing "create ..dotsdir" "$TAR ..dotsdir | SUM 3" \
|
||||
"62ff23c9b427020331992b9bc71f082099c1411f\n" "" ""
|
||||
|
||||
testing "pass ..dotsdir" "$TAR ..dotsdir | LST" \
|
||||
"drwxrwxr-x root/sys 0 2009-02-13 23:31 ..dotsdir/\n" "" ""
|
||||
rmdir ..dotsdir
|
||||
|
||||
mkdir -p one/two/three/four/five
|
||||
touch one/two/three/four/five/six
|
||||
testing "--strip" "$TAR one | tar t --strip=2 --show-transformed | grep six" \
|
||||
"three/four/five/six\n" "" ""
|
||||
|
||||
# toybox tar --xform depends on toybox sed
|
||||
[ -z "$TEST_HOST" ] && ! sed --tarxform '' </dev/null 2>/dev/null && SKIP=99
|
||||
|
||||
mkdir uno
|
||||
ln -s tres uno/dos
|
||||
touch uno/tres
|
||||
ln uno/tres uno/quatro
|
||||
LL() { LST --show-transformed-names $XX | sed 's/^.* 23:31 //'; }
|
||||
TT() { $TAR --no-recursion uno uno/{dos,tres,quatro} "$@" | LL; }
|
||||
testing 'xform S' \
|
||||
"TT --xform 's/uno/one/S;s/dos/two/S;s/tres/three/S;s/quatro/four/S'" \
|
||||
"one/\none/two -> tres\none/three\none/four link to one/three\n" "" ""
|
||||
|
||||
testing 'xform flags=rh starts with all disabled' \
|
||||
"TT --xform 's/uno/one/;flags=rh;s/dos/two/;s/tres/three/;s/quatro/four/'" \
|
||||
"one/\none/two -> tres\none/three\none/four link to one/three\n" "" ""
|
||||
|
||||
testing 'xform flags=rHhsS toggles' \
|
||||
"TT --xform 's/uno/one/;flags=rHhsS;s/dos/two/;s/tres/three/;s/quatro/four/'"\
|
||||
"one/\none/two -> tres\none/three\none/four link to one/three\n" "" ""
|
||||
|
||||
testing 'xform flags= is not a delta from previous' \
|
||||
"TT --xform 'flags=s;flags=rh;s/uno/one/;s/dos/two/;s/tres/three/;s/quatro/four/'" \
|
||||
"one/\none/two -> tres\none/three\none/four link to one/three\n" "" ""
|
||||
|
||||
testing 'xform H' \
|
||||
"TT --xform 'flags=rsH;s/uno/one/;s/dos/two/;s/tres/three/;s/quatro/four/'" \
|
||||
"one/\none/two -> three\none/three\none/four link to uno/tres\n" "" ""
|
||||
|
||||
testing 'xform R' \
|
||||
"TT --xform 'flags=rshR;s/uno/one/;s/dos/two/;s/tres/three/;s/quatro/four/'" \
|
||||
"uno/\nuno/dos -> three\nuno/tres\nuno/quatro link to one/three\n" "" ""
|
||||
|
||||
testing "xform path" "$TAR one --xform=s@three/four/@zero@ | tar t | grep six" \
|
||||
"one/two/zerofive/six\n" "" ""
|
||||
|
||||
testing "xform trailing slash special case" \
|
||||
"$TAR --xform 's#^.+/##x' one/two/three/four/five | tar t" 'five/\nsix\n' '' ''
|
||||
|
||||
# The quoting works because default IFS splits on whitepace not ;
|
||||
testing "xform extract all" \
|
||||
"XX='--xform s/uno/one/;s/dos/two/;s/tres/three/;s/quatro/four/' TT" \
|
||||
'one/\none/two -> three\none/three\none/four link to one/three\n' '' ''
|
||||
|
||||
testing 'xform extract S' \
|
||||
"XX='--xform s/uno/one/S;s/dos/two/S;s/tres/three/S;s/quatro/four/S' TT" \
|
||||
"one/\none/two -> tres\none/three\none/four link to one/three\n" "" ""
|
||||
|
||||
testing 'xform extract H' \
|
||||
"XX='--xform flags=rs;s/uno/one/;s/dos/two/;s/tres/three/;s/quatro/four/' TT"\
|
||||
"one/\none/two -> three\none/three\none/four link to uno/tres\n" "" ""
|
||||
|
||||
testing 'xform extract R' \
|
||||
"XX='--xform flags=sh;s/uno/one/;s/dos/two/;s/tres/three/;s/quatro/four/' TT"\
|
||||
"uno/\nuno/dos -> three\nuno/tres\nuno/quatro link to one/three\n" "" ""
|
||||
|
||||
rm -rf uno
|
||||
SKIP=0
|
||||
rm -rf one
|
||||
|
||||
testing '-P' "$TAR -P --no-recursion -C / /// .. | SUM 3" \
|
||||
"a3e94211582da121845d823374d8f41ead62d7bd\n" "" ""
|
||||
|
||||
testing 'without -P' "$TAR --no-recursion -C / /// .. 2>/dev/null | SUM 3" \
|
||||
"077d03243e247b074806904885e6da272fd5857a\n" "" ""
|
||||
|
||||
# Wildcards: --exclude, include (create/extract * cmdline/recursive)
|
||||
# --anchored, --wildcards, --wildcards-match-slash
|
||||
# --no-* versions of each. Span coverage, switching on/off...
|
||||
|
||||
#pattern a.c
|
||||
# abcd dabc a/c da/c
|
||||
# top/*
|
||||
|
||||
mkdir sub && cd sub && mkdir -p a da top/a top/da &&
|
||||
touch abcd dabc a/c da/c top/abcd top/dabc top/a/c top/da/c &&
|
||||
$TAR -f ../sub.tar abcd dabc a da top && cd .. || exit 1
|
||||
|
||||
# TODO I have not made wildcard state changes positional.
|
||||
|
||||
testing 'wildcards do not affect creation cmdline args' \
|
||||
'$TAR -C sub --wildcards a.cd abcd dabc a da top 2>/dev/null | cmp - sub.tar' \
|
||||
'' '' ''
|
||||
|
||||
testing 'creation --exclude --no-wildcards'\
|
||||
'$TAR -C sub --no-wildcards --exclude=d?bc abcd dabc | LL' \
|
||||
'abcd\ndabc\n' '' ''
|
||||
|
||||
|
||||
testing 'creation --wildcards --exclude'\
|
||||
'$TAR -C sub --wildcards --exclude=d?bc abcd dabc | LL' \
|
||||
'abcd\n' '' ''
|
||||
|
||||
# TODO: do we need to set DIRTREE_BREADTH at top level? Come up with test if so.
|
||||
mkdir sub2
|
||||
touch sub2/{ephebe,klatch,djelibeybi}
|
||||
testing 'tsort' '$TAR -c sub2 --sort=name | tar t' \
|
||||
'sub2/\nsub2/djelibeybi\nsub2/ephebe\nsub2/klatch\n' '' ''
|
||||
|
||||
touch file
|
||||
testing './file bug' 'tar c ./file > tar.tar && tar t ./file < tar.tar' \
|
||||
'./file\n' '' ''
|
||||
|
||||
skipnot [ $(id -u) -ne 0 ] # Root defaults to -p
|
||||
testing 'honor umask' \
|
||||
'umask 0022 && rm -rf dir && mkdir dir && tar xf $FILES/tar/dir.tar && stat -c%A dir dir/file' \
|
||||
'drwxr-xr-x\n-rwxr-xr-x\n' '' ''
|
||||
testing 'extract changes directory permissions' \
|
||||
'umask 0022 && rm -rf dir && mkdir dir && umask 0 && tar xf $FILES/tar/dir.tar && stat -c%A dir dir/file' \
|
||||
'drwxrwxrwx\n-rwxrwxrwx\n' '' ''
|
||||
testing '-p overrides umask' \
|
||||
'umask 0022 && rm -rf dir && mkdir dir && tar xpf $FILES/tar/dir.tar && stat -c%A dir dir/file' \
|
||||
'drwxrwxrwx\n-rwxrwxrwx\n' '' ''
|
||||
|
||||
if false
|
||||
then
|
||||
# Sequencing issues that leak implementation details out the interface
|
||||
testing "what order are --xform, --strip, and --exclude processed in?"
|
||||
testing "--xform vs ../ removal and adding / to dirs"
|
||||
|
||||
chmod 700 dir
|
||||
tar cpf tar.tgz dir/file
|
||||
@@ -282,7 +481,4 @@ tar cpf tar.tgz dir/file
|
||||
|
||||
fi
|
||||
|
||||
TZ="$OLDTZ"
|
||||
umask $OLDUMASK
|
||||
unset LONG TAR SUM OLDUMASK OLDTZ
|
||||
unset -f LST
|
||||
rm -f save.dat
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
[ -f testing.sh ] && . testing.sh
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
testing "" "tee" "one" "" "one"
|
||||
testing "" "tee -" "two\n" "" "two\n"
|
||||
testing "" "tee one > two && cmp one two && echo that" "that\n" "" "three"
|
||||
+89
-10
@@ -4,14 +4,23 @@
|
||||
|
||||
#testing "name" "command" "result" "infile" "stdin"
|
||||
|
||||
testcmd '0 args' '; echo $?' '1\n' '' ''
|
||||
testcmd '1 arg' '== ; echo $?' '0\n' '' ''
|
||||
testcmd "-- isn't parsed" "-- == -- && echo yes" "yes\n" "" ""
|
||||
|
||||
# Number and position of args is important
|
||||
testcmd 'no args is false' '; echo $?' '1\n' '' ''
|
||||
testcmd 'empty string is false' '""; echo $?' '1\n' '' ''
|
||||
testcmd '1 arg is true if not empty string' '== ; echo $?' '0\n' '' ''
|
||||
testcmd "1 arg isn't an operand" '-t 2>&1; echo $?' '0\n' '' ''
|
||||
testcmd '2 args' '-e == ; echo $?' '1\n' '' ''
|
||||
testcmd '3 args' '-e == -e ; echo $?' '0\n' '' ''
|
||||
|
||||
# parse as operator before parsing as parentheses around one argument
|
||||
testcmd '' '\( == \) ; echo $?' '1\n' '' ''
|
||||
testcmd '' '\( == \( ; echo $?' '0\n' '' ''
|
||||
testcmd '' '\( "" \) ; echo $?' '1\n' '' ''
|
||||
testcmd '' '\( x \) ; echo $?' '0\n' '' ''
|
||||
|
||||
# TODO: Should also have device and socket files
|
||||
# TODO: Should also have device and socket files, but requires root
|
||||
|
||||
mkdir d
|
||||
touch f
|
||||
@@ -30,22 +39,57 @@ type_test()
|
||||
testing "-b" "type_test -b" "" "" ""
|
||||
testing "-c" "type_test -c" "L" "" ""
|
||||
testing "-d" "type_test -d" "d" "" ""
|
||||
testing "-e" "type_test -e" "dfLsp" "" ""
|
||||
testing "-f" "type_test -f" "fs" "" ""
|
||||
testing "-h" "type_test -h" "L" "" ""
|
||||
testing "-L" "type_test -L" "L" "" ""
|
||||
testing "-s" "type_test -s" "ds" "" ""
|
||||
testing "-S" "type_test -S" "" "" ""
|
||||
testing "-p" "type_test -p" "p" "" ""
|
||||
testing "-e" "type_test -e" "dfLsp" "" ""
|
||||
testing "-S" "type_test -S" "" "" ""
|
||||
testing "-s" "type_test -s" "ds" "" ""
|
||||
testing "! -e" 'type_test ! -e' "n" "" ""
|
||||
|
||||
rm f L s p
|
||||
rmdir d
|
||||
|
||||
# TODO: Test rwx gu t
|
||||
# Alas can't expand to a redirect, so just test one success/fail
|
||||
testcmd "-t" '-t 0 < /dev/null; echo $?' '1\n' '' ''
|
||||
testcmd "-t2" '-t 0 < /dev/ptmx; echo $?' '0\n' '' ''
|
||||
|
||||
testcmd "" "'' || echo yes" "yes\n" "" ""
|
||||
testcmd "" "a && echo yes" "yes\n" "" ""
|
||||
# test -rwx each bit position and failure
|
||||
touch walrus
|
||||
MASK=111
|
||||
for i in x w r k g u; do
|
||||
[ $i == k ] && MASK=1000
|
||||
XX=no
|
||||
[ $(id -u) -eq 0 ] && [ $i == r -o $i == w ] && XX=yes # Root always has access
|
||||
# test everything off produces "off"
|
||||
chmod 000 walrus
|
||||
testcmd "-$i 0" "-$i walrus && echo yes || echo no" "$XX\n" "" ""
|
||||
chmod $((7777-$MASK)) walrus
|
||||
testcmd "-$i inverted" "-$i walrus && echo yes || echo no" "$XX\n" "" ""
|
||||
MASK=$(($MASK<<1))
|
||||
done
|
||||
unset MASK
|
||||
# Test setuid setgid sticky enabled
|
||||
for i in uu+s gg+s k+t; do
|
||||
chmod 000 walrus
|
||||
chmod ${i:1}+s walrus
|
||||
testcmd "-${i:0:1}" "-${i:0:1} walrus && echo yes" "yes\n" "" ""
|
||||
done
|
||||
# test each ugo+rwx bit position individually
|
||||
XX=no
|
||||
# Note: chmod 007 means everybody EXCEPT owner/group can access it. (Unix!)
|
||||
[ $(id -u) -eq 0 ] && XX=yes # Root always has access
|
||||
for i in 1 10 100; do for j in x w r; do
|
||||
chmod $i walrus
|
||||
|
||||
[ $i == 100 ] && XX=yes
|
||||
testcmd "-$j $i" "-$j walrus && echo yes || echo no" "$XX\n" "" ""
|
||||
i=$((i<<1))
|
||||
done; done
|
||||
rm -f walrus
|
||||
|
||||
# Not zero length, zero length, equals, not equals
|
||||
testcmd "-n" "-n '' || echo yes" "yes\n" "" ""
|
||||
testcmd "-n2" "-n a && echo yes" "yes\n" "" ""
|
||||
testcmd "-z" "-z '' && echo yes" "yes\n" "" ""
|
||||
@@ -69,12 +113,38 @@ testing "-ge" "arith_test -ge" "eg" "" ""
|
||||
testing "-lt" "arith_test -lt" "l" "" ""
|
||||
testing "-le" "arith_test -le" "le" "" ""
|
||||
|
||||
touch oldfile -d 1970-01-01
|
||||
touch newfile -d 2031-01-01T00:00:00.5
|
||||
ln -s newfile samefile
|
||||
|
||||
testcmd "-ef" "newfile -ef newfile && echo yes" "yes\n" "" ""
|
||||
testcmd "-ef link" "newfile -ef samefile && echo yes" "yes\n" "" ""
|
||||
testcmd "-ef2" "newfile -ef oldfile || echo no" "no\n" "" ""
|
||||
testcmd "-ot" "oldfile -ot newfile && echo yes" "yes\n" "" ""
|
||||
testcmd "-ot2" "oldfile -ot oldfile || echo no" "no\n" "" ""
|
||||
testcmd "-nt" "newfile -nt oldfile && echo yes" "yes\n" "" ""
|
||||
testcmd "-nt2" "oldfile -nt newfile || echo no" "no\n" "" ""
|
||||
testcmd "-nt2" "oldfile -nt newfile || echo no" "no\n" "" ""
|
||||
|
||||
testing "positional" "test -a == -a && echo yes" "yes\n" "" ""
|
||||
testing "! stacks" 'test \! \! \! \! 2 -eq 2 && echo yes' "yes\n" "" ""
|
||||
|
||||
# bash builtin "test" has these, but /usr/bin/test does not.
|
||||
testing "<1" 'test abc \< def && echo yes' "yes\n" "" ""
|
||||
testing "<2" 'test def \< abc || echo yes' "yes\n" "" ""
|
||||
testing ">1" 'test abc \> def || echo yes' "yes\n" "" ""
|
||||
testing ">2" 'test def \> abc && echo yes' "yes\n" "" ""
|
||||
|
||||
# bash only has this for [[ ]] but extra tests to _exclude_ silly...
|
||||
#toyonly testcmd "=~" "abc \'=~\' a.c && echo yes" "yes\n" "" ""
|
||||
#toyonly testcmd "=~ fail" "abc '=~' d.c; echo $?" '1\n' "" ""
|
||||
#toyonly testcmd "=~ zero length match" 'abc '=~' "1*" && echo yes' 'yes\n' '' ''
|
||||
|
||||
# test ! = -o a
|
||||
# test ! \( = -o a \)
|
||||
# test \( ! = \) -o a
|
||||
# test \( \)
|
||||
|
||||
#testing "" "[ -a -eq -a ] && echo yes" "yes\n" "" ""
|
||||
|
||||
# -e == -a
|
||||
# -e == -a -o -d != -o
|
||||
@@ -86,3 +156,12 @@ testing "-le" "arith_test -le" "le" "" ""
|
||||
# // x -o ( x -a x ) -a x -o x
|
||||
|
||||
# trailing ! and (
|
||||
# test \( ! ! ! -e \) \)
|
||||
# test \( \( "" \) -a "" \) -a ""
|
||||
# test !
|
||||
# test \( \) == \) \) -a x
|
||||
|
||||
# test \( "" \) -a \) == \)
|
||||
# test \( "x" \) -a \) == \)
|
||||
# test -e == -a
|
||||
# test \( "" \)
|
||||
|
||||
+12
-5
@@ -8,13 +8,13 @@
|
||||
testcmd "times out" '.1 sleep 100 ; echo $?' '124\n' '' ''
|
||||
testcmd "failure" '-s MONKEY .1 sleep 100 2>/dev/null ; echo $?' '125\n' '' ''
|
||||
testcmd "early failure" '2>/dev/null ; echo $?' '125\n' '' ''
|
||||
testcmd "can't execute" '.1 / 2>/dev/null ; echo $?' '126\n' '' ''
|
||||
testcmd "can't find" '.1 /does/not/exist 2>/dev/null ; echo $?' '127\n' '' ''
|
||||
testcmd "can't execute" '1 / 2>/dev/null ; echo $?' '126\n' '' ''
|
||||
testcmd "can't find" '1 /does/not/exist 2>/dev/null ; echo $?' '127\n' '' ''
|
||||
testcmd "custom signal" '-s 3 .1 sleep 100; echo $?' '124\n' '' ''
|
||||
testcmd "killed" '-s 9 .1 sleep 100; echo $?' '137\n' '' ''
|
||||
testcmd "TERM" '-s TERM .1 sleep 100; echo $?' '124\n' '' ''
|
||||
testcmd "exit 0" '.1 true ; echo $?' '0\n' '' ''
|
||||
testcmd "exit 1" '.1 false ; echo $?' '1\n' '' ''
|
||||
testcmd "exit 0" '1 true ; echo $?' '0\n' '' ''
|
||||
testcmd "exit 1" '1 false ; echo $?' '1\n' '' ''
|
||||
|
||||
testcmd "--preserve-status" '--preserve-status .1 sleep 100 ; echo $?' '143\n' '' ''
|
||||
testcmd "--preserve-status killed" '--preserve-status -s 9 .1 sleep 100 ; echo $?' '137\n' '' ''
|
||||
@@ -23,7 +23,7 @@ testcmd "--preserve-status killed" '--preserve-status -s 9 .1 sleep 100 ; echo $
|
||||
# signal and exits, we need to report that as a timeout (unless overridden).
|
||||
cat > loop.sh <<EOF
|
||||
#!/bin/sh
|
||||
trap "exit 3" SIGTERM
|
||||
trap "exit 3" TERM
|
||||
while true; do
|
||||
:
|
||||
done
|
||||
@@ -33,3 +33,10 @@ testcmd "trap-and-exit" '1 ./loop.sh ; echo $?' '124\n' '' ''
|
||||
testcmd "trap-and-exit --preserve-status" \
|
||||
'--preserve-status 1 ./loop.sh ; echo $?' '3\n' '' ''
|
||||
rm loop.sh
|
||||
|
||||
toyonly testcmd "-i" \
|
||||
"-i 1 sh -c 'for i in .25 .50 2; do sleep \$i; echo hello; done'" \
|
||||
"hello\nhello\n" "" ""
|
||||
testing '-v' "{ timeout -v .1 sleep 3;} 2>&1 | egrep -o 'TERM|sleep'" \
|
||||
'TERM\nsleep\n' '' ''
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user