Skip to content

Commit

Permalink
Merge pull request #9 from markprzepiora-forks/bugfixes
Browse files Browse the repository at this point in the history
Several bugfixes
  • Loading branch information
holman committed Jan 11, 2016
2 parents fc425b9 + 21b6799 commit 8f8c17e
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 17 deletions.
28 changes: 16 additions & 12 deletions spaceman-diff
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,30 @@ 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
set +e
sizeA=$(expr $(ls -l "$fileA" | awk '{print $5}') / 1024)
set -e
else
sizeA=0
fi

if [ -f $fileB ] ; then
sizeB=$(expr $(ls -l $fileB | awk '{print $5}') / 1024)
if [ -f "$fileB" ] ; then
set +e
sizeB=$(expr $(ls -l "$fileB" | awk '{print $5}') / 1024)
set -e
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)
Expand All @@ -65,12 +69,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)
Expand Down
55 changes: 50 additions & 5 deletions spaceman-diff-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,60 @@ 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"

rm "$output_file"
}

it_works_with_output_filenames_containing_spaces() {
output_file=$(run_spaceman \
"test/images/flag.png" \
"test/images/flag.png" a190ba 100644 \
"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"

rm "$output_file"
}

it_works_with_input_filenames_containing_spaces() {
output_file=$(run_spaceman \
"test/images/with spaces.png" \
"test/images/with spaces.png" a190ba 100644 \
"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"

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"

$output | grep "OLD:"
$output | grep "(84 KB)"
$output | grep "NEW:"
$output | grep "(9 KB)"
rm "$output_file"
}
Binary file added test/images/small-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/images/with spaces.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8f8c17e

Please sign in to comment.