From e1d46eb3da4cc6d04c93b4f4c1485a64887ac190 Mon Sep 17 00:00:00 2001
From: Tavian Barnes <tavianator@tavianator.com>
Date: Fri, 7 Feb 2025 12:16:52 -0500
Subject: tests: Use $EPOCHSECONDS if it exists

Bash 5 adds that special variable, which should be more reliable than
the awk trick, which is known to be broken on mawk.

Fixes: https://github.com/tavianator/bfs/issues/152
---
 tests/run.sh | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

(limited to 'tests')

diff --git a/tests/run.sh b/tests/run.sh
index 164790e..e3a4e3f 100644
--- a/tests/run.sh
+++ b/tests/run.sh
@@ -415,8 +415,13 @@ make_xattrs() {
 
 # Get the Unix epoch time in seconds
 epoch_time() {
-    # https://stackoverflow.com/a/12746260/502399
-    awk 'BEGIN { srand(); print srand(); }'
+    if [ "${EPOCHSECONDS:-}" ]; then
+        # Added in bash 5
+        printf '%d' "$EPOCHSECONDS"
+    else
+        # https://stackoverflow.com/a/12746260/502399
+        awk 'BEGIN { srand(); print srand(); }'
+    fi
 }
 
 ## Snapshot testing
-- 
cgit v1.2.3