fix some portability issues in the unit tests for running on Linux
authorTed Mielczarek <ted.mielczarek@gmail.com>
Mon, 08 Mar 2010 10:09:07 -0500
changeset 359114 a7b5e2775e7f32be8d70d595d205315e7a2ad1c8
parent 359113 47983a19bd7c52d50bc6971ea8716f6466521e3e
child 359115 fb903fdfa8b14423d99910603af47f6744cd74b8
push id16998
push userrwood@mozilla.com
push dateMon, 02 May 2016 19:42:03 +0000
fix some portability issues in the unit tests for running on Linux
hghooks/test-hook.sh
hghooks/test-lots-of-checkins.sh
hghooks/test-merges.sh
--- a/hghooks/test-hook.sh
+++ b/hghooks/test-hook.sh
@@ -1,10 +1,11 @@
-#!/bin/sh
+#!/bin/bash
 # This script tests the pushlog hook. I've only run it on OS X, so be warned.
+#TODO: port this + the other test scripts to Python using unittest
 
 export PYTHONPATH=`dirname $0`
 
 REPO=/tmp/hg-test
 CLONE=${REPO}-clone
 # cleanup any existing stuff
 rm -rf $REPO $CLONE
 
@@ -62,21 +63,33 @@ echo "SELECT node from changesets LEFT J
 
 if diff /tmp/hg-log-output /tmp/pushlog-output >/dev/null; then
     echo "PASS: recorded all changesets";
 else
     echo "FAIL: hg log and pushlog changesets differ!";
     exit 1;
 fi
 
-if [[ `stat -f %Sp $REPO/.hg/pushlog2.db | sed -e "s/^....\(..\).*$/\1/"` != "rw" ]]; then
-    echo "FAIL: pushlog db is not group writeable!"
-    exit 1;
-else
-    echo "PASS: pushlog db is group writeable!"
+# crummy non-portable stat stuff
+case `uname` in
+  Linux):
+        STATARGS='--format=%A'
+        ;;
+  Darwin):
+        STATARGS='-f %Sp'
+        ;;
+esac
+
+if test -n "$STATARGS"; then
+    if [[ `stat $STATARGS $REPO/.hg/pushlog2.db | sed -e "s/^....\(..\).*$/\1/"` != "rw" ]]; then
+        echo "FAIL: pushlog db is not group writeable!"
+        exit 1;
+    else
+        echo "PASS: pushlog db is group writeable!"
+    fi
 fi
 
 # Test that an empty db file doesn't break the hook - bug 466149
 rm $REPO/.hg/pushlog2.db
 touch $REPO/.hg/pushlog2.db
 
 echo "another checkin" >> $CLONE/testfile
 hg ci -R $CLONE -m "another checkin"
--- a/hghooks/test-lots-of-checkins.sh
+++ b/hghooks/test-lots-of-checkins.sh
@@ -1,9 +1,9 @@
-#!/bin/sh
+#!/bin/bash
 # This script tests the pushlog hook. I've only run it on OS X, so be warned.
 # This is mostly just to generate a repo for testing the pushlog web output.
 
 export PYTHONPATH=`dirname $0`
 
 REPO=/tmp/hg-test
 CLONE=${REPO}-clone
 # cleanup any existing stuff
@@ -23,21 +23,24 @@ EOF
 hg clone $REPO $CLONE
 
 # push lots of changes
 echo "checkin 1" > $CLONE/testfile
 hg add -R $CLONE $CLONE/testfile
 hg ci -R $CLONE -m "checkin 1"
 hg push -R $CLONE $REPO;
 
+printf "Adding changes"
 for ((i=2; $i<=200; i++)); do
   echo "checkin $i" >> $CLONE/testfile;
-  hg ci -R $CLONE -m "checkin $i";
-  hg push -R $CLONE $REPO;
+  hg ci -R $CLONE -m "checkin $i" >/dev/null;
+  hg push -R $CLONE $REPO >/dev/null;
+  printf "."
 done
+echo "Done"
 
 # Test total push count
 EXPECTED_PUSHCOUNT=200
 PUSHCOUNT=`echo "SELECT COUNT(*) FROM pushlog;" | sqlite3 $REPO/.hg/pushlog2.db`
 if [[ "$PUSHCOUNT" != "$EXPECTED_PUSHCOUNT" ]]; then
     echo "FAIL: push count $PUSHCOUNT != $EXPECTED_PUSHCOUNT";
     exit 1;
 else
--- a/hghooks/test-merges.sh
+++ b/hghooks/test-merges.sh
@@ -1,9 +1,9 @@
-#!/bin/sh
+#!/bin/bash
 # This script tests the pushlog hook. I've only run it on OS X, so be warned.
 
 export PYTHONPATH=`dirname $0`
 
 REPO=/tmp/hg-test
 CLONE=${REPO}-clone
 BRANCH=${REPO}-branch
 # cleanup any existing stuff