From 126be5fc337e72767dfd98f161e4fc86e4dd2714 Mon Sep 17 00:00:00 2001 From: Francesco Bertolaccini Date: Wed, 24 Jul 2024 12:34:59 +0200 Subject: [PATCH] test: add sarif test fixture --- test/sarif/CMakeLists.txt | 2 +- test/sarif/definitions.cpp | 79 ++++++++++++++++++++++++++++++++++++++ test/sarif/sarif.cpp | 8 ---- 3 files changed, 80 insertions(+), 9 deletions(-) create mode 100644 test/sarif/definitions.cpp delete mode 100644 test/sarif/sarif.cpp diff --git a/test/sarif/CMakeLists.txt b/test/sarif/CMakeLists.txt index fe0b48c..fd7492e 100644 --- a/test/sarif/CMakeLists.txt +++ b/test/sarif/CMakeLists.txt @@ -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 diff --git a/test/sarif/definitions.cpp b/test/sarif/definitions.cpp new file mode 100644 index 0000000..2cccebe --- /dev/null +++ b/test/sarif/definitions.cpp @@ -0,0 +1,79 @@ +// Copyright (c) 2024-present, Trail of Bits, Inc. + +#include +#include +#include +#include + +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, + }, + }, + }, + }, + }; + + 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); + } +} \ No newline at end of file diff --git a/test/sarif/sarif.cpp b/test/sarif/sarif.cpp deleted file mode 100644 index 79724b5..0000000 --- a/test/sarif/sarif.cpp +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (c) 2024-present, Trail of Bits, Inc. - -#include -#include -#include -#include - -namespace gap::sarif {} \ No newline at end of file