Browse Source

visual_regression: add some sanity checks and warnings (check files exist), change folder from data/images to visual_regression

sschmid 5 năm trước cách đây
mục cha
commit
cad0c84250
3 tập tin đã thay đổi với 52 bổ sung16 xóa
  1. 1 1
      .gitignore
  2. 2 2
      package.json
  3. 49 13
      test/Util/visual_regression.sh

+ 1 - 1
.gitignore

@@ -15,7 +15,7 @@ pids
 *.seed
 
 # optional npm script-generated data
-data/images/
+visual_regression/
 export/
 
 # Documentation

+ 2 - 2
package.json

@@ -19,8 +19,8 @@
     "build:webpack-sourcemap": "webpack --progress --colors --config webpack.sourcemap.js",
     "start": "webpack-dev-server --progress --colors --config webpack.dev.js",
     "generatePNG": "node ./test/Util/generateDiffImagesPuppeteerLocalhost.js ./test/data/ ./export/",
-    "generate:current": "node ./test/Util/generateDiffImagesPuppeteerLocalhost.js ./test/data/ ./data/images/current",
-    "generate:blessed": "node ./test/Util/generateDiffImagesPuppeteerLocalhost.js ./test/data/ ./data/images/blessed",
+    "generate:current": "node ./test/Util/generateDiffImagesPuppeteerLocalhost.js ./test/data/ ./visual_regression/current",
+    "generate:blessed": "node ./test/Util/generateDiffImagesPuppeteerLocalhost.js ./test/data/ ./visual_regression/blessed",
     "test:visual": "sh ./test/Util/visual_regression.sh",
     "fix-memory-limit": "cross-env NODE_OPTIONS=--max_old_space_size=4096"
   },

+ 49 - 13
test/Util/visual_regression.sh

@@ -43,7 +43,7 @@ THRESHOLD=0.01
 # Directories. You might want to change BASE, if you're running from a
 # different working directory.
 BASE=.
-IMAGESPARENTFOLDER=$BASE/data/images
+IMAGESPARENTFOLDER=$BASE/visual_regression
 BLESSED=$IMAGESPARENTFOLDER/blessed
 CURRENT=$IMAGESPARENTFOLDER/current
 DIFF=$IMAGESPARENTFOLDER/diff
@@ -52,16 +52,6 @@ DIFF=$IMAGESPARENTFOLDER/diff
 RESULTS=$DIFF/results.txt
 WARNINGS=$DIFF/warnings.txt
 
-mkdir -p $DIFF
-if [ -e "$RESULTS" ]
-then
-  rm $DIFF/*
-fi
-touch $RESULTS
-touch $RESULTS.pass
-touch $RESULTS.fail
-touch $WARNINGS
-
 # If no prefix is provided, test all images.
 if [ "$1" == "" ]
 then
@@ -70,11 +60,57 @@ else
   files=$1*.png
 fi
 
-if [ "`basename $PWD`" == "Util" ]
+# 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"
+# check if current directory exists / started from base OSMD folder
+if [ ! -e "$CURRENT" ]
+then
+  printf "Warning: directory ${CURRENT} missing. Please run npm run generate:current (and if necessary npm run generate:blessed) first.
+    ${folderWarningStringMsg}"
+  exit 1
+fi
+# check if blessed directory exists / started from base OSMD folder
+if [ ! -e "$BLESSED" ]
+then
+  printf "Warning: directory ${BLESSED} missing. Please run npm run generate:blessed first (or otherwise get the blessed images).
+    ${folderWarningStringMsg}"
+  exit 1
+fi
+# note: ls returns errors if the directory doesn't exist
+totalCurrentImages=`ls -l $CURRENT/*.png | wc -l | sed 's/[[:space:]]//g'`
+totalBlessedImages=`ls -l $BLESSED/*.png | wc -l | sed 's/[[:space:]]//g'`
+# check if there are some current images
+if [ "$totalCurrentImages" -lt 1 ]
 then
-  echo Please run this script from the OSMD base directory.
+  printf "Warning: Found no pngs in ${CURRENT}. Please run npm run generate (and if necessary npm run blessed) first.
+    ${folderWarningStringMsg}"
   exit 1
 fi
+# check if there are some blessed images
+if [ "$totalBlessedImages" -lt 1 ]
+then
+  printf "Warning: Found no pngs in ${BLESSED}. Please run npm run blessed first, ideally on the repository's develop state.
+    ${folderWarningStringMsg}"
+  exit 1
+fi
+# check that #currentImages == #blessedImages (will continue anyways)
+if [ ! "$totalCurrentImages" -eq "$totalBlessedImages" ]
+then
+  printf "Warning: Number of current images (${totalCurrentImages}) is not the same as blessed images (${totalBlessedImages}). Continuing anyways.\n"
+else
+  printf "Found ${totalCurrentImages} current and ${totalBlessedImages} blessed images. Continuing.\n"
+fi
+
+mkdir -p $DIFF
+if [ -e "$RESULTS" ]
+then
+  rm $DIFF/*
+fi
+touch $RESULTS
+touch $RESULTS.pass
+touch $RESULTS.fail
+touch $WARNINGS
 
 # Number of simultaneous jobs
 nproc=$(sysctl -n hw.physicalcpu 2> /dev/null || nproc)