diff options
Diffstat (limited to 'tests')
92 files changed, 728 insertions, 208 deletions
diff --git a/tests/bfs/Dmulti.out b/tests/bfs/Dmulti.out new file mode 100644 index 0000000..a7ccfe4 --- /dev/null +++ b/tests/bfs/Dmulti.out @@ -0,0 +1,19 @@ +basic +basic/a +basic/b +basic/c +basic/c/d +basic/e +basic/e/f +basic/g +basic/g/h +basic/i +basic/j +basic/j/foo +basic/k +basic/k/foo +basic/k/foo/bar +basic/l +basic/l/foo +basic/l/foo/bar +basic/l/foo/bar/baz diff --git a/tests/bfs/Dmulti.sh b/tests/bfs/Dmulti.sh new file mode 100644 index 0000000..35d64b1 --- /dev/null +++ b/tests/bfs/Dmulti.sh @@ -0,0 +1 @@ +bfs_diff -Dopt,tree,unknown basic diff --git a/tests/bfs/LD_stat.out b/tests/bfs/LD_stat.out new file mode 100644 index 0000000..ec9e861 --- /dev/null +++ b/tests/bfs/LD_stat.out @@ -0,0 +1,17 @@ +links +links/broken +links/deeply +links/deeply/nested +links/deeply/nested/broken +links/deeply/nested/dir +links/deeply/nested/file +links/deeply/nested/link +links/file +links/hardlink +links/notdir +links/skip +links/skip/broken +links/skip/dir +links/skip/file +links/skip/link +links/symlink diff --git a/tests/bfs/LD_stat.sh b/tests/bfs/LD_stat.sh new file mode 100644 index 0000000..d407de3 --- /dev/null +++ b/tests/bfs/LD_stat.sh @@ -0,0 +1 @@ +bfs_diff -LD stat links diff --git a/tests/bfs/LDstat.out b/tests/bfs/LDstat.out new file mode 100644 index 0000000..ec9e861 --- /dev/null +++ b/tests/bfs/LDstat.out @@ -0,0 +1,17 @@ +links +links/broken +links/deeply +links/deeply/nested +links/deeply/nested/broken +links/deeply/nested/dir +links/deeply/nested/file +links/deeply/nested/link +links/file +links/hardlink +links/notdir +links/skip +links/skip/broken +links/skip/dir +links/skip/file +links/skip/link +links/symlink diff --git a/tests/bfs/LDstat.sh b/tests/bfs/LDstat.sh new file mode 100644 index 0000000..ec6df0b --- /dev/null +++ b/tests/bfs/LDstat.sh @@ -0,0 +1 @@ +bfs_diff -LDstat links diff --git a/tests/bfs/O_3.sh b/tests/bfs/O_3.sh new file mode 100644 index 0000000..f159852 --- /dev/null +++ b/tests/bfs/O_3.sh @@ -0,0 +1 @@ +! invoke_bfs -O 3 basic diff --git a/tests/bfs/Sbfs.out b/tests/bfs/Sbfs.out new file mode 100644 index 0000000..bb3cd8d --- /dev/null +++ b/tests/bfs/Sbfs.out @@ -0,0 +1,19 @@ +basic +basic/a +basic/b +basic/c +basic/e +basic/g +basic/i +basic/j +basic/k +basic/l +basic/c/d +basic/e/f +basic/g/h +basic/j/foo +basic/k/foo +basic/l/foo +basic/k/foo/bar +basic/l/foo/bar +basic/l/foo/bar/baz diff --git a/tests/bfs/Sbfs.sh b/tests/bfs/Sbfs.sh new file mode 100644 index 0000000..72d92c8 --- /dev/null +++ b/tests/bfs/Sbfs.sh @@ -0,0 +1,2 @@ +invoke_bfs -Sbfs -s basic >"$OUT" +diff_output diff --git a/tests/bfs/color_ext_case.sh b/tests/bfs/color_ext_case.sh index 4adba69..4c14610 100644 --- a/tests/bfs/color_ext_case.sh +++ b/tests/bfs/color_ext_case.sh @@ -1,6 +1,6 @@ -# *.gz=01;31:*.GZ=01;32 -- case sensitive -# *.tAr=01;33:*.TaR=01;33 -- case-insensitive -# *.TAR.gz=01;34:*.tar.GZ=01;35 -- case-sensitive -# *.txt=35:*TXT=36 -- case-insensitive -export LS_COLORS="*.gz=01;31:*.GZ=01;32:*.tAr=01;33:*.TaR=01;33:*.TAR.gz=01;34:*.tar.GZ=01;35:*.txt=35:*TXT=36" +# *.gz=01;30:*.gz=01;31:*.GZ=01;30:*.GZ=01;32 -- case sensitive +# *.tAr=01;33:*.TaR=01;33 -- case-insensitive +# *.TAR.gz=01;34:*.tar.GZ=01;35 -- case-sensitive +# *.txt=35:*TXT=36 -- case-insensitive +export LS_COLORS="*.gz=01;30:*.gz=01;31:*.GZ=01;30:*.GZ=01;32:*.tAr=01;33:*.TaR=01;33:*.TAR.gz=01;34:*.tar.GZ=01;35:*.txt=35:*TXT=36" bfs_diff rainbow -color diff --git a/tests/bfs/color_ext_override.sh b/tests/bfs/color_ext_override.sh index ac4c7fb..9f818c9 100644 --- a/tests/bfs/color_ext_override.sh +++ b/tests/bfs/color_ext_override.sh @@ -1 +1 @@ -LS_COLORS="*.tar.gz=01;31:*.TAR=01;32:*.gz=01;33:" bfs_diff rainbow -color +LS_COLORS="*.tar.gz=01;31:*.TAR=01;32:*.gz=01;30:*.gz=01;33:" bfs_diff rainbow -color diff --git a/tests/bfs/nohidden.out b/tests/bfs/nohidden.out index d3ec901..84e6bd2 100644 --- a/tests/bfs/nohidden.out +++ b/tests/bfs/nohidden.out @@ -1,4 +1,8 @@ + +/n weirdnames +weirdnames/ +weirdnames/ weirdnames/ weirdnames/ /j weirdnames/! @@ -11,6 +15,8 @@ weirdnames/(-/c weirdnames/(/b weirdnames/) weirdnames/)/g +weirdnames/* +weirdnames/*/m weirdnames/, weirdnames/,/f weirdnames/- @@ -19,3 +25,5 @@ weirdnames/[ weirdnames/[/k weirdnames/\ weirdnames/\/i +weirdnames/{ +weirdnames/{/l diff --git a/tests/bfs/nohidden_depth.out b/tests/bfs/nohidden_depth.out index d3ec901..84e6bd2 100644 --- a/tests/bfs/nohidden_depth.out +++ b/tests/bfs/nohidden_depth.out @@ -1,4 +1,8 @@ + +/n weirdnames +weirdnames/ +weirdnames/ weirdnames/ weirdnames/ /j weirdnames/! @@ -11,6 +15,8 @@ weirdnames/(-/c weirdnames/(/b weirdnames/) weirdnames/)/g +weirdnames/* +weirdnames/*/m weirdnames/, weirdnames/,/f weirdnames/- @@ -19,3 +25,5 @@ weirdnames/[ weirdnames/[/k weirdnames/\ weirdnames/\/i +weirdnames/{ +weirdnames/{/l diff --git a/tests/bfs/printf_invalid_flag.sh b/tests/bfs/printf_invalid_flag.sh new file mode 100644 index 0000000..70dfe97 --- /dev/null +++ b/tests/bfs/printf_invalid_flag.sh @@ -0,0 +1 @@ +! invoke_bfs basic -printf '% p' diff --git a/tests/bfs/xtype_depth.sh b/tests/bfs/xtype_depth.sh index 02c8173..4683764 100644 --- a/tests/bfs/xtype_depth.sh +++ b/tests/bfs/xtype_depth.sh @@ -1,2 +1,2 @@ # Make sure -xtype is considered side-effecting for facts_when_impure -! invoke_bfs loops -xtype l -depth 100 +! invoke_bfs inaccessible/link -xtype l -depth 100 diff --git a/tests/bfs/xtype_reorder.sh b/tests/bfs/xtype_reorder.sh index 8d75d7d..c1d94f3 100644 --- a/tests/bfs/xtype_reorder.sh +++ b/tests/bfs/xtype_reorder.sh @@ -1,4 +1,3 @@ # Make sure -xtype is not reordered in front of anything -- if -xtype runs # before -links 100, it will report an ELOOP error -bfs_diff loops -links 100 -xtype l -invoke_bfs loops -links 100 -xtype l +bfs_diff inaccessible/link -links 100 -xtype l diff --git a/tests/bit.c b/tests/bit.c index 674d1b2..49e167d 100644 --- a/tests/bit.c +++ b/tests/bit.c @@ -76,15 +76,15 @@ bool check_bit(void) { ret &= check_eq(bswap((uint32_t)0x12345678), 0x78563412); ret &= check_eq(bswap((uint64_t)0x1234567812345678), 0x7856341278563412); - ret &= check_eq(count_ones(0x0), 0); - ret &= check_eq(count_ones(0x1), 1); - ret &= check_eq(count_ones(0x2), 1); - ret &= check_eq(count_ones(0x3), 2); - ret &= check_eq(count_ones(0x137F), 10); - - ret &= check_eq(count_zeros(0), INT_WIDTH); - ret &= check_eq(count_zeros(0L), LONG_WIDTH); - ret &= check_eq(count_zeros(0LL), LLONG_WIDTH); + ret &= check_eq(count_ones(0x0U), 0); + ret &= check_eq(count_ones(0x1U), 1); + ret &= check_eq(count_ones(0x2U), 1); + ret &= check_eq(count_ones(0x3U), 2); + ret &= check_eq(count_ones(0x137FU), 10); + + ret &= check_eq(count_zeros(0U), UINT_WIDTH); + ret &= check_eq(count_zeros(0UL), ULONG_WIDTH); + ret &= check_eq(count_zeros(0ULL), ULLONG_WIDTH); ret &= check_eq(count_zeros((uint8_t)0), 8); ret &= check_eq(count_zeros((uint16_t)0), 16); ret &= check_eq(count_zeros((uint32_t)0), 32); @@ -100,16 +100,16 @@ bool check_bit(void) { ret &= check_eq(rotate_right((uint32_t)0x12345678, 20), 0x45678123); ret &= check_eq(rotate_right((uint32_t)0x12345678, 0), 0x12345678); - for (int i = 0; i < 16; ++i) { + for (unsigned int i = 0; i < 16; ++i) { uint16_t n = (uint16_t)1 << i; - for (int j = i; j < 16; ++j) { + for (unsigned int j = i; j < 16; ++j) { uint16_t m = (uint16_t)1 << j; uint16_t nm = n | m; ret &= check_eq(count_ones(nm), 1 + (n != m)); ret &= check_eq(count_zeros(nm), 15 - (n != m)); ret &= check_eq(leading_zeros(nm), 15 - j); ret &= check_eq(trailing_zeros(nm), i); - ret &= check_eq(first_leading_one(nm), j + 1); + ret &= check_eq(first_leading_one(nm), 16 - j); ret &= check_eq(first_trailing_one(nm), i + 1); ret &= check_eq(bit_width(nm), j + 1); ret &= check_eq(bit_floor(nm), m); @@ -127,13 +127,13 @@ bool check_bit(void) { ret &= check_eq(leading_zeros((uint16_t)0), 16); ret &= check_eq(trailing_zeros((uint16_t)0), 16); - ret &= check_eq(first_leading_one(0), 0); - ret &= check_eq(first_trailing_one(0), 0); - ret &= check_eq(bit_width(0), 0); - ret &= check_eq(bit_floor(0), 0); - ret &= check_eq(bit_ceil(0), 1); + ret &= check_eq(first_leading_one(0U), 0); + ret &= check_eq(first_trailing_one(0U), 0); + ret &= check_eq(bit_width(0U), 0); + ret &= check_eq(bit_floor(0U), 0); + ret &= check_eq(bit_ceil(0U), 1); - ret &= bfs_check(!has_single_bit(0)); + ret &= bfs_check(!has_single_bit(0U)); ret &= bfs_check(!has_single_bit(UINT32_MAX)); ret &= bfs_check(has_single_bit((uint32_t)1 << (UINT_WIDTH - 1))); diff --git a/tests/bsd/Hf.out b/tests/bsd/Hf.out new file mode 100644 index 0000000..ff635ff --- /dev/null +++ b/tests/bsd/Hf.out @@ -0,0 +1 @@ +links/deeply/nested/dir diff --git a/tests/bsd/Hf.sh b/tests/bsd/Hf.sh new file mode 100644 index 0000000..333280c --- /dev/null +++ b/tests/bsd/Hf.sh @@ -0,0 +1 @@ +bfs_diff -Hf links/deeply/nested/dir diff --git a/tests/bsd/X.out b/tests/bsd/X.out index afa84f7..dbe2408 100644 --- a/tests/bsd/X.out +++ b/tests/bsd/X.out @@ -9,6 +9,8 @@ weirdnames/(-/c weirdnames/(/b weirdnames/) weirdnames/)/g +weirdnames/* +weirdnames/*/m weirdnames/, weirdnames/,/f weirdnames/- @@ -17,3 +19,5 @@ weirdnames/... weirdnames/.../h weirdnames/[ weirdnames/[/k +weirdnames/{ +weirdnames/{/l diff --git a/tests/bsd/perm_000_plus.out b/tests/bsd/perm_000_plus.out index d7494b8..42f2fed 100644 --- a/tests/bsd/perm_000_plus.out +++ b/tests/bsd/perm_000_plus.out @@ -1,8 +1,10 @@ perms -perms/0 -perms/r -perms/rw -perms/rwx -perms/rx -perms/w -perms/wx +perms/dr-x +perms/drwx +perms/f--- +perms/f-w- +perms/f-wx +perms/fr-- +perms/fr-x +perms/frw- +perms/frwx diff --git a/tests/bsd/perm_222_plus.out b/tests/bsd/perm_222_plus.out index 9a5b95a..5c78ecc 100644 --- a/tests/bsd/perm_222_plus.out +++ b/tests/bsd/perm_222_plus.out @@ -1,5 +1,6 @@ perms -perms/rw -perms/rwx -perms/w -perms/wx +perms/drwx +perms/f-w- +perms/f-wx +perms/frw- +perms/frwx diff --git a/tests/bsd/perm_644_plus.out b/tests/bsd/perm_644_plus.out index 7e5ae98..774c0ea 100644 --- a/tests/bsd/perm_644_plus.out +++ b/tests/bsd/perm_644_plus.out @@ -1,7 +1,9 @@ perms -perms/r -perms/rw -perms/rwx -perms/rx -perms/w -perms/wx +perms/dr-x +perms/drwx +perms/f-w- +perms/f-wx +perms/fr-- +perms/fr-x +perms/frw- +perms/frwx diff --git a/tests/bsd/printx.out b/tests/bsd/printx.out index 04bf9a9..034b2da 100644 --- a/tests/bsd/printx.out +++ b/tests/bsd/printx.out @@ -1,3 +1,5 @@ + +/n weirdnames weirdnames/! weirdnames/!- @@ -9,6 +11,8 @@ weirdnames/(-/c weirdnames/(/b weirdnames/) weirdnames/)/g +weirdnames/* +weirdnames/*/m weirdnames/, weirdnames/,/f weirdnames/- @@ -17,7 +21,11 @@ weirdnames/... weirdnames/.../h weirdnames/[ weirdnames/[/k +weirdnames/\ +weirdnames/\ weirdnames/\ weirdnames/\ /j weirdnames/\\ weirdnames/\\/i +weirdnames/{ +weirdnames/{/l diff --git a/tests/bsd/s.out b/tests/bsd/s.out index 6b790c2..5c85ac8 100644 --- a/tests/bsd/s.out +++ b/tests/bsd/s.out @@ -1,12 +1,16 @@ weirdnames +weirdnames/ + weirdnames/ weirdnames/! weirdnames/!- weirdnames/( weirdnames/(- weirdnames/) +weirdnames/* weirdnames/, weirdnames/- weirdnames/... weirdnames/[ weirdnames/\ +weirdnames/{ diff --git a/tests/color.sh b/tests/color.sh index 805d2b8..4f4312e 100644 --- a/tests/color.sh +++ b/tests/color.sh @@ -35,3 +35,119 @@ color() { "$@" | "$SED" $'s/\e\\[[^m]*m//g' fi } + +## Status bar + +# Show the terminal status bar +show_bar() { + if [ -z "$TTY" ]; then + return 1 + fi + + # Name the pipe deterministically based on the ttyname, so that concurrent + # tests.sh runs on the same terminal (e.g. make -jN check) cooperate + local pipe + pipe=$(printf '%s' "$TTY" | tr '/' '-') + pipe="${TMPDIR:-/tmp}/bfs$pipe.bar" + + if mkfifo "$pipe" 2>/dev/null; then + # We won the race, create the background process to manage the bar + bar_proc "$pipe" & + exec {BAR}>"$pipe" + elif [ -p "$pipe" ]; then + # We lost the race, connect to the existing process. + # There is a small TOCTTOU race here but I don't see how to avoid it. + exec {BAR}>"$pipe" + else + return 1 + fi +} + +# Print to the terminal status bar +print_bar() { + printf 'PRINT:%d:%s\0' $$ "$1" >&$BAR +} + +# Hide the terminal status bar +hide_bar() { + printf 'HIDE:%d:\0' $$ >&$BAR + exec {BAR}>&- + unset BAR +} + +# The background process that muxes multiple status bars for one TTY +bar_proc() { + # Read from the pipe, write to the TTY + exec <"$1" >"$TTY" + + # Delete the pipe when done + defer rm "$1" + # Reset the scroll region when done + defer printf '\e7\e[r\e8\e[J' + + # Workaround for bash 4: checkwinsize is off by default. We can turn it + # on, but we also have to explicitly trigger a foreground job to finish + # so that it will update the window size before we use $LINES + shopt -s checkwinsize + (:) + + BAR_HEIGHT=0 + resize_bar + # Adjust the bar when the TTY size changes + trap resize_bar WINCH + + # Map from PID to status bar + local -A pid2bar + + # Read commands of the form "OP:PID:STRING\0" + while IFS=':' read -r -d '' op pid str; do + # Map the pid to a bar, creating a new one if necessary + if [ -z "${pid2bar[$pid]:-}" ]; then + pid2bar["$pid"]=$((BAR_HEIGHT++)) + resize_bar + fi + bar="${pid2bar[$pid]}" + + case "$op" in + PRINT) + printf '\e7\e[%d;0f\e[K%s\e8' $((TTY_HEIGHT - bar)) "$str" + ;; + HIDE) + bar="${pid2bar[$pid]}" + # Delete this status bar + unset 'pid2bar[$pid]' + # Shift all higher status bars down + for i in "${!pid2bar[@]}"; do + ibar="${pid2bar[$i]}" + if ((ibar > bar)); then + pid2bar["$i"]=$((ibar - 1)) + fi + done + ((BAR_HEIGHT--)) + resize_bar + ;; + esac + done +} + +# Resize the status bar +resize_bar() { + # Bash gets $LINES from stderr, so if it's redirected use tput instead + TTY_HEIGHT="${LINES:-$(tput lines 2>"$TTY")}" + + if ((BAR_HEIGHT == 0)); then + return + fi + + # Hide the bars temporarily + local seq='\e7\e[r\e8\e[J' + # Print \eD (IND) N times to ensure N blank lines at the bottom + for ((i = 0; i < BAR_HEIGHT; ++i)); do + seq="${seq}\\eD" + done + # Go back up N lines + seq="${seq}\\e[${BAR_HEIGHT}A" + # Create the new scroll region + seq="${seq}\\e7\\e[;$((TTY_HEIGHT - BAR_HEIGHT))r\\e8\\e[J" + printf "$seq" +} diff --git a/tests/common/HLP.out b/tests/common/HLP.out new file mode 100644 index 0000000..ff635ff --- /dev/null +++ b/tests/common/HLP.out @@ -0,0 +1 @@ +links/deeply/nested/dir diff --git a/tests/common/HLP.sh b/tests/common/HLP.sh new file mode 100644 index 0000000..4b6d631 --- /dev/null +++ b/tests/common/HLP.sh @@ -0,0 +1 @@ +bfs_diff -HLP links/deeply/nested/dir diff --git a/tests/common/amin.out b/tests/common/amin.out new file mode 100644 index 0000000..af57325 --- /dev/null +++ b/tests/common/amin.out @@ -0,0 +1,6 @@ +-amin 1: ./one_minute_ago +-amin +1: ./one_hour_ago +-amin +1: ./two_minutes_ago +-amin -1: ./in_one_hour +-amin -1: ./in_one_minute +-amin -1: ./thirty_seconds_ago diff --git a/tests/common/amin.sh b/tests/common/amin.sh new file mode 100644 index 0000000..c4d53fb --- /dev/null +++ b/tests/common/amin.sh @@ -0,0 +1,15 @@ +cd "$TEST" + +now=$(epoch_time) + +"$XTOUCH" -at "@$((now - 60 * 60))" one_hour_ago +"$XTOUCH" -at "@$((now - 121))" two_minutes_ago +"$XTOUCH" -at "@$((now - 61))" one_minute_ago +"$XTOUCH" -at "@$((now - 30))" thirty_seconds_ago +"$XTOUCH" -at "@$((now + 60))" in_one_minute +"$XTOUCH" -at "@$((now + 60 * 60))" in_one_hour + +bfs_diff -mindepth 1 \ + \( -amin -1 -exec printf -- '-amin -1: %s\n' {} \; -o -true \) \ + \( -amin 1 -exec printf -- '-amin 1: %s\n' {} \; -o -true \) \ + \( -amin +1 -exec printf -- '-amin +1: %s\n' {} \; -o -true \) diff --git a/tests/common/atime.out b/tests/common/atime.out new file mode 100644 index 0000000..5ed206b --- /dev/null +++ b/tests/common/atime.out @@ -0,0 +1,6 @@ +-atime 1: ./yesterday +-atime +1: ./last_week +-atime +1: ./two_days_ago +-atime -1: ./now +-atime -1: ./one_hour_ago +-atime -1: ./tomorrow diff --git a/tests/common/atime.sh b/tests/common/atime.sh new file mode 100644 index 0000000..c2e4031 --- /dev/null +++ b/tests/common/atime.sh @@ -0,0 +1,15 @@ +cd "$TEST" + +now=$(epoch_time) + +"$XTOUCH" -at "@$((now - 60 * 60 * 24 * 7))" last_week +"$XTOUCH" -at "@$((now - 60 * 60 * 49))" two_days_ago +"$XTOUCH" -at "@$((now - 60 * 60 * 25))" yesterday +"$XTOUCH" -at "@$((now - 60 * 60))" one_hour_ago +"$XTOUCH" -at "@$((now))" now +"$XTOUCH" -at "@$((now + 60 * 60 * 24))" tomorrow + +bfs_diff -mindepth 1 \ + \( -atime -1 -exec printf -- '-atime -1: %s\n' {} \; -o -true \) \ + \( -atime 1 -exec printf -- '-atime 1: %s\n' {} \; -o -true \) \ + \( -atime +1 -exec printf -- '-atime +1: %s\n' {} \; -o -true \) diff --git a/tests/common/empty_error.out b/tests/common/empty_error.out index da45e23..49f773d 100644 --- a/tests/common/empty_error.out +++ b/tests/common/empty_error.out @@ -1,3 +1 @@ -./bar -./baz -./qux +inaccessible/file diff --git a/tests/common/empty_error.sh b/tests/common/empty_error.sh index 7c8049c..3438cca 100644 --- a/tests/common/empty_error.sh +++ b/tests/common/empty_error.sh @@ -1,7 +1 @@ -cd "$TEST" - -"$XTOUCH" -p foo/ bar/ baz qux -chmod -r foo baz -defer chmod +r foo baz - -! bfs_diff . -empty +! bfs_diff inaccessible -empty diff --git a/tests/common/mmin.out b/tests/common/mmin.out new file mode 100644 index 0000000..4c79a16 --- /dev/null +++ b/tests/common/mmin.out @@ -0,0 +1,6 @@ +-mmin 1: ./one_minute_ago +-mmin +1: ./one_hour_ago +-mmin +1: ./two_minutes_ago +-mmin -1: ./in_one_hour +-mmin -1: ./in_one_minute +-mmin -1: ./thirty_seconds_ago diff --git a/tests/common/mmin.sh b/tests/common/mmin.sh new file mode 100644 index 0000000..38e3337 --- /dev/null +++ b/tests/common/mmin.sh @@ -0,0 +1,15 @@ +cd "$TEST" + +now=$(epoch_time) + +"$XTOUCH" -mt "@$((now - 60 * 60))" one_hour_ago +"$XTOUCH" -mt "@$((now - 121))" two_minutes_ago +"$XTOUCH" -mt "@$((now - 61))" one_minute_ago +"$XTOUCH" -mt "@$((now - 30))" thirty_seconds_ago +"$XTOUCH" -mt "@$((now + 60))" in_one_minute +"$XTOUCH" -mt "@$((now + 60 * 60))" in_one_hour + +bfs_diff -mindepth 1 \ + \( -mmin -1 -exec printf -- '-mmin -1: %s\n' {} \; -o -true \) \ + \( -mmin 1 -exec printf -- '-mmin 1: %s\n' {} \; -o -true \) \ + \( -mmin +1 -exec printf -- '-mmin +1: %s\n' {} \; -o -true \) diff --git a/tests/common/mtime.out b/tests/common/mtime.out new file mode 100644 index 0000000..91f0114 --- /dev/null +++ b/tests/common/mtime.out @@ -0,0 +1,6 @@ +-mtime 1: ./yesterday +-mtime +1: ./last_week +-mtime +1: ./two_days_ago +-mtime -1: ./now +-mtime -1: ./one_hour_ago +-mtime -1: ./tomorrow diff --git a/tests/common/mtime.sh b/tests/common/mtime.sh new file mode 100644 index 0000000..7ba127e --- /dev/null +++ b/tests/common/mtime.sh @@ -0,0 +1,15 @@ +cd "$TEST" + +now=$(epoch_time) + +"$XTOUCH" -mt "@$((now - 60 * 60 * 24 * 7))" last_week +"$XTOUCH" -mt "@$((now - 60 * 60 * 49))" two_days_ago +"$XTOUCH" -mt "@$((now - 60 * 60 * 25))" yesterday +"$XTOUCH" -mt "@$((now - 60 * 60))" one_hour_ago +"$XTOUCH" -mt "@$((now))" now +"$XTOUCH" -mt "@$((now + 60 * 60 * 24))" tomorrow + +bfs_diff -mindepth 1 \ + \( -mtime -1 -exec printf -- '-mtime -1: %s\n' {} \; -o -true \) \ + \( -mtime 1 -exec printf -- '-mtime 1: %s\n' {} \; -o -true \) \ + \( -mtime +1 -exec printf -- '-mtime +1: %s\n' {} \; -o -true \) diff --git a/tests/gnu/executable.out b/tests/gnu/executable.out index 49c1b21..08965bf 100644 --- a/tests/gnu/executable.out +++ b/tests/gnu/executable.out @@ -1,4 +1,6 @@ perms -perms/rwx -perms/rx -perms/wx +perms/dr-x +perms/drwx +perms/f-wx +perms/fr-x +perms/frwx diff --git a/tests/gnu/files0_from_file.out b/tests/gnu/files0_from_file.out index 1d87e6b..0f6b00d 100644 --- a/tests/gnu/files0_from_file.out +++ b/tests/gnu/files0_from_file.out @@ -1,3 +1,7 @@ + + + + /j /j @@ -16,6 +20,9 @@ ) )/g )/g +* +*/m +*/m , ,/f ,/f @@ -25,9 +32,14 @@ ... .../h .../h +/n +/n [ [/k [/k \ \/i \/i +{ +{/l +{/l diff --git a/tests/gnu/files0_from_stdin.out b/tests/gnu/files0_from_stdin.out index 1d87e6b..0f6b00d 100644 --- a/tests/gnu/files0_from_stdin.out +++ b/tests/gnu/files0_from_stdin.out @@ -1,3 +1,7 @@ + + + + /j /j @@ -16,6 +20,9 @@ ) )/g )/g +* +*/m +*/m , ,/f ,/f @@ -25,9 +32,14 @@ ... .../h .../h +/n +/n [ [/k [/k \ \/i \/i +{ +{/l +{/l diff --git a/tests/gnu/follow_comma.out b/tests/gnu/follow_comma.out index 920b3d3..5e4b806 100644 --- a/tests/gnu/follow_comma.out +++ b/tests/gnu/follow_comma.out @@ -1,4 +1,7 @@ + . +./ +./ ./ ./ /j ./! @@ -11,6 +14,8 @@ ./(/b ./) ./)/g +./* +./*/m ./, ./,/f ./- @@ -21,3 +26,6 @@ ./[/k ./\ ./\/i +./{ +./{/l +/n diff --git a/tests/gnu/ignore_readdir_race_loop.out b/tests/gnu/ignore_readdir_race_loop.out new file mode 100644 index 0000000..a514555 --- /dev/null +++ b/tests/gnu/ignore_readdir_race_loop.out @@ -0,0 +1,11 @@ +loops +loops/broken +loops/deeply +loops/deeply/nested +loops/deeply/nested/dir +loops/file +loops/notdir +loops/skip +loops/skip/dir +loops/skip/loop +loops/symlink diff --git a/tests/gnu/ignore_readdir_race_loop.sh b/tests/gnu/ignore_readdir_race_loop.sh new file mode 100644 index 0000000..3329169 --- /dev/null +++ b/tests/gnu/ignore_readdir_race_loop.sh @@ -0,0 +1,2 @@ +# Make sure -ignore_readdir_race doesn't suppress ELOOP from an actual filesystem loop +! bfs_diff -L loops -ignore_readdir_race diff --git a/tests/gnu/perm_000_slash.out b/tests/gnu/perm_000_slash.out index d7494b8..42f2fed 100644 --- a/tests/gnu/perm_000_slash.out +++ b/tests/gnu/perm_000_slash.out @@ -1,8 +1,10 @@ perms -perms/0 -perms/r -perms/rw -perms/rwx -perms/rx -perms/w -perms/wx +perms/dr-x +perms/drwx +perms/f--- +perms/f-w- +perms/f-wx +perms/fr-- +perms/fr-x +perms/frw- +perms/frwx diff --git a/tests/gnu/perm_222_slash.out b/tests/gnu/perm_222_slash.out index 9a5b95a..5c78ecc 100644 --- a/tests/gnu/perm_222_slash.out +++ b/tests/gnu/perm_222_slash.out @@ -1,5 +1,6 @@ perms -perms/rw -perms/rwx -perms/w -perms/wx +perms/drwx +perms/f-w- +perms/f-wx +perms/frw- +perms/frwx diff --git a/tests/gnu/perm_644_slash.out b/tests/gnu/perm_644_slash.out index 7e5ae98..774c0ea 100644 --- a/tests/gnu/perm_644_slash.out +++ b/tests/gnu/perm_644_slash.out @@ -1,7 +1,9 @@ perms -perms/r -perms/rw -perms/rwx -perms/rx -perms/w -perms/wx +perms/dr-x +perms/drwx +perms/f-w- +perms/f-wx +perms/fr-- +perms/fr-x +perms/frw- +perms/frwx diff --git a/tests/gnu/perm_leading_plus_symbolic_slash.out b/tests/gnu/perm_leading_plus_symbolic_slash.out index 7e5ae98..774c0ea 100644 --- a/tests/gnu/perm_leading_plus_symbolic_slash.out +++ b/tests/gnu/perm_leading_plus_symbolic_slash.out @@ -1,7 +1,9 @@ perms -perms/r -perms/rw -perms/rwx -perms/rx -perms/w -perms/wx +perms/dr-x +perms/drwx +perms/f-w- +perms/f-wx +perms/fr-- +perms/fr-x +perms/frw- +perms/frwx diff --git a/tests/gnu/perm_symbolic_slash.out b/tests/gnu/perm_symbolic_slash.out index 7e5ae98..774c0ea 100644 --- a/tests/gnu/perm_symbolic_slash.out +++ b/tests/gnu/perm_symbolic_slash.out @@ -1,7 +1,9 @@ perms -perms/r -perms/rw -perms/rwx -perms/rx -perms/w -perms/wx +perms/dr-x +perms/drwx +perms/f-w- +perms/f-wx +perms/fr-- +perms/fr-x +perms/frw- +perms/frwx diff --git a/tests/gnu/printf_flags.sh b/tests/gnu/printf_flags.sh index 2ef37ad..98e8faa 100644 --- a/tests/gnu/printf_flags.sh +++ b/tests/gnu/printf_flags.sh @@ -1 +1 @@ -bfs_diff basic -printf '|%- 10.10p| %+03d %#4m\n' +bfs_diff basic -printf '|%-10.10p| %+03d % #4m\n' diff --git a/tests/gnu/readable.out b/tests/gnu/readable.out index 386feba..285aa43 100644 --- a/tests/gnu/readable.out +++ b/tests/gnu/readable.out @@ -1,5 +1,7 @@ perms -perms/r -perms/rw -perms/rwx -perms/rx +perms/dr-x +perms/drwx +perms/fr-- +perms/fr-x +perms/frw- +perms/frwx diff --git a/tests/gnu/regextype_awk.out b/tests/gnu/regextype_awk.out new file mode 100644 index 0000000..0f32fc4 --- /dev/null +++ b/tests/gnu/regextype_awk.out @@ -0,0 +1,2 @@ +weirdnames/*/m +weirdnames/[/k diff --git a/tests/gnu/regextype_awk.sh b/tests/gnu/regextype_awk.sh new file mode 100644 index 0000000..3718473 --- /dev/null +++ b/tests/gnu/regextype_awk.sh @@ -0,0 +1,3 @@ +invoke_bfs -regextype awk -quit || skip + +bfs_diff weirdnames -regextype awk -regex '.*/[\[\*]/.*' diff --git a/tests/gnu/regextype_egrep.out b/tests/gnu/regextype_egrep.out new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/gnu/regextype_egrep.out diff --git a/tests/gnu/regextype_egrep.sh b/tests/gnu/regextype_egrep.sh new file mode 100644 index 0000000..281d9c0 --- /dev/null +++ b/tests/gnu/regextype_egrep.sh @@ -0,0 +1,3 @@ +invoke_bfs -regextype egrep -quit || skip + +bfs_diff weirdnames -regextype egrep -regex '*.*/{l' diff --git a/tests/gnu/regextype_emacs.sh b/tests/gnu/regextype_emacs.sh index 3cc388c..164d17a 100644 --- a/tests/gnu/regextype_emacs.sh +++ b/tests/gnu/regextype_emacs.sh @@ -1,3 +1,3 @@ invoke_bfs -regextype emacs -quit || skip -bfs_diff basic -regextype emacs -regex '.*/\(f+o?o?\|bar\)' +bfs_diff basic -regextype emacs -regex '.*/\(?:f+o?o?\|bar\)' diff --git a/tests/gnu/regextype_findutils_default.out b/tests/gnu/regextype_findutils_default.out new file mode 100644 index 0000000..709a7ba --- /dev/null +++ b/tests/gnu/regextype_findutils_default.out @@ -0,0 +1,3 @@ +/n +weirdnames/ +weirdnames/*/m diff --git a/tests/gnu/regextype_findutils_default.sh b/tests/gnu/regextype_findutils_default.sh new file mode 100644 index 0000000..c870312 --- /dev/null +++ b/tests/gnu/regextype_findutils_default.sh @@ -0,0 +1,3 @@ +invoke_bfs -regextype findutils-default -quit || skip + +bfs_diff weirdnames -regextype findutils-default -regex '.*/./\(m\|n\)' diff --git a/tests/gnu/regextype_gnu_awk.out b/tests/gnu/regextype_gnu_awk.out new file mode 100644 index 0000000..0f32fc4 --- /dev/null +++ b/tests/gnu/regextype_gnu_awk.out @@ -0,0 +1,2 @@ +weirdnames/*/m +weirdnames/[/k diff --git a/tests/gnu/regextype_gnu_awk.sh b/tests/gnu/regextype_gnu_awk.sh new file mode 100644 index 0000000..6b66496 --- /dev/null +++ b/tests/gnu/regextype_gnu_awk.sh @@ -0,0 +1,3 @@ +invoke_bfs -regextype gnu-awk -quit || skip + +bfs_diff weirdnames -regextype gnu-awk -regex '.*/[\[\*]/(\<.\>)' diff --git a/tests/gnu/regextype_posix_awk.out b/tests/gnu/regextype_posix_awk.out new file mode 100644 index 0000000..0f32fc4 --- /dev/null +++ b/tests/gnu/regextype_posix_awk.out @@ -0,0 +1,2 @@ +weirdnames/*/m +weirdnames/[/k diff --git a/tests/gnu/regextype_posix_awk.sh b/tests/gnu/regextype_posix_awk.sh new file mode 100644 index 0000000..86377d7 --- /dev/null +++ b/tests/gnu/regextype_posix_awk.sh @@ -0,0 +1,3 @@ +invoke_bfs -regextype posix-awk -quit || skip + +bfs_diff weirdnames -regextype posix-awk -regex '.*/[\[\*]/.*' diff --git a/tests/gnu/regextype_posix_minimal_basic.out b/tests/gnu/regextype_posix_minimal_basic.out new file mode 100644 index 0000000..0f0971e --- /dev/null +++ b/tests/gnu/regextype_posix_minimal_basic.out @@ -0,0 +1 @@ +./( diff --git a/tests/gnu/regextype_posix_minimal_basic.sh b/tests/gnu/regextype_posix_minimal_basic.sh new file mode 100644 index 0000000..ee324f3 --- /dev/null +++ b/tests/gnu/regextype_posix_minimal_basic.sh @@ -0,0 +1,2 @@ +cd weirdnames +bfs_diff -regextype posix-minimal-basic -regex '\./\((\)' diff --git a/tests/gnu/used.sh b/tests/gnu/used.sh index 5e5d4e9..fe0a778 100644 --- a/tests/gnu/used.sh +++ b/tests/gnu/used.sh @@ -1,37 +1,18 @@ -iso8601() { - printf '%04d-%02d-%02dT%02d:%02d:%02d\n' "$@" -} - cd "$TEST" -now=$(date '+%Y-%m-%dT%H:%M:%S') - -# Parse the current date -[[ "$now" =~ ^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})$ ]] || fail -# Treat leading zeros as decimal, not octal -YYYY=$((10#${BASH_REMATCH[1]})) -MM=$((10#${BASH_REMATCH[2]})) -DD=$((10#${BASH_REMATCH[3]})) -hh=$((10#${BASH_REMATCH[4]})) -mm=$((10#${BASH_REMATCH[5]})) -ss=$((10#${BASH_REMATCH[6]})) +now=$(epoch_time) # -used is always false if atime < ctime -yesterday=$(iso8601 $YYYY $MM $((DD - 1)) $hh $mm $ss) -"$XTOUCH" -at "$yesterday" yesterday +"$XTOUCH" -at "@$((now - 60 * 60 * 24))" yesterday # -used rounds up -tomorrow=$(iso8601 $YYYY $MM $DD $((hh + 1)) $mm $ss) -"$XTOUCH" -at "$tomorrow" tomorrow +"$XTOUCH" -at "@$((now + 60 * 60))" tomorrow -dayafter=$(iso8601 $YYYY $MM $((DD + 1)) $((hh + 1)) $mm $ss) -"$XTOUCH" -at "$dayafter" dayafter +"$XTOUCH" -at "@$((now + 60 * 60 * 25))" dayafter -nextweek=$(iso8601 $YYYY $MM $((DD + 6)) $((hh + 1)) $mm $ss) -"$XTOUCH" -at "$nextweek" nextweek +"$XTOUCH" -at "@$((now + 60 * 60 * (24 * 6 + 1)))" nextweek -nextyear=$(iso8601 $((YYYY + 1)) $MM $DD $hh $mm $ss) -"$XTOUCH" -at "$nextyear" nextyear +"$XTOUCH" -at "@$((now + 60 * 60 * 24 * 365))" nextyear bfs_diff -mindepth 1 \ -a -used 1 -printf '-used 1: %p\n' \ diff --git a/tests/gnu/writable.out b/tests/gnu/writable.out index 9a5b95a..5c78ecc 100644 --- a/tests/gnu/writable.out +++ b/tests/gnu/writable.out @@ -1,5 +1,6 @@ perms -perms/rw -perms/rwx -perms/w -perms/wx +perms/drwx +perms/f-w- +perms/f-wx +perms/frw- +perms/frwx diff --git a/tests/gnu/xtype_l_loops.out b/tests/gnu/xtype_l_loops.out new file mode 100644 index 0000000..fdaccab --- /dev/null +++ b/tests/gnu/xtype_l_loops.out @@ -0,0 +1,3 @@ +loops/broken +loops/loop +loops/notdir diff --git a/tests/gnu/xtype_l_loops.sh b/tests/gnu/xtype_l_loops.sh new file mode 100644 index 0000000..6893134 --- /dev/null +++ b/tests/gnu/xtype_l_loops.sh @@ -0,0 +1 @@ +bfs_diff loops -xtype l diff --git a/tests/list.c b/tests/list.c new file mode 100644 index 0000000..e14570f --- /dev/null +++ b/tests/list.c @@ -0,0 +1,97 @@ +// Copyright © Tavian Barnes <tavianator@tavianator.com> +// SPDX-License-Identifier: 0BSD + +#include "prelude.h" +#include "tests.h" +#include "list.h" + +struct item { + int n; + struct item *next; +}; + +struct list { + struct item *head; + struct item **tail; +}; + +static bool check_list_items(struct list *list, int *array, size_t size) { + struct item **cur = &list->head; + for (size_t i = 0; i < size; ++i) { + if (!bfs_check(*cur != NULL)) { + return false; + } + int n = (*cur)->n; + if (!bfs_check(n == array[i], "%d != %d", n, array[i])) { + return false; + } + cur = &(*cur)->next; + } + + if (!bfs_check(*cur == NULL)) { + return false; + } + if (!bfs_check(list->tail == cur)) { + return false; + } + + return true; +} + +#define ARRAY(...) (int[]){ __VA_ARGS__ }, countof((int[]){ __VA_ARGS__ }) +#define EMPTY() NULL, 0 + +bool check_list(void) { + struct list l1; + SLIST_INIT(&l1); + bfs_verify(check_list_items(&l1, EMPTY())); + + struct list l2; + SLIST_INIT(&l2); + bfs_verify(check_list_items(&l2, EMPTY())); + + SLIST_EXTEND(&l1, &l2); + bfs_verify(check_list_items(&l1, EMPTY())); + + struct item i10 = { .n = 10 }; + SLIST_APPEND(&l1, &i10); + bfs_verify(check_list_items(&l1, ARRAY(10))); + + SLIST_EXTEND(&l1, &l2); + bfs_verify(check_list_items(&l1, ARRAY(10))); + + SLIST_SPLICE(&l1, &l1.head, &l2); + bfs_verify(check_list_items(&l1, ARRAY(10))); + + struct item i20 = { .n = 20 }; + SLIST_PREPEND(&l2, &i20); + bfs_verify(check_list_items(&l2, ARRAY(20))); + + SLIST_EXTEND(&l1, &l2); + bfs_verify(check_list_items(&l1, ARRAY(10, 20))); + bfs_verify(check_list_items(&l2, EMPTY())); + + struct item i15 = { .n = 15 }; + SLIST_APPEND(&l2, &i15); + SLIST_SPLICE(&l1, &i10.next, &l2); + bfs_verify(check_list_items(&l1, ARRAY(10, 15, 20))); + bfs_verify(check_list_items(&l2, EMPTY())); + + SLIST_EXTEND(&l1, &l2); + bfs_verify(check_list_items(&l1, ARRAY(10, 15, 20))); + + SLIST_SPLICE(&l1, &i10.next, &l2); + bfs_verify(check_list_items(&l1, ARRAY(10, 15, 20))); + + SLIST_SPLICE(&l1, &l1.head, &l2); + bfs_verify(check_list_items(&l1, ARRAY(10, 15, 20))); + + struct item i11 = { .n = 11 }; + struct item i12 = { .n = 12 }; + SLIST_APPEND(&l2, &i11); + SLIST_APPEND(&l2, &i12); + SLIST_SPLICE(&l1, &l1.head->next, &l2); + bfs_verify(check_list_items(&l1, ARRAY(10, 11, 12, 15, 20))); + + return true; +} diff --git a/tests/main.c b/tests/main.c index aef0583..bef2e37 100644 --- a/tests/main.c +++ b/tests/main.c @@ -111,6 +111,7 @@ int main(int argc, char *argv[]) { run_test(&ctx, "bfstd", check_bfstd); run_test(&ctx, "bit", check_bit); run_test(&ctx, "ioq", check_ioq); + run_test(&ctx, "list", check_list); run_test(&ctx, "sighook", check_sighook); run_test(&ctx, "trie", check_trie); run_test(&ctx, "xspawn", check_xspawn); diff --git a/tests/posix/HL.out b/tests/posix/HL.out new file mode 100644 index 0000000..ec9e861 --- /dev/null +++ b/tests/posix/HL.out @@ -0,0 +1,17 @@ +links +links/broken +links/deeply +links/deeply/nested +links/deeply/nested/broken +links/deeply/nested/dir +links/deeply/nested/file +links/deeply/nested/link +links/file +links/hardlink +links/notdir +links/skip +links/skip/broken +links/skip/dir +links/skip/file +links/skip/link +links/symlink diff --git a/tests/posix/HL.sh b/tests/posix/HL.sh new file mode 100644 index 0000000..1858982 --- /dev/null +++ b/tests/posix/HL.sh @@ -0,0 +1 @@ +bfs_diff -HL links diff --git a/tests/posix/LH.out b/tests/posix/LH.out new file mode 100644 index 0000000..ff635ff --- /dev/null +++ b/tests/posix/LH.out @@ -0,0 +1 @@ +links/deeply/nested/dir diff --git a/tests/posix/LH.sh b/tests/posix/LH.sh new file mode 100644 index 0000000..ef1d980 --- /dev/null +++ b/tests/posix/LH.sh @@ -0,0 +1 @@ +bfs_diff -LH links/deeply/nested/dir diff --git a/tests/posix/depth_error.out b/tests/posix/depth_error.out index 7ed5f0d..c4f8ce4 100644 --- a/tests/posix/depth_error.out +++ b/tests/posix/depth_error.out @@ -1,2 +1,4 @@ -. -./foo +inaccessible +inaccessible/dir +inaccessible/file +inaccessible/link diff --git a/tests/posix/depth_error.sh b/tests/posix/depth_error.sh index db414ba..9b29385 100644 --- a/tests/posix/depth_error.sh +++ b/tests/posix/depth_error.sh @@ -1,7 +1 @@ -cd "$TEST" -"$XTOUCH" -p foo/bar - -chmod a-r foo -defer chmod +r foo - -! bfs_diff . -depth +! bfs_diff inaccessible -depth diff --git a/tests/posix/perm_000.out b/tests/posix/perm_000.out index 5fd30bc..b46af62 100644 --- a/tests/posix/perm_000.out +++ b/tests/posix/perm_000.out @@ -1 +1 @@ -perms/0 +perms/f--- diff --git a/tests/posix/perm_000_minus.out b/tests/posix/perm_000_minus.out index d7494b8..42f2fed 100644 --- a/tests/posix/perm_000_minus.out +++ b/tests/posix/perm_000_minus.out @@ -1,8 +1,10 @@ perms -perms/0 -perms/r -perms/rw -perms/rwx -perms/rx -perms/w -perms/wx +perms/dr-x +perms/drwx +perms/f--- +perms/f-w- +perms/f-wx +perms/fr-- +perms/fr-x +perms/frw- +perms/frwx diff --git a/tests/posix/perm_222.out b/tests/posix/perm_222.out index 1690e43..4876193 100644 --- a/tests/posix/perm_222.out +++ b/tests/posix/perm_222.out @@ -1 +1 @@ -perms/w +perms/f-w- diff --git a/tests/posix/perm_222_minus.out b/tests/posix/perm_222_minus.out index 1690e43..4876193 100644 --- a/tests/posix/perm_222_minus.out +++ b/tests/posix/perm_222_minus.out @@ -1 +1 @@ -perms/w +perms/f-w- diff --git a/tests/posix/perm_644.out b/tests/posix/perm_644.out index 4e64e49..4598cc1 100644 --- a/tests/posix/perm_644.out +++ b/tests/posix/perm_644.out @@ -1 +1 @@ -perms/rw +perms/frw- diff --git a/tests/posix/perm_644_minus.out b/tests/posix/perm_644_minus.out index 2e2576b..9e041c3 100644 --- a/tests/posix/perm_644_minus.out +++ b/tests/posix/perm_644_minus.out @@ -1,3 +1,4 @@ perms -perms/rw -perms/rwx +perms/drwx +perms/frw- +perms/frwx diff --git a/tests/posix/perm_symbolic_minus.out b/tests/posix/perm_symbolic_minus.out index 2e2576b..9e041c3 100644 --- a/tests/posix/perm_symbolic_minus.out +++ b/tests/posix/perm_symbolic_minus.out @@ -1,3 +1,4 @@ perms -perms/rw -perms/rwx +perms/drwx +perms/frw- +perms/frwx diff --git a/tests/posix/permcopy.out b/tests/posix/permcopy.out index 4e64e49..4598cc1 100644 --- a/tests/posix/permcopy.out +++ b/tests/posix/permcopy.out @@ -1 +1 @@ -perms/rw +perms/frw- diff --git a/tests/posix/prune_error.out b/tests/posix/prune_error.out new file mode 100644 index 0000000..436c48e --- /dev/null +++ b/tests/posix/prune_error.out @@ -0,0 +1 @@ +inaccessible diff --git a/tests/posix/prune_error.sh b/tests/posix/prune_error.sh new file mode 100644 index 0000000..07a2523 --- /dev/null +++ b/tests/posix/prune_error.sh @@ -0,0 +1 @@ +! bfs_diff -L inaccessible -path '*/*' -prune -o -print diff --git a/tests/run.sh b/tests/run.sh index ad9c0be..115a036 100644 --- a/tests/run.sh +++ b/tests/run.sh @@ -5,23 +5,6 @@ ## Running test cases -# Beginning/end of line escape sequences -BOL=$'\n' -EOL=$'\n' - -# Update $EOL for the terminal size -update_eol() { - # Bash gets $COLUMNS from stderr, so if it's redirected use tput instead - local cols="${COLUMNS-}" - if [ -z "$cols" ]; then - cols=$(tput cols 2>/dev/tty) - fi - - # Put the cursor at the last column, then write a space so the next - # character will wrap - EOL=$'\e['"${cols}G " -} - # ERR trap for tests debug_err() { local ret=$? line func file @@ -64,19 +47,19 @@ run_test() { case $ret in 0) if ((VERBOSE_TESTS)); then - color printf "${BOL}${GRN}[PASS]${RST} ${BLD}%s${RST}\n" "$TEST" + color printf "${GRN}[PASS]${RST} ${BLD}%s${RST}\n" "$TEST" fi ;; $EX_SKIP) if ((VERBOSE_SKIPPED || VERBOSE_TESTS)); then - color printf "${BOL}${CYN}[SKIP]${RST} ${BLD}%s${RST}\n" "$TEST" + color printf "${CYN}[SKIP]${RST} ${BLD}%s${RST}\n" "$TEST" fi ;; *) if ((!VERBOSE_ERRORS)); then cat "$TMP/$TEST.err" >&2 fi - color printf "${BOL}${RED}[FAIL]${RST} ${BLD}%s${RST}\n" "$TEST" + color printf "${RED}[FAIL]${RST} ${BLD}%s${RST}\n" "$TEST" ;; esac @@ -112,12 +95,21 @@ reap_test() { # Wait for a background test to finish wait_test() { local pid - wait -n -ppid - ret=$? - if [ -z "${pid:-}" ]; then - debug "${BASH_SOURCE[0]}" $((LINENO - 3)) "${RED}error $ret${RST}" >&$DUPERR - exit 1 - fi + + while true; do + wait -n -ppid + ret=$? + + if [ "${pid:-}" ]; then + break + elif ((ret > 128)); then + # Interrupted by signal + continue + else + debug "${BASH_SOURCE[0]}" $((LINENO - 3)) "${RED}error $ret${RST}" >&$DUPERR + exit 1 + fi + done reap_test $ret } @@ -164,35 +156,24 @@ comake() { exec {READY_PIPE}<&${COPROC[0]} {DONE_PIPE}>&${COPROC[1]} } -# Run all the tests -run_tests() { - if ((VERBOSE_TESTS)); then - BOL='' - elif ((COLOR_STDOUT)); then - # Carriage return + clear line - BOL=$'\r\e[K' - - # Workaround for bash 4: checkwinsize is off by default. We can turn it - # on, but we also have to explicitly trigger a foreground job to finish - # so that it will update the window size before we use $COLUMNS - shopt -s checkwinsize - (:) - - update_eol - trap update_eol WINCH +# Print the current test progess +progress() { + if [ "${BAR:-}" ]; then + print_bar "$(printf "$@")" + elif ((VERBOSE_TESTS)); then + color printf "$@" fi +} +# Run all the tests +run_tests() { passed=0 failed=0 skipped=0 ran=0 total=${#TEST_CASES[@]} - if ((COLOR_STDOUT || VERBOSE_TESTS)); then - TEST_FMT="${BOL}${YLW}[%3d%%]${RST} ${BLD}%s${RST}${EOL}" - else - TEST_FMT="." - fi + TEST_FMT="${YLW}[%3d%%]${RST} ${BLD}%s${RST}\\n" if ((${#MAKE[@]})); then comake @@ -201,6 +182,10 @@ run_tests() { # Turn off set -e (but turn it back on in run_test) set +e + if ((COLOR_STDOUT && !VERBOSE_TESTS)); then + show_bar + fi + for TEST in "${TEST_CASES[@]}"; do wait_ready if ((STOP && failed > 0)); then @@ -208,7 +193,7 @@ run_tests() { fi percent=$((100 * ran / total)) - color printf "$TEST_FMT" $percent "$TEST" + progress "${YLW}[%3d%%]${RST} ${BLD}%s${RST}\\n" $percent "$TEST" mkdir -p "$TMP/$TEST" OUT="$TMP/$TEST.out" @@ -221,7 +206,9 @@ run_tests() { wait_test done - printf "${BOL}" + if [ "${BAR:-}" ]; then + hide_bar + fi if ((passed > 0)); then color printf "${GRN}[PASS]${RST} ${BLD}%3d${RST} / ${BLD}%d${RST}\n" $passed $total @@ -253,7 +240,6 @@ skip() { if ((VERBOSE_SKIPPED)); then caller | { read -r line file - printf "${BOL}" debug "$file" $line "" >&$DUPOUT } fi @@ -424,14 +410,20 @@ make_xattrs() { esac } +# Get the Unix epoch time in seconds +epoch_time() { + # https://stackoverflow.com/a/12746260/502399 + awk 'BEGIN { srand(); print srand(); }' +} + ## Snapshot testing # Return value when a difference is detected EX_DIFF=20 # Detect colored diff support -if diff --color /dev/null /dev/null &>/dev/null; then - DIFF="diff --color" +if ((COLOR_STDERR)) && diff --color=always /dev/null /dev/null &>/dev/null; then + DIFF="diff --color=always" else DIFF="diff" fi diff --git a/tests/stddirs.sh b/tests/stddirs.sh index e08e6bf..b3cd521 100644 --- a/tests/stddirs.sh +++ b/tests/stddirs.sh @@ -14,13 +14,13 @@ make_basic() { # Creates a file+directory structure with various permissions for tests make_perms() { - "$XTOUCH" -p -M000 "$1/0" - "$XTOUCH" -p -M444 "$1/r" - "$XTOUCH" -p -M222 "$1/w" - "$XTOUCH" -p -M644 "$1/rw" - "$XTOUCH" -p -M555 "$1/rx" - "$XTOUCH" -p -M311 "$1/wx" - "$XTOUCH" -p -M755 "$1/rwx" + "$XTOUCH" -p -M000 "$1/f---" + "$XTOUCH" -p -M444 "$1/fr--" + "$XTOUCH" -p -M222 "$1/f-w-" + "$XTOUCH" -p -M644 "$1/frw-" + "$XTOUCH" -p -M311 "$1/f-wx" + "$XTOUCH" -p -M555 "$1/fr-x" "$1/dr-x/" + "$XTOUCH" -p -M755 "$1/frwx" "$1/drwx/" } # Creates a file+directory structure with various symbolic and hard links @@ -48,6 +48,12 @@ make_loops() { ln -s deeply/nested/loop/nested "$1/skip" } +# Creates a file+directory structure with inaccessible files +make_inaccessible() { + "$XTOUCH" -p -M000 "$1/file" "$1/dir/" + ln -s dir/file "$1/link" +} + # Creates a file+directory structure with varying timestamps make_times() { "$XTOUCH" -p -t "1991-12-14 00:00" "$1/a" @@ -71,6 +77,9 @@ make_weirdnames() { "$XTOUCH" -p "$1/\\/i" "$XTOUCH" -p "$1/ /j" "$XTOUCH" -p "$1/[/k" + "$XTOUCH" -p "$1/{/l" + "$XTOUCH" -p "$1/*/m" + "$XTOUCH" -p "$1/"$'\n/n' } # Creates a very deep directory structure for testing PATH_MAX handling @@ -133,6 +142,7 @@ make_stddirs() { make_perms "$TMP/perms" make_links "$TMP/links" make_loops "$TMP/loops" + make_inaccessible "$TMP/inaccessible" make_times "$TMP/times" make_weirdnames "$TMP/weirdnames" make_deep "$TMP/deep" @@ -148,5 +158,6 @@ clean_stddirs() { fi done + chmod -R +rwX "$TMP" rm -rf "$TMP" } diff --git a/tests/tests.h b/tests/tests.h index 19b7f5e..2958fe1 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -9,6 +9,7 @@ #define BFS_TESTS_H #include "prelude.h" +#include "bfstd.h" #include "diag.h" /** Unit test function type. */ @@ -26,6 +27,9 @@ bool check_bit(void); /** I/O queue tests. */ bool check_ioq(void); +/** Linked list tests. */ +bool check_list(void); + /** Signal hook tests. */ bool check_sighook(void); @@ -61,7 +65,7 @@ static inline bool bfs_check(bool ret) { * Check a condition, logging the current error string on failure. */ #define bfs_echeck(...) \ - bfs_echeck_(#__VA_ARGS__, __VA_ARGS__, "", bfs_errstr()) + bfs_echeck_(#__VA_ARGS__, __VA_ARGS__, "", errstr()) #define bfs_echeck_(str, cond, format, ...) \ ((cond) ? true : (bfs_diag( \ diff --git a/tests/trie.c b/tests/trie.c index 4667322..ebaae5d 100644 --- a/tests/trie.c +++ b/tests/trie.c @@ -8,7 +8,7 @@ #include <stdlib.h> #include <string.h> -const char *keys[] = { +static const char *keys[] = { "foo", "bar", "baz", @@ -37,7 +37,7 @@ const char *keys[] = { ">>>", }; -const size_t nkeys = countof(keys); +static const size_t nkeys = countof(keys); bool check_trie(void) { bool ret = true; diff --git a/tests/util.sh b/tests/util.sh index 3969db5..76b72b9 100644 --- a/tests/util.sh +++ b/tests/util.sh @@ -59,6 +59,15 @@ stdenv() { # Close stdin so bfs doesn't think we're interactive # dup() the standard fds for logging even when redirected exec </dev/null {DUPOUT}>&1 {DUPERR}>&2 + + # Get the ttyname + if [ -t $DUPOUT ]; then + TTY=$(tty <&$DUPOUT) + elif [ -t $DUPERR ]; then + TTY=$(tty <&$DUPERR) + else + TTY= + fi } # Drop root priviliges or bail diff --git a/tests/xspawn.c b/tests/xspawn.c index b1d6dc1..f48e220 100644 --- a/tests/xspawn.c +++ b/tests/xspawn.c @@ -179,6 +179,8 @@ static bool check_resolve(void) { ret &= bfs_echeck(!bfs_spawn_resolve("eW6f5RM9Qi") && errno == ENOENT); + ret &= bfs_echeck(!bfs_spawn_resolve("bin/eW6f5RM9Qi") && errno == ENOENT); + return ret; } |