Commit b3104126 authored by Michiel Verloop's avatar Michiel Verloop
Browse files

Add/improve end-to-end tests.

• Add CTIerrorBegin/End call to a CTIerrorContinued call site that was missed in an earlier commit.
• Add end-to-end test for CTIerrorBegin/Continued/End.
• Rename error end-to-end tests to have consistent naming.
• Expand test-error-generic to additionally test line wrapping and custom header arguments.
• Fix inconsistent CTIerror behaviour by moving the CTFinitialize call from OPTcheckOptionConsistency to main.c.
parent 558588d1
......@@ -72,6 +72,7 @@ SetupCompiler (int argc, char *argv[], tool_t tool, char *toolname)
GLOBinitializeGlobal (argc, argv, tool, toolname);
OPTanalyseCommandline (argc, argv);
CTFinitialize (); // Reinitialize formatting settings based on command line arguments
RSCevaluateConfiguration ();
......
......@@ -154,9 +154,6 @@ OPTcheckOptionConsistency (void)
DBUG_ENTER ();
// Handle all the checks for compile time formatting aka error handling
CTFinitialize ();
if (global.optimize.dophm && !global.config.use_phm_api) {
CTIerror (EMPTY_LOC, "Private heap management disabled for this SBI.");
}
......
......@@ -124,13 +124,14 @@ CheckImportNameClash (const char *symbol, const char *module, sttable_t *table)
if (STcontains (symbol, table)) {
iterator = STentryIteratorGet (symbol, table);
CTIerror (EMPTY_LOC, "Symbol `%s' imported from module '%s' and", symbol, module);
CTIerrorBegin (EMPTY_LOC, "Symbol `%s' imported from module '%s' and",
symbol, module);
while (STentryIteratorHasMore (iterator)) {
CTIerrorContinued ("...used from module '%s'",
STentryName (STentryIteratorNext (iterator)));
}
CTIerrorEnd ();
iterator = STentryIteratorRelease (iterator);
}
......
......@@ -7,6 +7,8 @@
// SAC_TEST|<tab>echo "$$OUTPUT" | grep -E "^.*:[[:digit:]]+: abort:$$" | $(GREP_COMMAND_OUTPUT) "" 1; <nlslash>
// SAC_TEST|<tab>echo "$$OUTPUT" | grep -F " Cannot overload functions of arity 0" | $(GREP_COMMAND_OUTPUT) "" 1; <nlslash>
// Test the function CTIabort and the underlying CTF functions with partial location information.
int main ()
{
return 0;
......
// SAC_TEST|include common.mk
// SAC_TEST|SAC2C_FLAGS += -b 1:loc -target ThisTargetDoesNotExist
// SAC_TEST|CALL_SAC2C := $(SAC2C) $(SAC2C_FLAGS)
//
// SAC_TEST|all: <file-name>
// SAC_TEST|<tab>OUTPUT=`$(CALL_SAC2C) $< 2>&1`; <nlslash>
// SAC_TEST|<tab>echo "$$OUTPUT" | grep -E "^Error:$$" | $(GREP_COMMAND_OUTPUT) "" 1; <nlslash>
// SAC_TEST|<tab>echo "$$OUTPUT" | grep -F " The configuration files do not contain a specification of target 'ThisTargetDoesNotExist\`." | $(GREP_COMMAND_OUTPUT) "" 1; <nlslash>
// SAC_TEST|<tab>echo "$$OUTPUT" | grep -E "^ You may choose a different .* e.g. in '~/.sac2crc/sac2crc\.mine\`." | $(GREP_COMMAND_OUTPUT) "" 1
// Redo it but with cti-single-line to test the different output.
// SAC_TEST|<tab>OUTPUT=`$(CALL_SAC2C) -cti-single-line -cti-message-length 0 $< 2>&1`; <nlslash>
// We expect only 2 lines:
// SAC_TEST|<tab>echo "$$OUTPUT" | $(GREP_COMMAND_OUTPUT) "" 2; <nlslash>
//// One for the error:
// SAC_TEST|<tab>echo "$$OUTPUT" | grep -E "^Error: The configuration .* e.g. in '~/.sac2crc/sac2crc\.mine\`.$$" | $(GREP_COMMAND_OUTPUT) "" 1; <nlslash>
// And one for the usual compilation failed message:
// SAC_TEST|<tab>echo "$$OUTPUT" | grep -F "Compilation failed while initial, 1 error(s)." | $(GREP_COMMAND_OUTPUT) "" 1; <nlslash>
// Test the functions CTIerrorBegin/Continued/End and the underlying CTF functions with no location information.
// No code is necessary - the command line argument "-target ThisTargetDoesNotExist" leads to an error.
\ No newline at end of file
// SAC_TEST|include common.mk
// SAC_TEST|SAC2C_FLAGS += -check tc -b 1:loc -printstart 1:loc -cti-message-length 1 -cti-header-format "%s begin----: " -cti-multi-line-format "%s continued: "
// SAC_TEST|CALL_SAC2C := $(SAC2C) $(SAC2C_FLAGS)
//
// SAC_TEST|all: <file-name>
// SAC_TEST|<tab>OUTPUT=`$(CALL_SAC2C) $< 2>&1`; <nlslash>
// Test that there is 1 primary line and 11 continued lines.
// SAC_TEST|<tab>echo "$$OUTPUT" | grep -E "^Error begin----: .+$$" | $(GREP_COMMAND_OUTPUT) "" 1; <nlslash>
// SAC_TEST|<tab>echo "$$OUTPUT" | grep -E "^Error continued: .+$$" | $(GREP_COMMAND_OUTPUT) "" 11; <nlslash>
// Since the headers are of length 17, and the message length is lower than 37, the effective message length
// minus the header is set to 20.
// Recall that if there is a space in the first 20 (technically 21) characters, there will be room
// to wrap the line and no characters are allowed beyond the 20th character.
// However, if there are no spaces, the line is allowed to continue until the first place, at which point
// it is wrapped.
//
// To that end, we test that:
// If the non-header part of a line is longer than 20 characters (37 total),
// then there may not be any spaces in the message part of the line.
// SAC_TEST|<tab>echo "$$OUTPUT" | while IFS= read -r line; do <nlslash>
// SAC_TEST|<tab>if [ `echo -n "$$line" | wc -c` -gt 37 ] ; <nlslash>
// SAC_TEST|<tab>then echo "$$line" | cut -c 18- | $(GREP_COMMAND_OUTPUT) " " 0; fi; done; <nlslash>
// Test the function CTIerror and the underlying CTF functions with no location information.
// No code is necessary - there is no matching -printstop flag for the -printstart flag, which leads to an error.
\ No newline at end of file
// This test asserts that syntax errors are printed as `filename:line:column: Error:`
// SAC_TEST|include common.mk
// SAC_TEST|SAC2C_FLAGS += -check tc -b 1:prs
// SAC_TEST|CALL_SAC2C := $(SAC2C) $(SAC2C_FLAGS)
......@@ -7,6 +6,8 @@
// SAC_TEST|<tab>OUTPUT=`$(CALL_SAC2C) $< 2>&1`; <nlslash>
// SAC_TEST|<tab>echo "$$OUTPUT" | grep -E "^.*:[[:digit:]]+:[[:digit:]]+: error:$$" | $(GREP_COMMAND_OUTPUT) "" 3; <nlslash>
// Test the function CTIerror and the underlying CTF functions with complete location information.
int main () {
return 0; This text leads to a syntax error
}
\ No newline at end of file
// SAC_TEST|include common.mk
// SAC_TEST|SAC2C_FLAGS += -check tc -b 1:loc -printstart 1:loc
// SAC_TEST|CALL_SAC2C := $(SAC2C) $(SAC2C_FLAGS)
//
// SAC_TEST|all: <file-name>
// SAC_TEST|<tab>OUTPUT=`$(CALL_SAC2C) $< 2>&1`; <nlslash>
// SAC_TEST|<tab>echo "$$OUTPUT" | grep -E "^Error:$$" | $(GREP_COMMAND_OUTPUT) "" 1; <nlslash>
// SAC_TEST|<tab>echo "$$OUTPUT" | grep -E "^ .+$$" | $(GREP_COMMAND_OUTPUT) "" 3; <nlslash>
int main () {
return 0;
}
\ No newline at end of file
......@@ -8,8 +8,9 @@
// SAC_TEST|<tab>echo "$$OUTPUT" | grep -F ' All instances of "main" contain type errors' | $(GREP_COMMAND_OUTPUT) "" 1; <nlslash>
// SAC_TEST|<tab>echo "$$OUTPUT" | grep -F " Inferred type int[1]{0} should match declared type int" | $(GREP_COMMAND_OUTPUT) "" 1 ; <nlslash>
// Test the function CTIgetErrorMessageVA by causing type errors.
int main ()
{
return [0];
return [0]; // Expects int but gets int[1]{0}
}
\ No newline at end of file
......@@ -6,4 +6,6 @@
// SAC_TEST|<tab>OUTPUT=`$(CALL_SAC2C) $< 2>&1`; <nlslash>
// SAC_TEST|<tab>echo "$$OUTPUT" | grep -E "^TestWarningTest%.*cti-message-length.*$$" | $(GREP_COMMAND_OUTPUT) "" 1; <nlslash>
// No code is necessary - the cti-single-line flag conflicts with the cti-message-length flag and leads to a warning
\ No newline at end of file
// Test the function CTIwarn and the underlying CTF functions with no location information.
// No code is necessary - the cti-single-line flag conflicts with the cti-message-length flag and leads to a warning.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment