From 121178b6612721dd37a02b3dda501968a06429fc Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Fri, 21 Feb 2020 19:32:00 +0000 Subject: Add script to generate missing test outputs --- update-tests.sh | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100755 update-tests.sh (limited to 'update-tests.sh') diff --git a/update-tests.sh b/update-tests.sh new file mode 100755 index 0000000..6630b34 --- /dev/null +++ b/update-tests.sh @@ -0,0 +1,102 @@ +#!/usr/bin/env bash +# This script generates the missing "...B.dhall" files in tests. +# It needs to have a valid `dhall` executable in the PATH. +# It also uses the `fd` command (https://github.com/sharkdp/fd), until +# someone comes up with the correct equivalent `find` invocation. +# +# Usage: +# $ ./update-tests.sh + +usage_text=$(cat <<-END +Usage: update-tests.sh [missing | add] +END +) + +cd "$(dirname "$0")" || exit 1 + +if [ ! -x "$(which dhall)" ] ; then + echo "Error: 'dhall' executable not found in PATH" +fi +if [ ! -x "$(which fd)" ] ; then + echo "Error: 'fd' executable not found in PATH" +fi +if [ ! -x "$(which cbor2diag.rb)" ] ; then + echo "Error: 'cbor2diag.rb' executable not found in PATH" +fi + +function parser_input_file() { echo "$1A.dhall"; } +function parser_output_file() { echo "$1B.dhallb"; } +function parser_process() { + dhall encode --file "$1" +} + +function binary-decode_input_file() { echo "$1A.dhallb"; } +function binary-decode_output_file() { echo "$1B.dhall"; } +function binary-decode_process() { + dhall decode --file "$1" +} + +function semantic-hash_input_file() { echo "$1A.dhall"; } +function semantic-hash_output_file() { echo "$1B.hash"; } +function semantic-hash_process() { + dhall hash --file "$1" +} + +function import_input_file() { echo "$1A.dhall"; } +function import_output_file() { echo "$1B.dhall"; } +function import_process() { + dhall resolve --file "$1" +} + +function type-inference_input_file() { echo "$1A.dhall"; } +function type-inference_output_file() { echo "$1B.dhall"; } +function type-inference_process() { + dhall resolve --file "$1" | dhall type +} + +function normalization_input_file() { echo "$1A.dhall"; } +function normalization_output_file() { echo "$1B.dhall"; } +function normalization_process() { + dhall resolve --file "$1" | dhall normalize +} + +function alpha-normalization_input_file() { echo "$1A.dhall"; } +function alpha-normalization_output_file() { echo "$1B.dhall"; } +function alpha-normalization_process() { + dhall normalize --alpha --file "$1" +} + +tmpfile=$(mktemp -t update-tests.XXXXXX) +trap "{ rm -f $tmpfile; }" EXIT + +function generate_output_file() { + folder="$1" + file="$2" + INPUT_FILE="$(${folder}_input_file "$file")" + OUTPUT_FILE="$(${folder}_output_file "$file")" + if [ ! -f "$OUTPUT_FILE" ]; then + echo "$INPUT_FILE" + ${folder}_process "$INPUT_FILE" > "$tmpfile" + if [ $? -eq 0 ]; then + mv "$tmpfile" "$OUTPUT_FILE" + if [ "$folder" = "parser" ]; then + cat "$OUTPUT_FILE" | cbor2diag.rb > "${file}B.diag" + fi + fi + fi +} + +if [ "$1" = "missing" ]; then + echo "Generating missing output files..." + # This is not robust to spaces in filenames, but there should be none in the + # repo anyways. + for folder in parser binary-decode semantic-hash import type-inference normalization alpha-normalization; do + fd 'A\.dhallb?$' ./dhall-lang/tests/$folder/success ./dhall/tests/$folder/success \ + | sed 's/A.dhallb\?$//' \ + | while read file; do + generate_output_file "$folder" "$file" + done + done +else + echo "$usage_text" +fi -- cgit v1.2.3 From e8f3cc176f3cb44132d20540634aef3384238bce Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 23 Feb 2020 20:56:10 +0000 Subject: Enable script to add new tests --- update-tests.sh | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'update-tests.sh') diff --git a/update-tests.sh b/update-tests.sh index 6630b34..eeb79bd 100755 --- a/update-tests.sh +++ b/update-tests.sh @@ -75,7 +75,7 @@ function generate_output_file() { INPUT_FILE="$(${folder}_input_file "$file")" OUTPUT_FILE="$(${folder}_output_file "$file")" if [ ! -f "$OUTPUT_FILE" ]; then - echo "$INPUT_FILE" + echo "$OUTPUT_FILE" ${folder}_process "$INPUT_FILE" > "$tmpfile" if [ $? -eq 0 ]; then mv "$tmpfile" "$OUTPUT_FILE" @@ -88,8 +88,6 @@ function generate_output_file() { if [ "$1" = "missing" ]; then echo "Generating missing output files..." - # This is not robust to spaces in filenames, but there should be none in the - # repo anyways. for folder in parser binary-decode semantic-hash import type-inference normalization alpha-normalization; do fd 'A\.dhallb?$' ./dhall-lang/tests/$folder/success ./dhall/tests/$folder/success \ | sed 's/A.dhallb\?$//' \ @@ -97,6 +95,28 @@ if [ "$1" = "missing" ]; then generate_output_file "$folder" "$file" done done + +elif [ "$1" = "add" ]; then + # Takes in stdin lists of a path and file contents, like: + # normalization/unit/TextShowEmpty Text/show "" + # This will add a test to the local tests folder for each such line, and generate + # the output using the `dhall` command in the PATH. + while read file contents; do + folder="$(echo "$file" | cut -d/ -f1)" + is_success="$(echo "$file" | cut -d/ -f2)" + file="./dhall/tests/$file" + mkdir -p "$(dirname "$file")" + + if [ "$is_success" = "success" ]; then + INPUT_FILE="${file}A.dhall" + echo "$contents" > $INPUT_FILE + generate_output_file "$folder" "$file" + else + INPUT_FILE="${file}.dhall" + echo "$contents" > $INPUT_FILE + fi + done + else echo "$usage_text" fi -- cgit v1.2.3 From d0a1416b4f2f8138a0751553aac0f34be82e579a Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 23 Feb 2020 21:13:30 +0000 Subject: Make script more robust to missing folders --- update-tests.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'update-tests.sh') diff --git a/update-tests.sh b/update-tests.sh index eeb79bd..1bc0a08 100755 --- a/update-tests.sh +++ b/update-tests.sh @@ -89,11 +89,14 @@ function generate_output_file() { if [ "$1" = "missing" ]; then echo "Generating missing output files..." for folder in parser binary-decode semantic-hash import type-inference normalization alpha-normalization; do - fd 'A\.dhallb?$' ./dhall-lang/tests/$folder/success ./dhall/tests/$folder/success \ - | sed 's/A.dhallb\?$//' \ - | while read file; do - generate_output_file "$folder" "$file" - done + for root in "./dhall-lang/tests" "./dhall/tests"; do + # This is not robust to spaces in filenames, but hopefully there should be none + fd 'A\.dhallb?$' "$root/$folder/success" \ + | sed 's/A.dhallb\?$//' \ + | while read file; do + generate_output_file "$folder" "$file" + done + done done elif [ "$1" = "add" ]; then -- cgit v1.2.3 From 36fc9b140373ffacd90ab45750f97424d3808748 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 29 Feb 2020 22:50:31 +0000 Subject: Run tests from dhall dir --- update-tests.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'update-tests.sh') diff --git a/update-tests.sh b/update-tests.sh index 1bc0a08..d58b4c5 100755 --- a/update-tests.sh +++ b/update-tests.sh @@ -12,7 +12,7 @@ Usage: update-tests.sh [missing | add] END ) -cd "$(dirname "$0")" || exit 1 +cd "$(dirname "$0")/dhall" || exit 1 if [ ! -x "$(which dhall)" ] ; then echo "Error: 'dhall' executable not found in PATH" @@ -89,7 +89,7 @@ function generate_output_file() { if [ "$1" = "missing" ]; then echo "Generating missing output files..." for folder in parser binary-decode semantic-hash import type-inference normalization alpha-normalization; do - for root in "./dhall-lang/tests" "./dhall/tests"; do + for root in "../dhall-lang/tests" "tests"; do # This is not robust to spaces in filenames, but hopefully there should be none fd 'A\.dhallb?$' "$root/$folder/success" \ | sed 's/A.dhallb\?$//' \ -- cgit v1.2.3 From e277fb2f7316fef5c20e7c485eeba1f14328d621 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 1 Mar 2020 15:36:44 +0000 Subject: Run tests from repo root as specified in spec --- update-tests.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'update-tests.sh') diff --git a/update-tests.sh b/update-tests.sh index d58b4c5..91ac2ed 100755 --- a/update-tests.sh +++ b/update-tests.sh @@ -12,7 +12,7 @@ Usage: update-tests.sh [missing | add] END ) -cd "$(dirname "$0")/dhall" || exit 1 +cd "$(dirname "$0")" || exit 1 if [ ! -x "$(which dhall)" ] ; then echo "Error: 'dhall' executable not found in PATH" @@ -89,7 +89,7 @@ function generate_output_file() { if [ "$1" = "missing" ]; then echo "Generating missing output files..." for folder in parser binary-decode semantic-hash import type-inference normalization alpha-normalization; do - for root in "../dhall-lang/tests" "tests"; do + for root in "dhall-lang/tests" "dhall/tests"; do # This is not robust to spaces in filenames, but hopefully there should be none fd 'A\.dhallb?$' "$root/$folder/success" \ | sed 's/A.dhallb\?$//' \ -- cgit v1.2.3 From 24ff14dc98b83ddc12239a0eae4852c9cd87d41f Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 1 Mar 2020 16:37:10 +0000 Subject: Add a lot of import tests --- update-tests.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'update-tests.sh') diff --git a/update-tests.sh b/update-tests.sh index 91ac2ed..6192763 100755 --- a/update-tests.sh +++ b/update-tests.sh @@ -13,6 +13,7 @@ END ) cd "$(dirname "$0")" || exit 1 +export DHALL_TEST_VAR=42 if [ ! -x "$(which dhall)" ] ; then echo "Error: 'dhall' executable not found in PATH" @@ -45,7 +46,7 @@ function semantic-hash_process() { function import_input_file() { echo "$1A.dhall"; } function import_output_file() { echo "$1B.dhall"; } function import_process() { - dhall resolve --file "$1" + dhall --file "$1" } function type-inference_input_file() { echo "$1A.dhall"; } @@ -57,7 +58,7 @@ function type-inference_process() { function normalization_input_file() { echo "$1A.dhall"; } function normalization_output_file() { echo "$1B.dhall"; } function normalization_process() { - dhall resolve --file "$1" | dhall normalize + dhall --file "$1" } function alpha-normalization_input_file() { echo "$1A.dhall"; } -- cgit v1.2.3 From 386f34af802a812c2af8ece2cc427cfb5a7c1fe8 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 1 Mar 2020 17:26:59 +0000 Subject: Implement `missing` and `env:VAR` imports --- update-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'update-tests.sh') diff --git a/update-tests.sh b/update-tests.sh index 6192763..7be40c4 100755 --- a/update-tests.sh +++ b/update-tests.sh @@ -13,7 +13,7 @@ END ) cd "$(dirname "$0")" || exit 1 -export DHALL_TEST_VAR=42 +export DHALL_TEST_VAR="6 * 7" if [ ! -x "$(which dhall)" ] ; then echo "Error: 'dhall' executable not found in PATH" -- cgit v1.2.3