Browse Source

refactor visual_regression: change tmp folder from current to diff, clarify folders and state execution folder doesn't matter

part of #676
sschmid 5 năm trước cách đây
mục cha
commit
e71795b0c7
1 tập tin đã thay đổi với 23 bổ sung23 xóa
  1. 23 23
      test/Util/visual_regression.sh

+ 23 - 23
test/Util/visual_regression.sh

@@ -43,17 +43,18 @@
 # a good first pass.
 # a good first pass.
 THRESHOLD=0.01
 THRESHOLD=0.01
 
 
-# Directories. You might want to change BASE, if you're running from a
-# different working directory. (only necessary if you're running the script manually, i.e. not from npm run test:visual)
-if [ "$1" == "" ]
+# Set up Directories
+#   It does not matter where this script is executed, as long as these folders are given correctly (and blessed/current have png images set up correctly)
+BUILDFOLDER=./visual_regression
+if [ "$1" != "" ]
 then
 then
-  BASEFOLDER="./visual_regression"
-else
-  BASEFOLDER=$1
+  BUILDFOLDER=$1
 fi
 fi
-BLESSED=$BASEFOLDER/blessed
-CURRENT=$BASEFOLDER/current
-DIFF=$BASEFOLDER/diff
+BLESSED=$BUILDFOLDER/blessed
+CURRENT=$BUILDFOLDER/current
+DIFF=$BUILDFOLDER/diff
+# diff also acts as the temp folder here, unlike in Vexflow, where it is current.
+# it would be nice to have a tmp folder (for temporary files), but we'd want to delete the folder entirely, and we'd better not risk using rm -rf in a script
 
 
 # All results are stored here.
 # All results are stored here.
 RESULTS=$DIFF/results.txt
 RESULTS=$DIFF/results.txt
@@ -69,8 +70,7 @@ else
 fi
 fi
 
 
 # some sanity checks: check if some png images are in the right folder and warn if not. doesn't make sure there are actual, correct png images though.
 # some sanity checks: check if some png images are in the right folder and warn if not. doesn't make sure there are actual, correct png images though.
-folderWarningStringMsg="Also, please run this npm script from the base OSMD folder. (npm run test:visual should do this automatically)
-    Exiting without running visual regression tests.\n"
+folderWarningStringMsg="Exiting without running visual regression tests.\n"
 # check if current directory exists / started from base OSMD folder
 # check if current directory exists / started from base OSMD folder
 if [ ! -e "$CURRENT" ]
 if [ ! -e "$CURRENT" ]
 then
 then
@@ -116,8 +116,8 @@ then
   rm $DIFF/*
   rm $DIFF/*
 fi
 fi
 touch $RESULTS
 touch $RESULTS
-touch $RESULTS.pass
-touch $RESULTS.fail
+touch $RESULTS.fails
+#   this shouldn't be named .fail because we have a *.fail shell match further below, which will loop endlessly if files are in the same folder (diff).
 touch $WARNINGS
 touch $WARNINGS
 
 
 # Number of simultaneous jobs
 # Number of simultaneous jobs
@@ -145,7 +145,7 @@ function diff_image() {
   local name=`basename $image .png`
   local name=`basename $image .png`
   local blessed=$BLESSED/$name.png
   local blessed=$BLESSED/$name.png
   local current=$CURRENT/$name.png
   local current=$CURRENT/$name.png
-  local diff=$current-temp
+  local diff=$DIFF/$name.png-temp
 
 
   if [ ! -e "$current" ]
   if [ ! -e "$current" ]
   then
   then
@@ -167,7 +167,7 @@ function diff_image() {
   local isGT=`echo "$hash > $THRESHOLD" | bc -l`
   local isGT=`echo "$hash > $THRESHOLD" | bc -l`
   if [ "$isGT" == "1" ]
   if [ "$isGT" == "1" ]
   then
   then
-    # Add the result to results.text
+    # Add the result to results.txt
     echo $name $hash >$diff.fail
     echo $name $hash >$diff.fail
     # Threshold exceeded, save the diff and the original, current
     # Threshold exceeded, save the diff and the original, current
     cp $diff-diff.png $DIFF/$name.png
     cp $diff-diff.png $DIFF/$name.png
@@ -207,8 +207,8 @@ do
 done
 done
 wait
 wait
 
 
-cat $CURRENT/*.warn 1>$WARNINGS 2>/dev/null
-rm -f $CURRENT/*.warn
+cat $DIFF/*.warn 1>$WARNINGS 2>/dev/null
+rm -f $DIFF/*.warn
 
 
 ## Check for files newly built that are not yet blessed.
 ## Check for files newly built that are not yet blessed.
 for image in $CURRENT/$files
 for image in $CURRENT/$files
@@ -225,14 +225,14 @@ done
 
 
 num_warnings=`cat $WARNINGS | wc -l`
 num_warnings=`cat $WARNINGS | wc -l`
 
 
-cat $CURRENT/*.fail 1>$RESULTS.fail 2>/dev/null
-num_fails=`cat $RESULTS.fail | wc -l`
-rm -f  $CURRENT/*.fail
+cat $DIFF/*.fail 1>$RESULTS.fails 2>/dev/null
+num_fails=`cat $RESULTS.fails | wc -l`
+rm -f  $DIFF/*.fail
 
 
 # Sort results by PHASH
 # Sort results by PHASH
-sort -r -n -k 2 $RESULTS.fail >$RESULTS
-sort -r -n -k 2 $CURRENT/*.pass 1>>$RESULTS 2>/dev/null
-rm -f $CURRENT/*.pass $RESULTS.fail $RESULTS.pass
+sort -r -n -k 2 $RESULTS.fails >$RESULTS
+sort -r -n -k 2 $DIFF/*.pass 1>>$RESULTS 2>/dev/null
+rm -f $DIFF/*.pass $RESULTS.fails
 
 
 echo
 echo
 echo Results stored in $DIFF/results.txt
 echo Results stored in $DIFF/results.txt