From 2f7b46dae9b4a9178245e0a66226ab95f15de021 Mon Sep 17 00:00:00 2001 From: Mark Przepiora Date: Mon, 11 Jan 2016 11:06:05 -0700 Subject: [PATCH 1/3] Now works correctly on files with spaces in their names --- spaceman-diff | 24 ++++++++++++------------ spaceman-diff-test.sh | 26 ++++++++++++++++++++++++++ test/images/with spaces.png | Bin 0 -> 10216 bytes 3 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 test/images/with spaces.png diff --git a/spaceman-diff b/spaceman-diff index 82cc8c5..a138188 100755 --- a/spaceman-diff +++ b/spaceman-diff @@ -30,26 +30,26 @@ perDiffWidth=$(expr $screenWidthMinusBuffer / 2) fileA=$2 fileB=$5 -filenameA=$(basename $1) +filenameA=$(basename "$1") extA=${filenameA##*.} -filenameB=$(basename $5) +filenameB=$(basename "$5") extB=${filenameB##*.} # Header row -if [ -f $fileA ] ; then - sizeA=$(expr $(ls -l $fileA | awk '{print $5}') / 1024) +if [ -f "$fileA" ] ; then + sizeA=$(expr $(ls -l "$fileA" | awk '{print $5}') / 1024) else sizeA=0 fi -if [ -f $fileB ] ; then - sizeB=$(expr $(ls -l $fileB | awk '{print $5}') / 1024) +if [ -f "$fileB" ] ; then + sizeB=$(expr $(ls -l "$fileB" | awk '{print $5}') / 1024) else sizeB=0 fi -headerA="OLD: $(basename $1) ($sizeA KB)" -headerB="NEW: $(basename $5) ($sizeB KB)" +headerA="OLD: $(basename "$1") ($sizeA KB)" +headerB="NEW: $(basename "$5") ($sizeB KB)" lengthA=$(echo $headerA | wc -m | xargs) lengthB=$(echo $headerB | wc -m | xargs) @@ -65,12 +65,12 @@ printf "$(yes " " | head -n$sideBySideBuffer | tr -d '\n')" printf "$(yes "—" | head -n$perDiffWidth | tr -d '\n')" echo -if [ -f $fileA ] ; then - outputA=$(convert $fileA jpg:- | jp2a --color --width=$perDiffWidth -) +if [ -f "$fileA" ] ; then + outputA=$(convert "$fileA" jpg:- | jp2a --color --width=$perDiffWidth -) fi -if [ -f $fileB ] ; then - outputB=$(convert $fileB jpg:- | jp2a --color --width=$perDiffWidth -) +if [ -f "$fileB" ] ; then + outputB=$(convert "$fileB" jpg:- | jp2a --color --width=$perDiffWidth -) fi heightA=$(echo "$outputA" | wc -l | xargs) diff --git a/spaceman-diff-test.sh b/spaceman-diff-test.sh index 0a1a1f5..45dc57d 100644 --- a/spaceman-diff-test.sh +++ b/spaceman-diff-test.sh @@ -16,3 +16,29 @@ it_renders_diff() { $output | grep "NEW:" $output | grep "(9 KB)" } + +it_works_with_output_filenames_containing_spaces() { + output_file=$(mktemp /tmp/XXXXX) + + $spaceman "test/images/flag.png" \ + "test/images/flag.png" a190ba 100644 \ + "test/images/with spaces.png" 000000 100644 > "$output_file" + + grep -F 'OLD: flag.png (84 KB)' < "$output_file" + grep -F 'NEW: with spaces.png (9 KB)' < "$output_file" + + rm "$output_file" +} + +it_works_with_input_filenames_containing_spaces() { + output_file=$(mktemp /tmp/XXXXX) + + $spaceman "test/images/with spaces.png" \ + "test/images/with spaces.png" a190ba 100644 \ + "test/images/flag.png" 000000 100644 > "$output_file" + + grep -F 'OLD: with spaces.png (9 KB)' < "$output_file" + grep -F 'NEW: flag.png (84 KB)' < "$output_file" + + rm "$output_file" +} diff --git a/test/images/with spaces.png b/test/images/with spaces.png new file mode 100644 index 0000000000000000000000000000000000000000..2298e303eca8204f426821267d0670511f9d0ef3 GIT binary patch literal 10216 zcmeAS@N?(olHy`uVBq!ia0y~yV86h?z;cCy2`I8(nR_XaVoUONcVYMsf(!O8pUl9Z zz~JfP7*a9k&8>~R%?=DKj&d>FSFIMiE?>tee$Z?E_B5>>6{U}hWu$?c85lmCv8x6% z82&IHlm)YxnykSz3rjhe=HPe-rUeA zjtm@4AE&+w^2^$glbht&GL!4w-k8ym*wN8wV8JvxB0m}ip!#V5(t*VJ?SA Date: Mon, 11 Jan 2016 11:11:18 -0700 Subject: [PATCH 2/3] Speed up test suite --- spaceman-diff-test.sh | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/spaceman-diff-test.sh b/spaceman-diff-test.sh index 45dc57d..a33cbaa 100644 --- a/spaceman-diff-test.sh +++ b/spaceman-diff-test.sh @@ -4,25 +4,33 @@ describe "spaceman-diff: generates ascii image diffs!" spaceman="./spaceman-diff" +run_spaceman() { + readonly output_file=$(mktemp /tmp/XXXXX) + $spaceman "$@" > "$output_file" + echo "$output_file" +} + it_shows_help_with_no_argv() { $spaceman | grep USAGE } it_renders_diff() { - output="$spaceman test/images/flag.png test/images/flag.png a190ba 100644 test/images/gooder-flag.png 000000 100644" + output_file=$(run_spaceman \ + test/images/flag.png \ + test/images/flag.png a190ba 100644 \ + test/images/gooder-flag.png 000000 100644) + + grep -F "OLD: flag.png (84 KB)" < "$output_file" + grep -F "NEW: gooder-flag.png (9 KB)" < "$output_file" - $output | grep "OLD:" - $output | grep "(84 KB)" - $output | grep "NEW:" - $output | grep "(9 KB)" + rm "$output_file" } it_works_with_output_filenames_containing_spaces() { - output_file=$(mktemp /tmp/XXXXX) - - $spaceman "test/images/flag.png" \ + output_file=$(run_spaceman \ + "test/images/flag.png" \ "test/images/flag.png" a190ba 100644 \ - "test/images/with spaces.png" 000000 100644 > "$output_file" + "test/images/with spaces.png" 000000 100644) grep -F 'OLD: flag.png (84 KB)' < "$output_file" grep -F 'NEW: with spaces.png (9 KB)' < "$output_file" @@ -31,11 +39,10 @@ it_works_with_output_filenames_containing_spaces() { } it_works_with_input_filenames_containing_spaces() { - output_file=$(mktemp /tmp/XXXXX) - - $spaceman "test/images/with spaces.png" \ + output_file=$(run_spaceman \ + "test/images/with spaces.png" \ "test/images/with spaces.png" a190ba 100644 \ - "test/images/flag.png" 000000 100644 > "$output_file" + "test/images/flag.png" 000000 100644) grep -F 'OLD: with spaces.png (9 KB)' < "$output_file" grep -F 'NEW: flag.png (84 KB)' < "$output_file" From 21b6799e4f2e8c799d7154acc1c9d1806e0dbc2d Mon Sep 17 00:00:00 2001 From: Mark Przepiora Date: Mon, 11 Jan 2016 11:16:06 -0700 Subject: [PATCH 3/3] Now works correctly with small (< 1 KB) images --- spaceman-diff | 4 ++++ spaceman-diff-test.sh | 12 ++++++++++++ test/images/small-image.png | Bin 0 -> 569 bytes 3 files changed, 16 insertions(+) create mode 100644 test/images/small-image.png diff --git a/spaceman-diff b/spaceman-diff index a138188..eb3bce1 100755 --- a/spaceman-diff +++ b/spaceman-diff @@ -37,13 +37,17 @@ extB=${filenameB##*.} # Header row if [ -f "$fileA" ] ; then + set +e sizeA=$(expr $(ls -l "$fileA" | awk '{print $5}') / 1024) + set -e else sizeA=0 fi if [ -f "$fileB" ] ; then + set +e sizeB=$(expr $(ls -l "$fileB" | awk '{print $5}') / 1024) + set -e else sizeB=0 fi diff --git a/spaceman-diff-test.sh b/spaceman-diff-test.sh index a33cbaa..1faf1a8 100644 --- a/spaceman-diff-test.sh +++ b/spaceman-diff-test.sh @@ -49,3 +49,15 @@ it_works_with_input_filenames_containing_spaces() { rm "$output_file" } + +it_works_with_small_files() { + output_file=$(run_spaceman \ + "test/images/gooder-flag.png" \ + "test/images/gooder-flag.png" a190ba 100644 \ + "test/images/small-image.png" 000000 100644) + + grep -F 'OLD: gooder-flag.png (9 KB)' < "$output_file" + grep -F 'NEW: small-image.png (0 KB)' < "$output_file" + + rm "$output_file" +} diff --git a/test/images/small-image.png b/test/images/small-image.png new file mode 100644 index 0000000000000000000000000000000000000000..851cf6bd9d5bdcd8bdc9089765716fefea95d8f9 GIT binary patch literal 569 zcmV-90>=G`P)p)AdVd1(H6Y#( z#J{mQC;*730I@V4!!sDj2e|Y;1>zha-T>k-K?PHRcpVGr435$Aa=pD`WWJejO@ALsrP~St76F>@jO7!9kp>AmB4jH3& z{E%@smGq8g`=Ohte*iHDl9&fHvEc&fO;igi=>>srpmOLKkYPDU0_Yeh%BBvY7@Nuj z?J3L~1dahUU6wOJyD6a2t9T$j4NX(@0zaU3#zEciA0WU0(g|X9hZu%m00000NkvXX Hu0mjf9~;`J literal 0 HcmV?d00001