mirror of
https://github.com/github/semantic.git
synced 2024-12-11 08:45:48 +03:00
71 lines
1.6 KiB
Bash
Executable File
71 lines
1.6 KiB
Bash
Executable File
#!/bin/bash
|
|
#/ Usage: script/generate-example fileA fileB
|
|
#/ script/generate-example directory
|
|
#/
|
|
#/ Generate expected output for a test fixture example or directory of examples.
|
|
#/
|
|
#/ Example:
|
|
#/ script/generate-example test/fixtures/ruby/and-or.{A,B}.rb
|
|
#/ script/generate-example test/fixtures/ruby
|
|
|
|
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"
|
|
|
|
count=0
|
|
status () {
|
|
tput cuu 1 && tput el
|
|
echo "Generating $1"
|
|
((count+=1))
|
|
}
|
|
|
|
generate_example () {
|
|
fileA="$1"
|
|
fileB="$2"
|
|
parseFileA="${fileA%%.*}.parseA.txt"
|
|
parseFileB="${fileB%%.*}.parseB.txt"
|
|
diffFileAB="${fileA%%.*}.diffA-B.txt"
|
|
diffFileBA="${fileB%%.*}.diffB-A.txt"
|
|
|
|
if [ -e "$fileA" ]; then
|
|
status $parseFileA
|
|
stack exec semantic -- parse --sexpression $fileA > $parseFileA
|
|
fi
|
|
|
|
if [ -e "$fileB" ]; then
|
|
status $parseFileB
|
|
stack exec semantic -- parse --sexpression $fileB > $parseFileB
|
|
fi
|
|
|
|
if [ -e "$fileA" -a -e "$fileB" ]; then
|
|
status $diffFileAB
|
|
stack exec semantic -- diff --sexpression $fileA $fileB > $diffFileAB
|
|
|
|
status $diffFileBA
|
|
stack exec semantic -- diff --sexpression $fileB $fileA > $diffFileBA
|
|
fi
|
|
}
|
|
|
|
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."
|