Skip to contentSkip to conversation

Attempt to auto-detect stat(1) being used if not given proper invocation

PATCH In review [email protected] 2 participants 2 messages Jan 3, 2018 – Jan 4, 2018 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Attempt to auto-detect stat(1) being used if not given proper invocation

GNU stat(1) uses '-c "%s"' as the proper invocation to print filesize of the file in question, while BSD stat(1) uses '-f "%Uz"'. Do some trivial autodetection to check if we're using GNU stat(1) and assume we're using BSD stat(1) if we don't detect otherwise.

This should allow the test suite to run properly out-of-the-box on *BSDs and MacOS in addition to the current Linux support.

---

I should also note here that I've not tested this on Linux, given that I don't really have any Linux boxes, but I don't see any reason why it wouldn't work.

 tests/run_tests.sh | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tests/run_tests.sh +8 -1
index 3fa7c0a..0d30edf 100755
@@ -8,7 +8,14 @@ fi
 
 # stat differs between platforms
 if [ -z "$STATSZ" ]; then
-	STATSZ="stat -c %s"
+	stat --version 2>/dev/null | grep -q 'GNU'
+	GNUSTAT=$?
+	if [ "$GNUSTAT" -ne 0 ]; then
+		# Assume BSD stat if we can't detect as GNU stat
+		STATSZ="stat -f %Uz"
+	else
+		STATSZ="stat -c %s"
+	fi
 fi
 
 export QUIET_TEST=1
Signature · 1 line
2.15.1

A message that is not in the archive (sent off-list or not yet received): 20180103163444.68928-1-kevans-HZy0K5TPuP5AfugRpC6u6w@public.gmane.org

#2 lore raw
Quoted 8 lines · On Wed, Jan 03, 2018 at 10:34:44AM -0600…

GNU stat(1) uses '-c "%s"' as the proper invocation to print filesize of the file in question, while BSD stat(1) uses '-f "%Uz"'. Do some trivial autodetection to check if we're using GNU stat(1) and assume we're using BSD stat(1) if we don't detect otherwise.

This should allow the test suite to run properly out-of-the-box on *BSDs and MacOS in addition to the current Linux support.

Quoted 6 lines

---

I should also note here that I've not tested this on Linux, given that I don't really have any Linux boxes, but I don't see any reason why it wouldn't work.

Works for me, applied.

Quoted 24 lines
 tests/run_tests.sh | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tests/run_tests.sh +8 -1
index 3fa7c0a..0d30edf 100755
@@ -8,7 +8,14 @@ fi
 
 # stat differs between platforms
 if [ -z "$STATSZ" ]; then
-	STATSZ="stat -c %s"
+	stat --version 2>/dev/null | grep -q 'GNU'
+	GNUSTAT=$?
+	if [ "$GNUSTAT" -ne 0 ]; then
+		# Assume BSD stat if we can't detect as GNU stat
+		STATSZ="stat -f %Uz"
+	else
+		STATSZ="stat -c %s"
+	fi
 fi
 
 export QUIET_TEST=1
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson