diff --git a/cobc/ChangeLog b/cobc/ChangeLog index 2cb212623..b412aaaed 100644 --- a/cobc/ChangeLog +++ b/cobc/ChangeLog @@ -114,6 +114,11 @@ * codegen.c: handle profiling code generation under the cb_flag_prof guard +2024-03-15 Fabrice Le Fessant + + * error.c (print_error_prefix): add cobc_slashify to replace backslashes + by slashes, only if COB_IS_RUNNING_IN_TESTMODE is set. + 2024-02-19 Boris Eng * parser.y (screen_value_clause): replaced basic literals by literals diff --git a/cobc/cobc.c b/cobc/cobc.c index f44c62f75..7d8402f87 100644 --- a/cobc/cobc.c +++ b/cobc/cobc.c @@ -9431,10 +9431,14 @@ main (int argc, char **argv) struct cb_text_list *l; fprintf (cb_depend_file, "%s: \\\n", cb_depend_target); for (l = cb_depend_list; l; l = l->next) { - fprintf (cb_depend_file, " %s%s\n", l->text, l->next ? " \\" : "\n"); + char *filename = cobc_slashify (l->text); + fprintf (cb_depend_file, " %s%s\n", filename, l->next ? " \\" : "\n"); + cobc_free (filename); } for (l = cb_depend_list; l; l = l->next) { - fprintf (cb_depend_file, "%s:\n", l->text); + char *filename = cobc_slashify (l->text); + fprintf (cb_depend_file, "%s:\n", filename); + cobc_free (filename); } fclose (cb_depend_file); } diff --git a/cobc/cobc.h b/cobc/cobc.h index 822f7381e..28b1ec68f 100644 --- a/cobc/cobc.h +++ b/cobc/cobc.h @@ -669,6 +669,8 @@ DECLNORET extern void cobc_terminate_exit (const char *, const char *) COB_A_NO extern void cobc_set_listing_header_code (void); +extern char * cobc_slashify (const char *); + /* reserved.c */ extern struct reserved_word_list *cobc_user_res_list; diff --git a/cobc/error.c b/cobc/error.c index 97a57cd96..cc1e24ebb 100644 --- a/cobc/error.c +++ b/cobc/error.c @@ -62,11 +62,42 @@ size_t cb_msg_style; DECLNORET static void cobc_too_many_errors (void) COB_A_NORETURN; +static int is_test = -1; + +/* Returns a copy of the argument with backslashes replaced by slashes +in filenames, only if COB_IS_RUNNING_IN_TESTMODE. This mode simplifies +the test of outputs, as they will be similar on Unix and Windows. +*/ +char * +cobc_slashify (const char *src) +{ + if (is_test < 0) + is_test = !!getenv ("COB_IS_RUNNING_IN_TESTMODE"); + + if (is_test){ + int i; + int len = strlen (src); + char *dst = cobc_malloc (len+1); + for (i=0; i compiler.output], [0], [], +[],[ + # On Windows, we get a failure from gcc, so the binary is not created, the stderr is mixed and exit code is 1. + AT_CHECK([grep libcob: compiler.output], [0], [libcob: warning: Temporary directory TMP is invalid, adjust TMPDIR! ]) -AT_CHECK([$COBCRUN_DIRECT ./prog], [0], [OK], []) -AT_CHECK([TMPDIR="" TMP="" TEMP="./prog.cob" $COMPILE prog.cob], [0], [], -[libcob: warning: Temporary directory TEMP is invalid, adjust TMPDIR! + ], + [ + AT_CHECK([cat compiler.output], [0], [libcob: warning: Temporary directory TMP is invalid, adjust TMPDIR! +]) + AT_CHECK([$COBCRUN_DIRECT ./prog], [0], [OK], []) + ]) + +AT_CHECK([TMPDIR="" TMP="" TEMP="./prog.cob" $COMPILE prog.cob 2> compiler.output], [0], [], +[],[ + AT_CHECK([grep libcob: compiler.output], [0], [libcob: warning: Temporary directory TEMP is invalid, adjust TMPDIR! ]) + ], + [ + AT_CHECK([cat compiler.output], [0], [libcob: warning: Temporary directory TEMP is invalid, adjust TMPDIR! +]) + ]) + # TMPDIR is only checked when actually needed which is currently only the case # for SORT #AT_CHECK([TMPDIR="./prog.cob" $COBCRUN_DIRECT ./prog], [0], [OK], @@ -1081,15 +1096,16 @@ AT_CHECK([$COBC -fdiagnostics-plain-output -fdiagnostics-show-caret -Wno-others ]]) AT_CHECK([$COMPILE -fdiagnostics-absolute-paths -Wall prog.cob 2> compiler.output], [1]) +AT_CAPTURE_FILE([compiler.output]) + +AT_CHECK([echo "$PWD/prog.cob:7: error: CRUD.CPY: No such file or directory" > expected.output]) +AT_CHECK([echo "$PWD/prog.cob:6: warning: numeric value is expected" >> expected.output]) +AT_CHECK([echo "$PWD/prog.cob:14: warning: ignoring redundant ." >> expected.output]) +AT_CAPTURE_FILE([expected.output]) -# note: -fdiagnostics-absolute-paths will show the realpath, -# so for MSYS/MSVC builds that will be x:\something\prog.cob, not the output of PWD, -# but the _return_path function from atlocal may adjust that -AT_CHECK([cat compiler.output | tr '\\' '/' | $SED "s|$(_return_path "$(pwd)")|DIR|"], [0], -[DIR/prog.cob:7: error: CRUD.CPY: No such file or directory -DIR/prog.cob:6: warning: numeric value is expected -DIR/prog.cob:14: warning: ignoring redundant . -], [], [echo set: $SED "s|$(_return_path "$(pwd)")|DIR|"]) +AT_CHECK([[cat compiler.output | tr '[:upper:]' '[:lower:]' | tr -d ':/\\' > compiler.output2]]) +AT_CHECK([[cat expected.output | tr '[:upper:]' '[:lower:]' | tr -d ':/\\' > expected.output2]]) +AT_CHECK([diff compiler.output2 expected.output2]) AT_CLEANUP @@ -1099,13 +1115,13 @@ AT_SETUP([check include header file]) AT_DATA([filec.h], [ /* COB_EXT_IMPORT will be defined by libcob.h up-front */ -COB_EXT_IMPORT void f (char *, long); +COB_EXT_IMPORT void rename (const char *, const char*); ]) AT_DATA([prog.cob], [ IDENTIFICATION DIVISION. PROGRAM-ID. prog. PROCEDURE DIVISION. - CALL "f" USING "Hello". + CALL "rename" USING "Hello". ]) # dynamic call - program seems correct @@ -1119,10 +1135,8 @@ AT_DATA([prog2.cob], [ IDENTIFICATION DIVISION. PROGRAM-ID. prog. DATA DIVISION. - WORKING-STORAGE SECTION. - 01 long USAGE BINARY-C-LONG. PROCEDURE DIVISION. - CALL "f" USING "Hello" BY VALUE long RETURNING NOTHING. + CALL "rename" USING "Hello" "Hello2" RETURNING NOTHING. ]) # note: we likely need to build an import library for some environments @@ -1153,22 +1167,22 @@ AT_CHECK([$COMPILE_MODULE -I . --include "filec.h" -fstatic-call prog2.cob -o pr # * putting RETURNING NOTHING is not supported # * putting RETURNING OMITTED is ok, but triggers a warning (see stderr) -AT_DATA([f.copy], [ +AT_DATA([rename.copy], [ IDENTIFICATION DIVISION. - PROGRAM-ID. f PROTOTYPE. + PROGRAM-ID. rename PROTOTYPE. DATA DIVISION. LINKAGE SECTION. 01 a PIC X(20). - 01 b BINARY-C-LONG. - PROCEDURE DIVISION USING a BY VALUE b RETURNING OMITTED. - END PROGRAM f. + 01 b PIC X(20). + PROCEDURE DIVISION USING a b RETURNING OMITTED. + END PROGRAM rename. ]) -AT_CHECK([$COMPILE_MODULE -Wno-unfinished --copy "f.copy" -fstatic-call prog2.cob -o prog2c], [0], [], +AT_CHECK([$COMPILE_MODULE -Wno-unfinished --copy "rename.copy" -fstatic-call prog2.cob -o prog2c], [0], [], [prog2.cob:8: warning: unexpected RETURNING item ], [ # Previous test "failed" --> retry with import library - AT_CHECK([$COMPILE_MODULE -Wno-unfinished --copy "f.copy" -fstatic-call -L. -lfilec prog2.cob -o prog2c], [0], ignore, ignore)] + AT_CHECK([$COMPILE_MODULE -Wno-unfinished --copy "rename.copy" -fstatic-call -L. -lfilec prog2.cob -o prog2c], [0], ignore, ignore)] ) AT_CLEANUP