sarif_invocation::prepare_to_flush (diagnostic_context &context)
{
/* "executionSuccessful" property (SARIF v2.1.0 section 3.20.14). */
+ if (context.execution_failed_p ())
+ m_success = false;
set_bool ("executionSuccessful", m_success);
/* "toolExecutionNotifications" property (SARIF v2.1.0 section 3.20.21). */
m_original_argv = nullptr;
}
+/* Return true if sufficiently severe diagnostics have been seen that
+ we ought to exit with a non-zero exit code. */
+
+bool
+diagnostic_context::execution_failed_p () const
+{
+ /* Equivalent to (seen_error () || werrorcount), but on
+ this context, rather than global_dc. */
+ return (m_diagnostic_count [DK_ERROR]
+ || m_diagnostic_count [DK_SORRY]
+ || m_diagnostic_count [DK_WERROR]);
+}
+
void
diagnostic_context::set_output_format (diagnostic_output_format *output_format)
{
void finish ();
+ bool execution_failed_p () const;
+
void set_original_argv (unique_argv original_argv);
const char * const *get_original_argv ()
{
#include "include-chain-2.h"
-/* We expect a failing compile due to the errors, but the use of
- -fdiagnostics-format=sarif-file means there should be no output to stderr.
- DejaGnu injects this message; ignore it:
- { dg-prune-output "exit status is 1" } */
-
/* Verify that some JSON was written to a file with the expected name:
{ dg-final { verify-sarif-file } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-fdiagnostics-format=sarif-file" } */
+
+/* Verify our SARIF output for a translation unit with no diagnostics. */
+
+int nonempty;
+
+/* Verify that some JSON was written to a file with the expected name:
+ { dg-final { verify-sarif-file } } */
+
+/* Use a Python script to verify various properties about the generated
+ .sarif file:
+ { dg-final { run-sarif-pytest no-diagnostics.c "test-no-diagnostics.py" } } */
version = sarif['version']
assert version == "2.1.0"
+def test_execution_unsuccessful(sarif):
+ runs = sarif['runs']
+ run = runs[0]
+
+ invocations = run['invocations']
+ assert len(invocations) == 1
+ invocation = invocations[0]
+
+ # We expect the errors to make executionSuccessful be false
+ assert invocation['executionSuccessful'] == False
+
def test_location_relationships(sarif):
runs = sarif['runs']
run = runs[0]
version = sarif['version']
assert version == "2.1.0"
+def test_execution_successful(sarif):
+ runs = sarif['runs']
+ run = runs[0]
+
+ invocations = run['invocations']
+ assert len(invocations) == 1
+ invocation = invocations[0]
+
+ # We expect a mere 'warning' to allow executionSuccessful be true
+ assert invocation['executionSuccessful'] == True
+
def test_result(sarif):
runs = sarif['runs']
run = runs[0]
version = sarif['version']
assert version == "2.1.0"
+def test_execution_unsuccessful(sarif):
+ runs = sarif['runs']
+ run = runs[0]
+
+ invocations = run['invocations']
+ assert len(invocations) == 1
+ invocation = invocations[0]
+
+ # We expect the 'error' to make executionSuccessful be false
+ assert invocation['executionSuccessful'] == False
+
def test_location_relationships(sarif):
runs = sarif['runs']
run = runs[0]
--- /dev/null
+from sarif import *
+
+import pytest
+
+@pytest.fixture(scope='function', autouse=True)
+def sarif():
+ return sarif_from_env()
+
+def test_basics(sarif):
+ schema = sarif['$schema']
+ assert schema == "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json"
+
+ version = sarif['version']
+ assert version == "2.1.0"
+
+def test_execution_successful(sarif):
+ runs = sarif['runs']
+ run = runs[0]
+
+ invocations = run['invocations']
+ assert len(invocations) == 1
+ invocation = invocations[0]
+
+ assert invocation['executionSuccessful'] == True
+ assert invocation['toolExecutionNotifications'] == []
+
+def test_empty_results(sarif):
+ runs = sarif['runs']
+ run = runs[0]
+ results = run['results']
+ assert len(results) == 0
--- /dev/null
+from sarif import *
+
+import pytest
+
+@pytest.fixture(scope='function', autouse=True)
+def sarif():
+ return sarif_from_env()
+
+def test_basics(sarif):
+ schema = sarif['$schema']
+ assert schema == "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json"
+
+ version = sarif['version']
+ assert version == "2.1.0"
+
+def test_execution_unsuccessful(sarif):
+ runs = sarif['runs']
+ run = runs[0]
+
+ invocations = run['invocations']
+ assert len(invocations) == 1
+ invocation = invocations[0]
+
+ assert '-Werror=unused-variable' in invocation['arguments']
+
+ # We expect the 'Werror' to make executionSuccessful be false
+ assert invocation['executionSuccessful'] == False
+
+def test_result(sarif):
+ runs = sarif['runs']
+ run = runs[0]
+ results = run['results']
+
+ assert len(results) == 1
+
+ result = results[0]
+ assert result['ruleId'] == '-Werror=unused-variable'
+ assert result['level'] == 'error'
+ assert result['message']['text'] == "'ununsed' defined but not used"
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-Werror=unused-variable -fdiagnostics-format=sarif-file" } */
+
+/* Verify our SARIF output for a translation unit with -Werror. */
+
+static int ununsed;
+
+/* We expect a failing compile due to the Werror, but the use of
+ -fdiagnostics-format=sarif-file means there should be no output to stderr.
+ DejaGnu injects this message; ignore it:
+ { dg-prune-output "exit status is 1" } */
+
+/* Verify that some JSON was written to a file with the expected name:
+ { dg-final { verify-sarif-file } } */
+
+/* Use a Python script to verify various properties about the generated
+ .sarif file:
+ { dg-final { run-sarif-pytest werror.c "test-werror.py" } } */
after_memory_report = true;
- if (seen_error () || werrorcount)
+ if (global_dc->execution_failed_p ())
return (FATAL_EXIT_CODE);
return (SUCCESS_EXIT_CODE);