From 081605d04d9becf03caaa3238ccc0d1b6129eb55 Mon Sep 17 00:00:00 2001 From: Louis Gesbert Date: Wed, 15 May 2024 17:23:36 +0200 Subject: [PATCH] tests: check the generated C code (and update for new errors) --- dune | 4 ++-- runtimes/dune | 2 +- tests/backends/output/main.c | 32 +++++++++++++++++++------------- tests/backends/output/simple.c | 24 ++++++++++++++++++++++-- 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/dune b/dune index e6e33c64..82abd739 100644 --- a/dune +++ b/dune @@ -1,6 +1,6 @@ -(dirs runtimes compiler build_system) +(dirs runtimes compiler build_system tests) -(data_only_dirs tests syntax_highlighting) +(data_only_dirs syntax_highlighting) (vendored_dirs catala-examples.tmp french-law.tmp) diff --git a/runtimes/dune b/runtimes/dune index 721fc5d5..d0364d5f 100644 --- a/runtimes/dune +++ b/runtimes/dune @@ -1,7 +1,7 @@ (documentation (package catala)) -(dirs jsoo ocaml python r rescript) +(dirs jsoo ocaml python r rescript c) ; Installation is done as source under catala lib directory ; For dev version this makes it easy to install the proper runtime with just diff --git a/tests/backends/output/main.c b/tests/backends/output/main.c index b8e7b80b..7c1e6975 100644 --- a/tests/backends/output/main.c +++ b/tests/backends/output/main.c @@ -52,25 +52,31 @@ int main() { char *error_kind; switch (catala_fatal_error_raised.code) - { - case catala_no_value_provided: - error_kind = "No value provided"; + { + case catala_assertion_failed: + error_kind = "an assertion doesn't hold"; break; - case catala_conflict: - error_kind = "Conflict between exceptions"; + case catala_no_value: + error_kind = "no applicable rule to define this variable in this situation"; break; - case catala_crash: - error_kind = "Crash"; + case catala_conflict: + error_kind = "conflict between multiple valid consequences for assigning the same variable"; break; - case catala_empty: - error_kind = "Empty error not caught"; + case catala_division_by_zero: + error_kind = "a value is being used as denominator in a division and it computed to zero"; break; - case catala_assertion_failure: - error_kind = "Asssertion failure"; + case catala_not_same_length: + error_kind = "traversing multiple lists of different lengths"; break; - case catala_malloc_error: + case catala_uncomparable_durations: + error_kind = "ambiguous comparison between durations in different units (e.g. months vs. days)"; + break; + case catala_indivisible_durations: + error_kind = "dividing durations that are not in days"; + break; + case catala_malloc_error: error_kind = "Malloc error"; - } + }; printf("\033[1;31m[ERROR]\033[0m %s in file %s:%d.%d-%d.%d\n", error_kind, catala_fatal_error_raised.position.filename, diff --git a/tests/backends/output/simple.c b/tests/backends/output/simple.c index b67e47d9..b430bb9b 100644 --- a/tests/backends/output/simple.c +++ b/tests/backends/output/simple.c @@ -388,6 +388,18 @@ baz_struct baz_func(baz_in_struct baz_in) { temp_c_2.code = option_3_enum_none_3_cons; temp_c_2.payload.none_3_cons = NULL; } + option_3_enum temp_c_5; + if (1 /* TRUE */) { + array_3_struct temp_c_6; + temp_c_6.content_field = catala_malloc(sizeof(array_3_struct)); + + option_3_enum temp_c_7 = {option_3_enum_some_3_cons, + {some_3_cons: temp_c_6}}; + temp_c_5 = temp_c_7; + } else { + temp_c_5.code = option_3_enum_none_3_cons; + temp_c_5.payload.none_3_cons = NULL; + } option_3_enum exception_acc_5 = {option_3_enum_none_3_cons, {none_3_cons: NULL}}; option_3_enum exception_current_5; @@ -400,6 +412,14 @@ baz_struct baz_func(baz_in_struct baz_in) { exception_acc_5 = exception_current_5; } } + exception_current_5 = temp_c_5; + if (exception_current_5.code == option_3_enum_some_3_cons) { + if (exception_acc_5.code == option_3_enum_some_3_cons) { + exception_conflict_5 = 1; + } else { + exception_acc_5 = exception_current_5; + } + } if (exception_conflict_5) { catala_fatal_error_raised.code = catala_conflict; catala_fatal_error_raised.position.filename = "tests/backends/simple.catala_en"; @@ -413,9 +433,9 @@ baz_struct baz_func(baz_in_struct baz_in) { temp_c_1 = exception_acc_5; } else { if (0 /* FALSE */) { - option_3_enum temp_c_5 = {option_3_enum_none_3_cons, + option_3_enum temp_c_8 = {option_3_enum_none_3_cons, {none_3_cons: NULL}}; - temp_c_1 = temp_c_5; + temp_c_1 = temp_c_8; } else { temp_c_1.code = option_3_enum_none_3_cons; temp_c_1.payload.none_3_cons = NULL;