2020-03-30 05:49:33 +03:00
|
|
|
#!/usr/bin/env bash
|
2017-02-24 19:36:18 +03:00
|
|
|
#/ Usage: script/generate-example fileA fileB
|
2017-02-28 02:25:44 +03:00
|
|
|
#/ script/generate-example directory
|
2017-02-24 19:36:18 +03:00
|
|
|
#/
|
2017-02-28 02:25:44 +03:00
|
|
|
#/ Generate expected output for a test fixture example or directory of examples.
|
2017-02-24 19:36:18 +03:00
|
|
|
#/
|
|
|
|
#/ Example:
|
2018-06-22 21:19:01 +03:00
|
|
|
#/ script/generate-example test/fixtures/ruby/corpus/and-or.{A,B}.rb
|
|
|
|
#/ script/generate-example test/fixtures/ruby/corpus
|
2017-02-24 19:36:18 +03:00
|
|
|
|
|
|
|
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"
|
|
|
|
diffFileAB="${fileA%%.*}.diffA-B.txt"
|
|
|
|
diffFileBA="${fileB%%.*}.diffB-A.txt"
|
2017-02-24 19:36:18 +03:00
|
|
|
|
2018-04-11 08:49:57 +03:00
|
|
|
if [ -e "$fileA" ]; then
|
|
|
|
status $parseFileA
|
2019-10-30 15:42:28 +03:00
|
|
|
cabal v2-run --verbose=0 semantic -- parse --sexpression $fileA > $parseFileA
|
2018-04-11 08:49:57 +03:00
|
|
|
fi
|
2017-02-24 19:36:18 +03:00
|
|
|
|
2018-04-11 08:49:57 +03:00
|
|
|
if [ -e "$fileB" ]; then
|
|
|
|
status $parseFileB
|
2019-10-30 15:42:28 +03:00
|
|
|
cabal v2-run --verbose=0 semantic -- parse --sexpression $fileB > $parseFileB
|
2018-04-11 08:49:57 +03:00
|
|
|
fi
|
2017-02-27 22:24:52 +03:00
|
|
|
|
2018-04-11 08:49:57 +03:00
|
|
|
if [ -e "$fileA" -a -e "$fileB" ]; then
|
|
|
|
status $diffFileAB
|
2019-10-30 15:42:28 +03:00
|
|
|
cabal v2-run --verbose=0 semantic -- diff --sexpression $fileA $fileB > $diffFileAB
|
2017-02-27 22:55:49 +03:00
|
|
|
|
2018-04-11 08:49:57 +03:00
|
|
|
status $diffFileBA
|
2019-10-30 15:42:28 +03:00
|
|
|
cabal v2-run --verbose=0 semantic -- diff --sexpression $fileB $fileA > $diffFileBA
|
2018-04-11 08:49:57 +03:00
|
|
|
fi
|
2017-02-27 22:55:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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."
|