Revision: 74298
          http://sourceforge.net/p/brlcad/code/74298
Author:   brlcad
Date:     2019-11-05 22:27:57 +0000 (Tue, 05 Nov 2019)
Log Message:
-----------
document the two file comparison functions, define behavior and add additional 
tests to make sure the filename args are as expected.

Modified Paths:
--------------
    brlcad/trunk/regress/library.sh

Modified: brlcad/trunk/regress/library.sh
===================================================================
--- brlcad/trunk/regress/library.sh     2019-11-05 20:47:22 UTC (rev 74297)
+++ brlcad/trunk/regress/library.sh     2019-11-05 22:27:57 UTC (rev 74298)
@@ -107,46 +107,85 @@
 }
 
 
+###
+# should_be_different file1 file2
+#
+# comparison function returns success (zero) if the two specified
+# files differ or either doesn't exist, error otherwise.  Increments
+# STATUS global.
 should_be_different ( ) {
     if test $# -ne 2 ; then
        log "INTERNAL ERROR: should_be_different has wrong arg count ($# -ne 2)"
        exit 1
     fi
-    if test "x$1" = "x" ; then
-       log "INTERNAL ERROR: should_be_different has empty file #1"
+    if test "x$2" = "x" ; then
+       log "INTERNAL ERROR: should_be_different is missing filename #2"
        exit 1
     fi
-    if test "x$2" = "x" ; then
-       log "INTERNAL ERROR: should_be_different has empty file #2"
+    if test "x$1" = "x" ; then
+       log "INTERNAL ERROR: should_be_different is missing filename #1"
        exit 1
     fi
-    if test "x`diff $1 $2`" = "x" ; then
+
+    ret=0
+    if test ! -f "$2" ; then
+       log "ERROR: $2 does not exist"
+       ret=1
+    elif test ! -f "$1" ; then
+       log "ERROR: $1 does not exist"
+       ret=1
+    elif test "x`diff $1 $2`" = "x" ; then
        log "ERROR: comparison failed  ($1 and $2 are identical, expected 
change)"
+       ret=1
+    fi
+
+    if test $ret -ne 0 ; then
        STATUS="`expr $STATUS + 1`"
        export STATUS
     fi
+    return $ret
 }
 
 
+###
+# should_be_same file1 file2
+#
+# comparison function returns true if two specified files both exist
+# and are the same, false otherwise.  Increments STATUS global.
 should_be_same ( ) {
     if test $# -ne 2 ; then
        log "INTERNAL ERROR: should_be_same has wrong arg count ($# -ne 2)"
        exit 1
     fi
-    if test "x$1" = "x" ; then
-       log "INTERNAL ERROR: should_be_same has empty file #1"
+    if test "x$2" = "x" ; then
+       log "INTERNAL ERROR: should_be_same is missing filename #2"
        exit 1
     fi
-    if test "x$2" = "x" ; then
-       log "INTERNAL ERROR: should_be_same has empty file #2"
+    if test "x$1" = "x" ; then
+       log "INTERNAL ERROR: should_be_same is missing filename #1"
        exit 1
     fi
-    if test "x`diff $1 $2`" != "x" ; then
+
+    ret=0
+    if test ! -f "$2" ; then
+       log "ERROR: $2 does not exist"
+       ret=1
+    elif test ! -f "$1" ; then
+       log "ERROR: $1 does not exist"
+       ret=1
+    elif test "x`diff $1 $2`" != "x" ; then
        log "ERROR: comparison failed  ($1 and $2 are different, expected no 
change)"
+       # display diff in the log
+       log "Differences:"
        run diff -u $1 $2
+       ret=1
+    fi
+
+    if test $ret -ne 0 ; then
        STATUS="`expr $STATUS + 1`"
        export STATUS
     fi
+    return $ret
 }
 
 

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to