tests: check the generated C code

(and update for new errors)
This commit is contained in:
Louis Gesbert 2024-05-15 17:23:36 +02:00
parent 9af7548bf0
commit 081605d04d
4 changed files with 44 additions and 18 deletions

4
dune
View File

@ -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)

View File

@ -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

View File

@ -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,

View File

@ -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;