#!/bin/bash
# Gate 24, part 2 (Pillow checker): the published checker on test files, edge inputs and every fixed file.
# Usage: bash cmds-mac.sh   (run from the folder holding in/ and fix2/)
LOG=commands-checker.log; : > $LOG
run() { # label file
  echo "published: python3 check-cover.py cover.png" >> $LOG
  out=$(/opt/homebrew/bin/python3.10 check-cover.py "$2" 2>&1); ec=$?
  echo "run on $2:" >> $LOG; echo "$out" | sed 's/^/  /' >> $LOG; echo "exit=$ec" >> $LOG; echo "edge: $1" >> $LOG; echo >> $LOG
}
run "test file, passes every rule" in/01-ok-3000.png
run "lower bound 1400 JPEG" in/02-ok-1400.jpg
run "one pixel under the range" in/03-small-1399.jpg
run "one pixel over the range" in/04-large-3001.png
run "not square" in/05-nonsquare-3000x2800.png
run "CMYK JPEG" in/06-cmyk-3000.jpg
run "PNG with transparent corners" in/07-alpha-corners-3000.png
run "alpha channel present but every pixel opaque" in/07b-alpha-opaque-3000.png
run "WebP" in/08-webp-3000.webp
run "PNG saved under a .jpg name" in/09-png-renamed-3000.jpg
run "large file, passes every rule" in/10-heavy-3000.jpg
run "3000 x 3000 JPEG, passes every rule" in/11-ok-3000.jpg
run "portrait 2000x3000" in/12-portrait-2000x3000.png
run "file that does not exist" in/nofile.png
: > /tmp/pcart/empty.png
run "empty file, not an image" /tmp/pcart/empty.png
for f in crop pad crop-portrait pad-portrait flat flat-opaque cmyk rgb-again webp renamed big small-up; do
  g=$(ls fix2/$f.* | head -1); run "output of the fix command: $f" $g
done
