Skip to content

Commit

Permalink
Add support for case studies as tests
Browse files Browse the repository at this point in the history
Case studies are tested just like examples, but their results are output in a separate group.
Case studies are also added as part of the pretty-printer test cases.
The file `./case-studies/.gitkeep` can be deleted once case studies are added to the repository.
  • Loading branch information
MartyO256 committed Jan 27, 2024
1 parent 16786c5 commit 8e17136
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
13 changes: 13 additions & 0 deletions TEST.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ shopt -s nullglob

# Option flags.
declare FORCE_COLOR_OUTPUT=""
declare RUN_CASE_STUDIES="true"
declare RUN_EXAMPLES_TESTS="true"
declare RUN_COMPILER_TESTS="true"
declare RUN_INTERACTIVE_MODE_TESTS="true"
Expand All @@ -28,6 +29,7 @@ declare -r REPLAY=${REPLAY:-"${BUILDPATH}/replay"}

declare -r TESTROOTDIR=${TESTROOTDIR:-"./t"}
declare -r TESTDIR=${TESTDIR:-"${TESTROOTDIR}/code"}
declare -r STUDYDIR=${STUDYDIR:-"./case-studies"}
declare -r EXAMPLEDIR=${EXAMPLEDIR:-"./examples"}
declare -r INTERACTIVE_TESTDIR=${INTERACTIVE_TESTDIR:-"${TESTROOTDIR}/interactive"}
declare -r HARPOON_TESTDIR=${HARPOON_TESTDIR:-"${TESTROOTDIR}/harpoon"}
Expand All @@ -37,6 +39,7 @@ declare -i TIMEOUT=${TIMEOUT:-10}
function rsync_test_artifacts {
rsync -ak "${ROOTDIR}/.admissible-fail" "${TEMPDIR}/.admissible-fail"
rsync -ak --chmod=Fa+w "${ROOTDIR}/${TESTROOTDIR}/" "${TEMPDIR}/${TESTROOTDIR}"
rsync -ak "${ROOTDIR}/${STUDYDIR}/" "${TEMPDIR}/${STUDYDIR}"
rsync -ak "${ROOTDIR}/${EXAMPLEDIR}/" "${TEMPDIR}/${EXAMPLEDIR}"
}

Expand Down Expand Up @@ -123,6 +126,16 @@ function do_testing {
# Limit runtime of each test case, in seconds.
ulimit -t "${TIMEOUT}"

if [[ -n "${RUN_CASE_STUDIES}" ]]; then
echo "===== CASE STUDIES ====="

while read -r file_path; do
start_test_case "${file_path}"

check_example_test_case "${file_path}"
done <<< "$(find_compiler_tests_in "${STUDYDIR}" | sort -n)"
fi

if [[ -n "${RUN_EXAMPLES_TESTS}" ]]; then
echo "===== EXAMPLES ====="

Expand Down
Empty file added case-studies/.gitkeep
Empty file.
3 changes: 2 additions & 1 deletion test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
test_parser/fixtures/disambiguation_state.json
(glob_files test_parser/fixtures/*.input.bel)
(glob_files test_parser/fixtures/*.output.json)
(glob_files_rec ../examples/*)))
(glob_files_rec ../examples/*)
(glob_files_rec ../case-studies/*)))
5 changes: 4 additions & 1 deletion test/test_parser/test_html_pp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ let make_html_test ?(save_html_to_file = false) compiler_test_file =
ignore
(Format.asprintf "%a@." Beluga_html.pp_signature signature : string)

let case_studies_directory = "../case-studies"

let examples_directory = "../examples"

let tests () =
let compiler_tests =
Files.find_compiler_tests ~directory:examples_directory
Files.find_compiler_tests ~directory:case_studies_directory
@ Files.find_compiler_tests ~directory:examples_directory
in
List.map make_html_test compiler_tests
5 changes: 4 additions & 1 deletion test/test_parser/test_pp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,13 @@ let make_compiler_test ?(save_json_to_file = false)
Fun.(json_of_signature >> without_locations)
~expected:signature ~actual:signature'

let case_studies_directory = "../case-studies"

let examples_directory = "../examples"

let tests () =
let compiler_tests =
Files.find_compiler_tests ~directory:examples_directory
Files.find_compiler_tests ~directory:case_studies_directory
@ Files.find_compiler_tests ~directory:examples_directory
in
List.map make_compiler_test compiler_tests

0 comments on commit 8e17136

Please sign in to comment.