Skip to content

Commit

Permalink
test: add sarif test fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
frabert committed Jul 24, 2024
1 parent 29be3ef commit 126be5f
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 9 deletions.
2 changes: 1 addition & 1 deletion test/sarif/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2024, Trail of Bits, Inc. All rights reserved.

add_gap_test(test-gap-sarif
sarif.cpp
definitions.cpp
)

target_link_libraries(test-gap-sarif
Expand Down
79 changes: 79 additions & 0 deletions test/sarif/definitions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright (c) 2024-present, Trail of Bits, Inc.

#include <doctest/doctest.h>
#include <gap/sarif/definitions.hpp>
#include <memory>
#include <vector>

namespace gap::sarif::definitions {
TEST_CASE("Roundtrip") {
// Sample SARIF output from https://github.com/microsoft/sarif-tutorials/blob/main/docs/1-Introduction.md
root_struct root{
.version = version_enum::k2_1_0,
.runs = {
{
.tool = {
.driver = {
.name="ESLint",
.informationUri="https://eslint.org",
.rules = {
{
.id = "no-unused-vars",
.shortDescription = {
.text = "disallow unused variables",
},
.helpUri = "https://eslint.org/docs/rules/no-unused-vars",
.properties = {
{"category", "Variables"},
},
},
},
},
},
.artifacts = {
{
.location = {
.uri = "file:///C:/dev/sarif/sarif-tutorials/samples/Introduction/simple-example.js",
},
},
},
.results = {
{
.level = level_enum::kError,
.message = {
.text = "'x' is assigned a value but never used.",
},
.locations = {
{
.physicalLocation = {
.artifactLocation = {
.uri = "file:///C:/dev/sarif/sarif-tutorials/samples/Introduction/simple-example.js",
.index = 0,
},
.region = {
.startLine = 1,
.startColumn = 5,
},
},
},
},
.ruleId = "no-unused-vars",
.ruleIndex = 0,
},
},
},
},
};

Check failure on line 66 in test/sarif/definitions.cpp

View workflow job for this annotation

GitHub Actions / build

missing initializer for member ‘gap::sarif::definitions::tool_component_struct::guid’ [-Werror=missing-field-initializers]

Check failure on line 66 in test/sarif/definitions.cpp

View workflow job for this annotation

GitHub Actions / build

missing initializer for member ‘gap::sarif::definitions::tool_component_struct::organization’ [-Werror=missing-field-initializers]

Check failure on line 66 in test/sarif/definitions.cpp

View workflow job for this annotation

GitHub Actions / build

missing initializer for member ‘gap::sarif::definitions::tool_component_struct::product’ [-Werror=missing-field-initializers]

Check failure on line 66 in test/sarif/definitions.cpp

View workflow job for this annotation

GitHub Actions / build

missing initializer for member ‘gap::sarif::definitions::tool_component_struct::productSuite’ [-Werror=missing-field-initializers]

Check failure on line 66 in test/sarif/definitions.cpp

View workflow job for this annotation

GitHub Actions / build

missing initializer for member ‘gap::sarif::definitions::tool_component_struct::shortDescription’ [-Werror=missing-field-initializers]

Check failure on line 66 in test/sarif/definitions.cpp

View workflow job for this annotation

GitHub Actions / build

missing initializer for member ‘gap::sarif::definitions::tool_component_struct::fullDescription’ [-Werror=missing-field-initializers]

Check failure on line 66 in test/sarif/definitions.cpp

View workflow job for this annotation

GitHub Actions / build

missing initializer for member ‘gap::sarif::definitions::tool_component_struct::fullName’ [-Werror=missing-field-initializers]

Check failure on line 66 in test/sarif/definitions.cpp

View workflow job for this annotation

GitHub Actions / build

missing initializer for member ‘gap::sarif::definitions::tool_component_struct::version’ [-Werror=missing-field-initializers]

Check failure on line 66 in test/sarif/definitions.cpp

View workflow job for this annotation

GitHub Actions / build

missing initializer for member ‘gap::sarif::definitions::tool_component_struct::semanticVersion’ [-Werror=missing-field-initializers]

Check failure on line 66 in test/sarif/definitions.cpp

View workflow job for this annotation

GitHub Actions / build

missing initializer for member ‘gap::sarif::definitions::tool_component_struct::dottedQuadFileVersion’ [-Werror=missing-field-initializers]

nlohmann::json root_json;
to_json(root_json, root);

root_struct deser;
from_json(root_json, deser);

nlohmann::json deser_json;
to_json(deser_json, deser);

CHECK(root_json == deser_json);
}
}
8 changes: 0 additions & 8 deletions test/sarif/sarif.cpp

This file was deleted.

0 comments on commit 126be5f

Please sign in to comment.