2017-02-24 19:36:18 +03:00
|
|
|
#!/bin/bash
|
|
|
|
#/ Usage: script/generate-example fileA fileB
|
|
|
|
#/
|
|
|
|
#/ Generate expected output for a test fixture example.
|
|
|
|
#/
|
|
|
|
#/ Example:
|
|
|
|
#/ script/generate-example test/fixtures/ruby/and-or.{A,B}.rb
|
|
|
|
|
|
|
|
set -e
|
|
|
|
[ $# -eq 0 ] && set -- --help
|
|
|
|
|
|
|
|
if [[ $1 = -h || $1 = --help ]]; then
|
|
|
|
grep ^#/ <"$0" |cut -c4-
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Work out of the project root directory
|
|
|
|
root=$(cd $(dirname "$0")/.. && pwd)
|
|
|
|
cd "$root"
|
|
|
|
|
2017-02-27 22:55:49 +03:00
|
|
|
count=0
|
|
|
|
status () {
|
|
|
|
tput cuu 1 && tput el
|
|
|
|
echo "Generating $1"
|
|
|
|
((count+=1))
|
|
|
|
}
|
2017-02-24 19:36:18 +03:00
|
|
|
|
2017-02-27 22:55:49 +03:00
|
|
|
generate_example () {
|
|
|
|
fileA="$1"
|
|
|
|
fileB="$2"
|
|
|
|
parseFileA="${fileA%%.*}.parseA.txt"
|
|
|
|
parseFileB="${fileB%%.*}.parseB.txt"
|
|
|
|
diffFileAddA="${fileA%%.*}.diff+A.txt"
|
|
|
|
diffFileRemoveA="${fileA%%.*}.diff-A.txt"
|
|
|
|
diffFileAddB="${fileB%%.*}.diff+B.txt"
|
|
|
|
diffFileRemoveB="${fileB%%.*}.diff-B.txt"
|
|
|
|
diffFileAB="${fileA%%.*}.diffA-B.txt"
|
|
|
|
diffFileBA="${fileB%%.*}.diffB-A.txt"
|
2017-02-24 19:36:18 +03:00
|
|
|
|
2017-02-27 22:55:49 +03:00
|
|
|
status $parseFileA
|
|
|
|
stack exec semantic-diff -- --sexpression --parse $fileA > $parseFileA
|
2017-02-24 19:36:18 +03:00
|
|
|
|
2017-02-27 22:55:49 +03:00
|
|
|
status $parseFileB
|
|
|
|
stack exec semantic-diff -- --sexpression --parse $fileB > $parseFileB
|
2017-02-27 22:24:52 +03:00
|
|
|
|
2017-02-27 22:55:49 +03:00
|
|
|
status $diffFileAddA
|
|
|
|
stack exec semantic-diff -- --sexpression --no-index /dev/null $fileA > $diffFileAddA
|
2017-02-27 22:24:52 +03:00
|
|
|
|
2017-02-27 22:55:49 +03:00
|
|
|
status $diffFileRemoveA
|
|
|
|
stack exec semantic-diff -- --sexpression --no-index $fileA /dev/null > $diffFileRemoveA
|
2017-02-27 22:24:52 +03:00
|
|
|
|
2017-02-27 22:55:49 +03:00
|
|
|
status $diffFileAddB
|
|
|
|
stack exec semantic-diff -- --sexpression --no-index /dev/null $fileB > $diffFileAddB
|
2017-02-27 22:24:52 +03:00
|
|
|
|
2017-02-27 22:55:49 +03:00
|
|
|
status $diffFileRemoveB
|
|
|
|
stack exec semantic-diff -- --sexpression --no-index $fileB /dev/null > $diffFileRemoveB
|
2017-02-24 19:36:18 +03:00
|
|
|
|
2017-02-27 22:55:49 +03:00
|
|
|
status $diffFileAB
|
|
|
|
stack exec semantic-diff -- --sexpression --no-index $fileA $fileB > $diffFileAB
|
|
|
|
|
|
|
|
status $diffFileBA
|
|
|
|
stack exec semantic-diff -- --sexpression --no-index $fileB $fileA > $diffFileBA
|
|
|
|
}
|
|
|
|
|
|
|
|
if [[ -d $1 ]]; then
|
|
|
|
echo "Generating all examples for $1"
|
|
|
|
echo ""
|
|
|
|
for f in $(ls $1/*.A.*); do
|
|
|
|
# echo "${f%%.*}.B."${f##*.}""
|
|
|
|
generate_example $f "${f%%.*}.B."${f##*.}""
|
|
|
|
done
|
|
|
|
else
|
|
|
|
echo "Generating examples just for $1 $2"
|
|
|
|
echo ""
|
|
|
|
generate_example $1 $2
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Done. Generated $count examples."
|