12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331 |
- #!/bin/sh
- # Test cases for exists.sh
- # Copyright 2019-2020, 2022 orbea
- # All rights reserved.
- #
- # Redistribution and use of this script, with or without modification, is
- # permitted provided that the following conditions are met:
- #
- # 1. Redistributions of this script must retain the above copyright
- # notice, this list of conditions and the following disclaimer.
- #
- # THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
- # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
- # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- IFS='
- '
- \unset -f command printf unalias 2>/dev/null
- \unalias -a 2>/dev/null
- PATH="$(command -p getconf PATH):$PATH"
- LC_ALL=C; export LC_ALL
- set -euf
- COMMAND=
- FULLRUN=
- TESTSHELL=
- VAR=
- VERBOSE=
- WRAPPER=
- usage='test.sh - Test framework for exists.sh.
- Usage: test.sh [OPTIONS]
- -f, --full, Run all tests including very slow tests.
- -h, --help, Show this help message.
- -s, --shell, Path of the shell.
- -v, --verbose, Verbose logging.
- -w, --wrapper, Select tests to run.
- Supported tests:
- command, exists (default), which'
- chkscript () {
- case "$1" in
- command|exists|which ) WRAPPER="$1" ;;
- * ) die 1 "Unrecognized script '$1.sh', use -h for help." ;;
- esac
- }
- chkvar () {
- case "$1" in
- '' ) die 1 "Unrecognized option '$2', use -h for help." ;;
- WRAPPER ) chkscript "$2"; VAR= ;;
- * ) eval "$VAR=\"$2\""; VAR= ;;
- esac
- }
- die () {
- ret="$1"; shift
- case "$ret" in
- : ) printf %s\\n "$@" >&2; return 0 ;;
- 0 ) printf %s\\n "$@" ;;
- * ) printf %s\\n "$@" >&2 ;;
- esac
- exit "$ret"
- }
- for flag do
- case "$flag" in
- '' ) : ;;
- -- ) break ;;
- -f|--full ) FULLRUN=1 ;;
- -h|--help ) die 0 "$usage" ;;
- -s|--shell ) VAR=TESTSHELL ;;
- -v|--verbose ) VERBOSE=1; VAR= ;;
- -w|--wrapper ) VAR=WRAPPER ;;
- -* ) die 1 "Unrecognized option '$flag', use -h for help." ;;
- * ) chkvar "$VAR" "$flag" ;;
- esac
- done
- if [ ! -x "${TESTSHELL:=/bin/sh}" ] || [ ! -f "$TESTSHELL" ]; then
- die 1 "ERROR: Shell '$TESTSHELL' is not an executable file."
- fi
- checkfile () {
- [ -z "$skip" ] || return 0
- fail=0
- v=2
- # Some shells do not have a builtin printf and $PATH is unset
- printf_hack "${NEWPATH:=tests}"
- case "$NEWPATH" in
- __empty__ ) PATH= ;;
- __unset__ ) unset PATH ;;
- * ) PATH="$NEWPATH" ;;
- esac
- if [ -n "${1+x}" ]; then
- CMD="$("$TESTSHELL" -- "$rootdir"/$WRAPPER.sh "${@:-}")" || fail=1
- else
- CMD="$("$TESTSHELL" -- "$rootdir"/$WRAPPER.sh)" || fail=1
- fi
- export PATH="$ORIGPATH"
- NEWPATH=
- if [ $fail -lt 1 ] && [ "${CMD}" = "${test:-}" ]; then
- v=0
- elif [ $fail -gt 0 ] && [ "${CMD}" = "${test:-}" ]; then
- v=1
- fi
- log "output = $CMD" "match = ${test:-}" "input = ${@:-}" "result = $fail"
- set +f
- rm -rf -- tests/*
- set -f
- }
- makefile () {
- [ -z "$skip" ] || return 0
- while [ $# -gt 0 ]; do
- file="${1%:*}"
- perm="${1##*:}"
- shift
- [ "$file" = "${file%/*}" ] || mkdir -p "tests/${file%/*}"
- touch "tests/$file"
- chmod "$perm" "tests/$file"
- if [ -x "tests/$file" ] && [ -f "tests/$file" ]; then
- printf %s\\n "$rootdir/tests/$file"
- fi
- done
- }
- printf_hack () {
- case "$1" in
- __empty__|__unset__ ) p=':.' ;;
- * ) p=":$1" ;;
- esac
- while [ "$p" != "${p%:*}" ]; do
- dir="${p##*:}"
- if [ -d "${dir#:}" ]; then
- cp -- "$rootdir"/scripts/printf "${p##*:}/"
- chmod 0755 "${p##*:}/printf"
- break
- fi
- p="${p%:*}"
- done
- }
- result () {
- case "$1" in
- 0 ) result=PASS ;;
- 1 ) result=FAIL ;;
- esac
- if [ -n "$skip" ]; then
- printf %s\\n "SKIP - $2 || $result" >&2
- shift 2
- [ -z "${1+x}" ] || log "$@" >&2
- elif [ "$v" = "$1" ]; then
- printf %s\\n "PASS - $2 || $result"
- else
- printf %s\\n "FAIL - $2 || $result" >&2
- fi
- }
- settest () { test="$(printf %s\\n "$@")"; }
- quit () { err=$?; rm -f ./printf; rm -rf ./tests/; }
- case "$VERBOSE" in
- 1 ) log () { printf %s\\n "$@"; } ;;
- * ) log () { :; } ;;
- esac
- # Test if the command builtin accepts multiple arguments with -v
- if [ "$WRAPPER" = command ] && "$TESTSHELL" scripts/command-args-test.sh; then
- COMMAND=1
- # Test if the command builtin exits on the first missing executable with -v
- if "$TESTSHELL" scripts/command-args2-test.sh; then
- COMMAND=2
- fi
- fi
- # HACK for broken shells like posh and Slackware ash.
- if "$TESTSHELL" scripts/pwd-test.sh "$(pwd)" >/dev/null 2>&1; then
- retpwd () { pwd; }
- else
- retpwd () { pwd -P; }
- fi
- if [ "$0" != "${0%/*}" ]; then
- rootdir="$(cd -- "${0%/*}/" && retpwd)"
- cd -- "$rootdir"
- else
- rootdir="$(retpwd)"
- fi
- NEWPATH=
- ORIGPATH="$PATH"
- WRAPPER="${WRAPPER:-exists}"
- #########################
- #### Shell bug tests ####
- #########################
- skip=
- SKIP_EMPTY_PATH=
- SKIP_UNSET_PATH=
- # Test if an empty PATH variable is replaced
- # This happens with ksh93-20191228_5abcbd06 in Slackware
- if PATH= "$TESTSHELL" scripts/path-empty-test.sh; then
- SKIP_EMPTY_PATH=1
- fi
- # Test if an unset PATH variable is replaced
- # This happens with all shells other than yash
- unset PATH
- if "$TESTSHELL" scripts/path-empty-test.sh; then
- SKIP_UNSET_PATH=1
- fi
- export PATH="$ORIGPATH"
- ##########################
- #### Tests start here ####
- ##########################
- rm -rf tests
- trap 'quit; trap - EXIT; exit $err' EXIT INT
- mkdir tests
- # test an executable file - pass
- (
- test="$(makefile testfile:0755)"
- checkfile testfile
- result 0 'Executable File'
- )
- # test a non-executable file - fail
- (
- test="$(makefile testfile:0644)"
- checkfile testfile
- result 1 'Non-executable File'
- )
- # test $0 as an executable file - pass
- (
- test="$rootdir/$0"
- NEWPATH="$rootdir"
- checkfile "$0"
- result 0 "\$0 Executable File"
- )
- # test an executable file with a trailing forward slash - fail
- (
- test="$(makefile testfile:0755)"
- test=
- checkfile testfile/
- result 1 'Executable File with a Trailing Forward Slash'
- )
- # test an non-executable file with a trailing forward slash - fail
- (
- test="$(makefile testfile:0644)"
- checkfile testfile/
- result 1 'Non-executable File with a Trailing Forward Slash'
- )
- # test an executable file with a colon - pass
- (
- test="$(makefile test:file:0755)"
- checkfile test:file
- result 0 'Executable File with a Colon'
- )
- # test an executable file with a space - pass
- (
- test="$(makefile test\ file:0755)"
- checkfile test\ file
- result 0 'Executable File with a Space'
- )
- # test an executable file with a backslash - pass
- (
- test="$(makefile test\\file:0755)"
- checkfile test\\file
- result 0 'Executable File with a Backslash'
- )
- # test an executable file with a dollar sign - pass
- (
- test="$(makefile test\$file:0755)"
- checkfile test\$file
- result 0 'Executable File with a Dollar Sign'
- )
- # test an executable file with a grave - pass
- (
- test="$(makefile test\`file:0755)"
- checkfile test\`file
- result 0 'Executable File with a Grave'
- )
- # test an executable file with a wildcard sign - pass
- (
- test="$(makefile test\*file:0755)"
- checkfile test\*file
- result 0 'Executable File with a Wildcard Sign - 1'
- )
- (
- test="$(makefile test\*file:0755 test1file:0755)"
- settest "$rootdir"/tests/test\*file
- checkfile test\*file
- result 0 'Executable File with a Wildcard Sign - 2'
- )
- (
- test="$(makefile test\*file:0755 test1file:0755)"
- settest "$rootdir"/tests/test\*file
- cd tests/
- NEWPATH="$rootdir/tests"
- checkfile test\*file
- result 0 'Executable File with a Wildcard Sign - 3'
- )
- # test an executable file with a single quote - pass
- (
- test="$(makefile test\'file:0755)"
- checkfile test\'file
- result 0 'Executable File with a Single Quote'
- )
- # test an executable file with a double quote - pass
- (
- test="$(makefile test\"file:0755)"
- checkfile test\"file
- result 0 'Executable File with a Double Quote'
- )
- # test an executable file with mixed quotes - pass
- (
- test="$(makefile \"test\'file:0755)"
- checkfile \"test\'file
- result 0 'Executable File with Mixed Quotes'
- )
- # test an executable file as a dash - pass
- (
- test="$(makefile -:0755)"
- checkfile -- -
- result 0 'Executable File as a Dash - 1'
- )
- (
- test="$(makefile --:0755)"
- checkfile -- --
- result 0 'Executable File as a Dash - 2'
- )
- (
- test="$(makefile ---:0755)"
- checkfile -- ---
- result 0 'Executable File as a Dash - 3'
- )
- # test an executable file prefixed with a dash - pass
- (
- test="$(makefile -testfile:0755)"
- checkfile -- -testfile
- result 0 'Executable File Prefixed with a Dash - 1'
- )
- (
- test="$(makefile --testfile:0755)"
- checkfile -- --testfile
- result 0 'Executable File Prefixed with a Dash - 2'
- )
- (
- test="$(makefile ---testfile:0755)"
- checkfile -- ---testfile
- result 0 'Executable File Prefixed with a Dash - 3'
- )
- # test an executable file as a symlink - pass
- (
- test="$(makefile testfile1:0755)"
- settest "$rootdir"/tests/testfile2
- ln -s "$rootdir/tests/testfile1" "$rootdir/tests/testfile2"
- checkfile testfile2
- result 0 'Executable File as as Symlink'
- )
- # test and non-executable file as a symlink - fail
- (
- test="$(makefile testfile1:0644)"
- ln -s "$rootdir/tests/testfile1" "$rootdir/tests/testfile2"
- checkfile testfile2
- result 1 'Non-executable File as as Symlink'
- )
- # test an absolute file path - pass
- (
- test="$(makefile testfile:0755)"
- checkfile "$rootdir/tests/testfile"
- result 0 'Absolute File Path'
- )
- # test an absolute file path with a double forward slash - pass
- (
- test="$(makefile foobar//testfile:0755)"
- checkfile "$rootdir/tests/foobar//testfile"
- result 0 'Absolute File Path with a Double Forward Slash'
- )
- # test an absolute file path with a colon - pass
- (
- test="$(makefile foo:bar/testfile:0755)"
- checkfile "$rootdir/tests/foo:bar/testfile"
- result 0 'Absolute File Path with a Colon'
- )
- # test an absolute file path with spaces - pass
- (
- test="$(makefile foo\ bar/test\ file:0755)"
- checkfile "$rootdir/tests/foo bar/test file"
- result 0 'Absolute File Path with Spaces'
- )
- # test a relative file path - pass
- (
- test="$(makefile testfile:0755)"
- checkfile tests/testfile
- result 0 'Relative File Path - 1'
- )
- (
- test="$(makefile testfile:0755)"
- settest "$rootdir"/./tests/testfile
- checkfile ./tests/testfile
- result 0 'Relative File Path - 2'
- )
- # test a relative file path with a double forward slash - pass
- (
- test="$(makefile foobar//testfile:0755)"
- checkfile tests/foobar//testfile
- result 0 'Relative File Path with a Double Forward Slash - 1'
- )
- (
- test="$(makefile foobar//testfile:0755)"
- settest "$rootdir"/./tests/foobar//testfile
- checkfile ./tests/foobar//testfile
- result 0 'Relative File Path with a Double Forward Slash - 2'
- )
- # test a relative file path with a colon - pass
- (
- test="$(makefile foo:bar/testfile:0755)"
- checkfile tests/foo:bar/testfile
- result 0 'Relative File Path with a Colon - 1'
- )
- (
- test="$(makefile foo:bar/testfile:0755)"
- settest "$rootdir"/./tests/foo:bar/testfile
- checkfile ./tests/foo:bar/testfile
- result 0 'Relative File Path with a Colon - 2'
- )
- # test a relative file path with spaces - pass
- (
- test="$(makefile foo\ bar/test\ file:0755)"
- checkfile tests/foo\ bar/test\ file
- result 0 'Relative File Path with Spaces - 1'
- )
- (
- test="$(makefile foo\ bar/test\ file:0755)"
- settest "$rootdir"/./tests/foo\ bar/test\ file
- checkfile ./tests/foo\ bar/test\ file
- result 0 'Relative File Path with Spaces - 2'
- )
- # test first directory in $PATH - pass
- (
- test="$(makefile local/bin/testfile1:0755)"
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- checkfile testfile1
- result 0 "First Directory in \$PATH - 1"
- )
- (
- test="$(makefile local/bin/testfile1:0755 bin/testfile2:0755 \
- usr/bin/testfile3:0755)"
- settest "$rootdir"/tests/local/bin/testfile1
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- checkfile testfile1
- result 0 "First Directory in \$PATH - 2"
- )
- # test middle directory in $PATH - pass
- (
- test="$(makefile bin/testfile2:0755)"
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- checkfile testfile2
- result 0 "Middle Directory in \$PATH - 1"
- )
- (
- test="$(makefile local/bin/testfile1:0755 bin/testfile2:0755 \
- usr/bin/testfile3:0755)"
- settest "$rootdir"/tests/bin/testfile2
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- checkfile testfile2
- result 0 "Middle Directory in \$PATH - 2"
- )
- # test final directory in $PATH - pass
- (
- test="$(makefile usr/bin/testfile3:0755)"
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- checkfile testfile3
- result 0 "Final Directory in \$PATH - 1"
- )
- (
- test="$(makefile local/bin/testfile1:0755 bin/testfile2:0755 \
- usr/bin/testfile3:0755)"
- settest "$rootdir"/tests/usr/bin/testfile3
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- checkfile testfile3
- result 0 "Final Directory in \$PATH - 2"
- )
- # test matching directory and file names - pass
- (
- test="$(makefile tests:0755)"
- checkfile tests
- result 0 'Matching Directory and File Name - Executable'
- )
- # test matching directory and file names - fail
- (
- test="$(makefile tests:0644)"
- checkfile tests
- result 1 'Matching Directory and File Name - Non-Executable'
- )
- # test a directory - fail
- (
- mkdir tests/testdir
- checkfile testdir
- result 1 'Directory is not a File'
- )
- (
- mkdir tests/tests
- checkfile tests
- result 1 'Directory is not a File - Matching Directory and Path Name'
- )
- (
- mkdir tests/testdir1 tests/testdir2 tests/testdir3
- checkfile testdir1 testdir2 testdir3
- result 1 'Multiple Directories are not Files'
- )
- # test a missing file - fail
- (
- checkfile testfile
- result 1 'Missing File'
- )
- # test a wildcard with no files - fail
- (
- cd tests/
- set +f
- checkfile *
- set -f
- result 1 'Wildcard Sign with no Files'
- )
- # test the working directory with an executable file - pass
- (
- test="$(makefile testfile:0755)"
- NEWPATH=.
- cd tests
- settest "$rootdir"/tests/./testfile
- checkfile testfile
- result 0 'Working Directory with an Executable File'
- )
- # test the working directory with an executable file - fail
- (
- test="$(makefile testfile:0755)"
- NEWPATH=.
- test=
- checkfile testfile
- result 1 'Working Directory with an Executable File'
- )
- # test the working directory with a non-executable file - fail
- (
- test="$(makefile testfile:0644)"
- NEWPATH=.
- cd tests
- checkfile testfile
- result 1 'Working Directory with a Non-executable File'
- )
- # test the working directory with an executable absolute file path - pass
- (
- test="$(makefile testfile:0755)"
- NEWPATH=.
- cd tests
- checkfile "$rootdir"/tests/testfile
- result 0 'Working Directory with an Executable File Absolute Path - 1'
- )
- (
- test="$(makefile testfile:0755)"
- NEWPATH=.
- checkfile "$rootdir"/tests/testfile
- result 0 'Working Directory with an Executable File Absolute Path - 2'
- )
- # test the working directory with an executable relative file path - pass
- (
- test="$(makefile testfile:0755)"
- NEWPATH=.
- checkfile tests/testfile
- result 0 'Working Directory with an Executable File Relative Path - 1'
- )
- (
- test="$(makefile testfile:0755)"
- NEWPATH=.
- cd tests
- settest "$rootdir"/tests/./testfile
- checkfile ./testfile
- result 0 'Working Directory with an Executable File Relative Path - 2'
- )
- # test the working directory with a non-executable absolute file path - fail
- (
- test="$(makefile testfile:0644)"
- NEWPATH=.
- checkfile "$rootdir"/testfile
- result 1 'Working Directory with a Non-executable File Absolute Path - 1'
- )
- (
- test="$(makefile testfile:0644)"
- NEWPATH=.
- cd tests
- checkfile "$rootdir"/testfile
- result 1 'Working Directory with a Non-executable File Absolute Path - 2'
- )
- # test the working directory with a non-executable relative file path - fail
- (
- test="$(makefile testfile:0644)"
- NEWPATH=.
- checkfile tests/testfile
- result 1 'Working Directory with a Non-executable File Relative Path - 1'
- )
- (
- test="$(makefile testfile:0644)"
- NEWPATH=.
- cd tests
- checkfile ./testfile
- result 1 'Working Directory with a Non-executable File Relative Path - 2'
- )
- # test an empty $PATH with an executable file - pass
- (
- [ -z "${SKIP_EMPTY_PATH}" ] || skip=1
- test="$(makefile testfile:0755)"
- NEWPATH=__empty__
- cd tests
- checkfile testfile
- result 0 "Empty \$PATH with an Executable File" \
- "With '$TESTSHELL' an empty PATH is helpfully replaced."
- )
- # test an empty $PATH with an executable file - fail
- (
- [ -z "${SKIP_EMPTY_PATH}" ] || skip=1
- test="$(makefile testfile:0755)"
- NEWPATH=__empty__
- test=
- checkfile testfile
- result 1 "Empty \$PATH with an Executable File" \
- "With '$TESTSHELL' an empty PATH is helpfully replaced."
- )
- # test an empty $PATH with a non-executable file - fail
- (
- [ -z "${SKIP_EMPTY_PATH}" ] || skip=1
- test="$(makefile testfile:0644)"
- NEWPATH=__empty__
- cd tests
- checkfile testfile
- result 1 "Empty \$PATH with a Non-executable File - 1" \
- "With '$TESTSHELL' an empty PATH is helpfully replaced."
- )
- (
- [ -z "${SKIP_EMPTY_PATH}" ] || skip=1
- test="$(makefile testfile:0644)"
- NEWPATH=__empty__
- checkfile testfile
- result 1 "Empty \$PATH with a Non-executable File - 2" \
- "With '$TESTSHELL' an empty PATH is helpfully replaced."
- )
- # test an empty $PATH with an executable absolute file path - pass
- (
- [ -z "${SKIP_EMPTY_PATH}" ] || skip=1
- test="$(makefile testfile:0755)"
- NEWPATH=__empty__
- checkfile "$rootdir"/tests/testfile
- result 0 "Empty \$PATH with an Executable File Absolute Path" \
- "With '$TESTSHELL' an empty PATH is helpfully replaced."
- )
- # test an empty $PATH with an executable relative file path - pass
- (
- [ -z "${SKIP_EMPTY_PATH}" ] || skip=1
- test="$(makefile testfile:0755)"
- NEWPATH=__empty__
- checkfile tests/testfile
- result 0 "Empty \$PATH with an Executable File Relative Path - 1" \
- "With '$TESTSHELL' an empty PATH is helpfully replaced."
- )
- (
- [ -z "${SKIP_EMPTY_PATH}" ] || skip=1
- test="$(makefile testfile:0755)"
- NEWPATH=__empty__
- cd tests
- settest "$rootdir"/tests/./testfile
- checkfile ./testfile
- result 0 "Empty \$PATH with an Executable File Relative Path - 2" \
- "With '$TESTSHELL' an empty PATH is helpfully replaced."
- )
- # test an empty $PATH with a non-executable absolute file path - fail
- (
- [ -z "${SKIP_EMPTY_PATH}" ] || skip=1
- test="$(makefile testfile:0644)"
- NEWPATH=__empty__
- checkfile "$rootdir"/testfile
- result 1 "Empty \$PATH with a Non-executable File Absolute Path" \
- "With '$TESTSHELL' an empty PATH is helpfully replaced."
- )
- # test an empty $PATH with a non-executable relative file path - fail
- (
- [ -z "${SKIP_EMPTY_PATH}" ] || skip=1
- test="$(makefile testfile:0644)"
- NEWPATH=__empty__
- checkfile tests/testfile
- result 1 "Empty \$PATH with a Non-executable File Relative Path - 1" \
- "With '$TESTSHELL' an empty PATH is helpfully replaced."
- )
- (
- [ -z "${SKIP_EMPTY_PATH}" ] || skip=1
- test="$(makefile testfile:0644)"
- NEWPATH=__empty__
- cd tests
- checkfile ./testfile
- result 1 "Empty \$PATH with a Non-executable File Relative Path - 2" \
- "With '$TESTSHELL' an empty PATH is helpfully replaced."
- )
- # test an unset $PATH with an executable file - fail
- (
- [ -z "${SKIP_UNSET_PATH}" ] || skip=1
- test="$(makefile testfile:0755)"
- NEWPATH=__unset__
- cd tests
- test=
- checkfile testfile
- result 1 "Unset \$PATH with an Executable File - 1" \
- "With '$TESTSHELL' an unset PATH is helpfully replaced."
- )
- # test an unset $PATH with an executable file - fail
- (
- [ -z "${SKIP_UNSET_PATH}" ] || skip=1
- test="$(makefile testfile:0755)"
- NEWPATH=__unset__
- test=
- checkfile testfile
- result 1 "Unset \$PATH with an Executable File - 2" \
- "With '$TESTSHELL' an unset PATH is helpfully replaced."
- )
- # test an unset $PATH with a non-executable file - fail
- (
- [ -z "${SKIP_UNSET_PATH}" ] || skip=1
- test="$(makefile testfile:0644)"
- NEWPATH=__unset__
- cd tests
- checkfile testfile
- result 1 "Unset \$PATH with a Non-executable File - 1" \
- "With '$TESTSHELL' an unset PATH is helpfully replaced."
- )
- (
- [ -z "${SKIP_UNSET_PATH}" ] || skip=1
- test="$(makefile testfile:0644)"
- NEWPATH=__unset__
- checkfile testfile
- result 1 "Unset \$PATH with a Non-executable File - 2" \
- "With '$TESTSHELL' an unset PATH is helpfully replaced."
- )
- # test an unset $PATH with an executable absolute file path - pass
- (
- [ -z "${SKIP_UNSET_PATH}" ] || skip=1
- test="$(makefile testfile:0755)"
- NEWPATH=__unset__
- checkfile "$rootdir"/tests/testfile
- result 0 "Unset \$PATH with an Executable File Absolute Path" \
- "With '$TESTSHELL' an unset PATH is helpfully replaced."
- )
- # test an unset $PATH with an executable relative file path - pass
- (
- [ -z "${SKIP_UNSET_PATH}" ] || skip=1
- test="$(makefile testfile:0755)"
- NEWPATH=__unset__
- checkfile tests/testfile
- result 0 "Unset \$PATH with an Executable File Relative Path - 1" \
- "With '$TESTSHELL' an unset PATH is helpfully replaced."
- )
- (
- [ -z "${SKIP_UNSET_PATH}" ] || skip=1
- test="$(makefile testfile:0755)"
- NEWPATH=__unset__
- cd tests
- settest "$rootdir"/tests/./testfile
- checkfile ./testfile
- result 0 "Unset \$PATH with an Executable File Relative Path - 2" \
- "With '$TESTSHELL' an unset PATH is helpfully replaced."
- )
- # test an unset $PATH with a non-executable absolute file path - fail
- (
- [ -z "${SKIP_UNSET_PATH}" ] || skip=1
- test="$(makefile testfile:0644)"
- NEWPATH=__unset__
- checkfile "$rootdir"/testfile
- result 1 "Unset \$PATH with a Non-executable File Absolute Path" \
- "With '$TESTSHELL' an unset PATH is helpfully replaced."
- )
- # test an unset $PATH with a non-executable relative file path - fail
- (
- [ -z "${SKIP_UNSET_PATH}" ] || skip=1
- test="$(makefile testfile:0644)"
- NEWPATH=__unset__
- checkfile tests/testfile
- result 1 "Unset \$PATH with a Non-executable File Relative Path - 1" \
- "With '$TESTSHELL' an unset PATH is helpfully replaced."
- )
- (
- [ -z "${SKIP_UNSET_PATH}" ] || skip=1
- test="$(makefile testfile:0644)"
- NEWPATH=__unset__
- cd tests
- checkfile ./testfile
- result 1 "Unset \$PATH with a Non-executable File Relative Path - 2" \
- "With '$TESTSHELL' an unset PATH is helpfully replaced."
- )
- # test an empty argument - fail
- (
- checkfile ''
- result 1 'Empty Argument'
- )
- # test an unset argument - pass
- (
- checkfile
- result 0 'Unset Argument'
- )
- if [ "$WRAPPER" = exists ] || [ "$WRAPPER" = which ] || [ -n "$COMMAND" ]; then
- # test multiple executable files - pass
- (
- test="$(makefile testfile1:0755 testfile2:0755)"
- checkfile testfile1 testfile2
- result 0 'Multiple Executable Files - 1'
- )
- (
- test="$(makefile testfile1:0755 testfile2:0755 testfile3:0755)"
- checkfile testfile1 testfile2 testfile3
- result 0 'Multiple Executable Files - 2'
- )
- # test multiple non-executable files - pass
- (
- test="$(makefile testfile1:0644 testfile2:0644)"
- checkfile testfile1 testfile2
- result 1 'Multiple Non-executable Files - 1'
- )
- (
- test="$(makefile testfile1:0644 testfile2:0644 testfile3:0644)"
- checkfile testfile1 testfile2 testfile3
- result 1 'Multiple Non-executable Files - 2'
- )
- # test multiple missing files - fail
- (
- checkfile testfile1 testfile2
- result 1 'Multiple Missing Files - 1'
- )
- (
- checkfile testfile1 testfile2 testfile3
- result 1 'Multiple Missing Files - 2'
- )
- # test multiple executable and non-executable files - fail
- (
- test="$(makefile testfile1:0755 testfile2:0644)"
- settest "$rootdir"/tests/testfile1
- checkfile testfile1 testfile2
- result 1 'Multiple Executable and Non-Executable Files - 1'
- )
- (
- test="$(makefile testfile1:0755 testfile2:0755 testfile3:0644)"
- settest "$rootdir"/tests/testfile1 "$rootdir"/tests/testfile2
- checkfile testfile1 testfile2 testfile3
- result 1 'Multiple Executable and Non-Executable Files - 2'
- )
- # test an absolute file path with a wildcard - pass
- (
- test="$(makefile testfile1:0755 testfile2:0755 testfile3:0755)"
- settest "$rootdir/tests/testfile1" "$rootdir/tests/testfile2" \
- "$rootdir/tests/testfile3"
- set +f
- checkfile "$rootdir"/tests/test*
- set -f
- result 0 'Absolute File Path with a Wildcard'
- )
- # test multiple files and directories - fail
- (
- test="$(makefile testfile1:0755 testfile2:0755)"
- mkdir tests/testdir1 tests/testdir2
- settest "$rootdir"/tests/testfile1 "$rootdir"/tests/testfile2
- checkfile testfile1 testfile2 testdir1 testdir2
- result 1 'Multiple Executable Files and Directories'
- )
- # test multiple present and missing files - fail
- (
- test="$(makefile testfile1:0755)"
- checkfile testfile1 testfile2
- result 1 'Multiple Present and Missing Files - 1'
- )
- (
- test="$(makefile testfile1:0755 testfile2:0755)"
- checkfile testfile1 testfile2 testfile3
- result 1 'Multiple Present and Missing Files - 2'
- )
- (
- test="$(makefile testfile1:0755 testfile2:0755 testfile3:0755)"
- checkfile testfile1 testfile2 testfile3 testifile4
- result 1 'Multiple Present and Missing Files - 3'
- )
- if [ "$WRAPPER" != command ] || [ "$COMMAND" = 2 ]; then
- (
- test="$(makefile testfile2:0755 testfile3:0755)"
- checkfile testfile1 testfile2 testfile3
- result 1 'Multiple Present and Missing Files - 4'
- )
- (
- test="$(makefile testfile1:0755 testfile3:0755)"
- checkfile testfile1 testfile2 testfile3
- result 1 'Multiple Present and Missing Files - 5'
- )
- # test multiple files and directories - fail
- (
- test="$(makefile testfile1:0644 testfile2:0755)"
- mkdir tests/testdir1 tests/testdir2
- settest "$rootdir"/tests/testfile2
- checkfile testfile1 testfile2 testdir1 testdir2
- result 1 'Multiple Executable Files, Non-executable Files and Directories'
- )
- # test multiple files in the $PATH with a wildcard - fail
- (
- test="$(makefile testfile1:0644 testfile2:0644 bin/testfile1:0755 \
- usr/bin/testfile2:0755)"
- settest "$rootdir"/tests/bin/testfile1 "$rootdir"/tests/usr/bin/testfile2
- cd tests/
- NEWPATH=bin:usr/bin
- set +f
- checkfile *
- set -f
- result 1 "Multiple Executable Files in the \$PATH with a Wildcard"
- )
- # test multiple files with dashes - fail
- (
- test="$(makefile --:0755 -testfile:0644 -:0755 --testfile:0755 ---:0644 \
- ---testfile:0755)"
- settest "$rootdir"/tests/-- "$rootdir"/tests/- "$rootdir"/tests/--testfile \
- "$rootdir"/tests/---testfile
- checkfile -- -- -testfile - --testfile --- ---testfile
- result 1 'Multiple files with dashes - 1'
- )
- (
- test="$(makefile --:0644 -testfile:0755 -:0644 --testfile:0644 ---:0755 \
- ---testfile:0644)"
- settest "$rootdir"/tests/-testfile "$rootdir"/tests/---
- checkfile -- -- -testfile - --testfile --- ---testfile
- result 1 'Multiple files with dashes - 2'
- )
- (
- test="$(makefile -testfile:0755 ---:0644 --testfile:0644 --:0755 \
- ---testfile:0755 -:0755)"
- settest "$rootdir"/tests/-testfile "$rootdir"/tests/-- \
- "$rootdir"/tests/---testfile "$rootdir"/tests/-
- checkfile -- -testfile --- --testfile -- ---testfile -
- result 1 'Multiple files with dashes - 3'
- )
- fi
- # test 100 executable files - pass
- (
- files1=
- files2=
- for i in $(seq 100); do
- files1="${files1} $i"
- files2="${files2} $i:0755"
- done
- eval "set -- $files2"
- test="$(makefile "$@")"
- eval "set -- $files1"
- checkfile "$@"
- result 0 '100 Executable Files'
- )
- # Very slow tests
- if [ "$FULLRUN" = 1 ]; then
- # test 1000 executable files - pass
- (
- files1=
- files2=
- for i in $(seq 1000); do
- files1="${files1} $i"
- files2="${files2} $i:0755"
- done
- eval "set -- $files2"
- test="$(makefile "$@")"
- eval "set -- $files1"
- checkfile "$@"
- result 0 '1000 Executable Files'
- )
- # test 10000 executable files - pass
- (
- files1=
- files2=
- for i in $(seq 10000); do
- files1="${files1} $i"
- files2="${files2} $i:0755"
- done
- eval "set -- $files2"
- test="$(makefile "$@")"
- eval "set -- $files1"
- checkfile "$@"
- result 0 '10000 Executable Files'
- )
- fi
- fi
- if [ "$WRAPPER" = exists ] || [ "$WRAPPER" = which ]; then
- # test --all - pass
- (
- test="$(makefile bin/testfile:0755 usr/bin/testfile:0755)"
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- checkfile --all testfile
- result 0 'All matches with --all and executable files - 1'
- )
- (
- test="$(makefile bin/testfile:0755 usr/bin/testfile:0755)"
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- checkfile -a testfile
- result 0 'All matches with --all and executable files - 2'
- )
- (
- test="$(makefile local/bin/testfile:0755 bin/testfile:0644 \
- usr/bin/testfile:0755)"
- settest "$rootdir"/tests/local/bin/testfile \
- "$rootdir"/tests/usr/bin/testfile
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- checkfile --all testfile
- result 0 'All matches with --all and executable files - 3'
- )
- (
- test="$(makefile local/bin/testfile:0755 bin/testfile:0644 \
- usr/bin/testfile:0755)"
- settest "$rootdir"/tests/local/bin/testfile \
- "$rootdir"/tests/usr/bin/testfile
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- checkfile -a testfile
- result 0 'All matches with --all and executable files - 4'
- )
- # test --all with non-exuectubable files - fail
- (
- test="$(makefile bin/testfile:0644 usr/bin/testfile:0644)"
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- checkfile --all testfile
- result 1 'All matches with --all and non-executable files - 1'
- )
- (
- test="$(makefile bin/testfile:0644 usr/bin/testfile:0644)"
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- checkfile -a testfile
- result 1 'All matches with --all and non-executable files - 2'
- )
- # test executable files titled --all - pass
- (
- test="$(makefile --all:0755)"
- checkfile -- --all
- result 0 'Executable file titled --all - 1'
- )
- (
- test="$(makefile -a:0755)"
- checkfile -- -a
- result 0 'Executable file titled --all - 2'
- )
- (
- test="$(makefile bin/--all:0755 usr/bin/--all:0755)"
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- checkfile --all -- --all
- result 0 'Executable file titled --all - 3'
- )
- (
- test="$(makefile bin/-a:0755 usr/bin/-a:0755)"
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- checkfile -a -- -a
- result 0 'Executable file titled --all - 4'
- )
- (
- test="$(makefile bin/--all:0755 usr/bin/--all:0755)"
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- checkfile -a -- --all
- result 0 'Executable file titled --all - 5'
- )
- (
- test="$(makefile bin/-a:0755 usr/bin/-a:0755)"
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- checkfile --all -- -a
- result 0 'Executable file titled --all - 6'
- )
- # test non-executable files titled --all - fail
- (
- test="$(makefile --all:0644)"
- checkfile -- --all
- result 1 'Non-executable file titled --all - 1'
- )
- (
- test="$(makefile -a:0644)"
- checkfile -- -a
- result 1 'Non-executable file titled --all - 2'
- )
- (
- test="$(makefile bin/--all:0644 usr/bin/--all:0644)"
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- checkfile --all -- --all
- result 1 'Non-executable file titled --all - 3'
- )
- (
- test="$(makefile bin/-a:0644 usr/bin/-a:0644)"
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- checkfile -a -- -a
- result 1 'Non-executable file titled --all - 4'
- )
- (
- test="$(makefile bin/--all:0644 usr/bin/--all:0644)"
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- checkfile -a -- --all
- result 1 'Non-executable file titled --all - 5'
- )
- (
- test="$(makefile bin/-a:0644 usr/bin/-a:0644)"
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- checkfile --all -- -a
- result 1 'Non-executable file titled --all - 6'
- )
- # Invalid command-line with --all - pass
- (
- test="$(makefile --all:0755)"
- test=
- checkfile --all
- result 0 'Invalid command-line with --all - 1'
- )
- (
- test="$(makefile -a:0755)"
- test=
- checkfile -a
- result 0 'Invalid command-line with --all - 2'
- )
- (
- test="$(makefile bin/--all:0755 usr/bin/--all:0755)"
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- test=
- checkfile --all --all
- result 0 'Invalid command-line with --all - 3'
- )
- (
- test="$(makefile bin/-a:0755 usr/bin/-a:0755)"
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- test=
- checkfile -a -a
- result 0 'Invalid command-line with --all - 4'
- )
- (
- test="$(makefile bin/--all:0755 usr/bin/--all:0755)"
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- test=
- checkfile -a --all
- result 0 'Invalid command-line with --all - 5'
- )
- (
- test="$(makefile bin/-a:0755 usr/bin/-a:0755)"
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- test=
- checkfile --all -a
- result 0 'Invalid command-line with --all - 6'
- )
- # test --all at the end of the commandline - pass
- (
- test="$(makefile bin/-a:0755 bin/testfile:0755 usr/bin/testfile:0755)"
- settest "$rootdir"/tests/bin/testfile "$rootdir"/tests/bin/-a
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- checkfile testfile -a
- result 0 'Executable files with --all at the end of the command-line - 1'
- )
- (
- test="$(makefile bin/--all:0755 bin/testfile:0755 usr/bin/testfile:0755)"
- settest "$rootdir"/tests/bin/testfile "$rootdir"/tests/bin/--all
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- checkfile testfile --all
- result 0 'Executable files with --all at the end of the command-line - 2'
- )
- # test --all at the end of the commandline - fail
- (
- test="$(makefile bin/testfile:0755 usr/bin/testfile:0755)"
- settest "$rootdir"/tests/bin/testfile
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- checkfile testfile -a
- result 1 'Executable files with --all at the end of the command-line - 3'
- )
- (
- test="$(makefile bin/testfile:0755 usr/bin/testfile:0755)"
- settest "$rootdir"/tests/bin/testfile
- NEWPATH=tests/local/bin:tests/bin:tests/usr/bin
- checkfile testfile --all
- result 1 'Executable files with --all at the end of the command-line - 4'
- )
- fi
|