Skip to content

Commit

Permalink
test: generate_SARIF()
Browse files Browse the repository at this point in the history
  • Loading branch information
jamacku committed May 9, 2024
1 parent c8739cb commit cb3a8c3
Show file tree
Hide file tree
Showing 3 changed files with 299 additions and 0 deletions.
49 changes: 49 additions & 0 deletions test/fixtures/generate_SARIF/defects.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"defects": [
{
"checker": "SHELLCHECK_WARNING",
"language": "shell",
"tool": "shellcheck",
"key_event_idx": 0,
"events": [
{
"file_name": "innocent-script.sh",
"line": 7,
"event": "warning[SC2034]",
"message": "UNUSED_VAR2 appears unused. Verify use (or export if used externally).",
"verbosity_level": 0
}
]
},
{
"checker": "SHELLCHECK_WARNING",
"language": "shell",
"tool": "shellcheck",
"key_event_idx": 0,
"events": [
{
"file_name": "innocent-script.sh",
"line": 11,
"event": "warning[SC2115]",
"message": "Use \"${var:?}\" to ensure this never expands to / .",
"verbosity_level": 0
}
]
},
{
"checker": "SHELLCHECK_WARNING",
"language": "shell",
"tool": "shellcheck",
"key_event_idx": 0,
"events": [
{
"file_name": "innocent-script.sh",
"line": 11,
"event": "warning[SC2115]",
"message": "Use \"${var:?}\" to ensure this never expands to / .",
"verbosity_level": 0
}
]
}
]
}
210 changes: 210 additions & 0 deletions test/fixtures/generate_SARIF/test.sarif
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
{
"$schema": "https://json.schemastore.org/sarif-2.1.0.json",
"version": "2.1.0",
"inlineExternalProperties": [
{
"externalizedProperties": {
"tool": "ShellCheck",
"tool-url": "https://www.shellcheck.net/wiki/",
"tool-version": "0.9.0"
}
}
],
"runs": [
{
"tool": {
"driver": {
"name": "ShellCheck",
"version": "0.9.0",
"informationUri": "https://www.shellcheck.net/wiki/",
"rules": [
{
"id": "SHELLCHECK_WARNING: warning[SC2034]",
"properties": {
"tags": [
"ShellCheck"
]
},
"name": "SC2034",
"help": {
"text": "Defect reference: https://github.com/koalaman/shellcheck/wiki/SC2034",
"markdown": "Defect reference: [SC2034](https://github.com/koalaman/shellcheck/wiki/SC2034)"
}
},
{
"id": "SHELLCHECK_WARNING: warning[SC2115]",
"properties": {
"tags": [
"ShellCheck"
]
},
"name": "SC2115",
"help": {
"text": "Defect reference: https://github.com/koalaman/shellcheck/wiki/SC2115",
"markdown": "Defect reference: [SC2115](https://github.com/koalaman/shellcheck/wiki/SC2115)"
}
}
]
}
},
"results": [
{
"ruleId": "SHELLCHECK_WARNING: warning[SC2034]",
"level": "warning",
"locations": [
{
"id": 0,
"physicalLocation": {
"artifactLocation": {
"uri": "innocent-script.sh"
},
"region": {
"startLine": 7,
"endLine": 7
}
}
}
],
"message": {
"text": "UNUSED_VAR2 appears unused. Verify use (or export if used externally)."
},
"codeFlows": [
{
"threadFlows": [
{
"locations": [
{
"location": {
"id": 0,
"physicalLocation": {
"artifactLocation": {
"uri": "innocent-script.sh"
},
"region": {
"startLine": 7,
"endLine": 7
}
},
"message": {
"text": "UNUSED_VAR2 appears unused. Verify use (or export if used externally)."
}
},
"nestingLevel": 0,
"kinds": [
"warning[SC2034]"
]
}
]
}
]
}
]
},
{
"ruleId": "SHELLCHECK_WARNING: warning[SC2115]",
"level": "warning",
"locations": [
{
"id": 0,
"physicalLocation": {
"artifactLocation": {
"uri": "innocent-script.sh"
},
"region": {
"startLine": 11,
"endLine": 11
}
}
}
],
"message": {
"text": "Use \"${var:?}\" to ensure this never expands to / ."
},
"codeFlows": [
{
"threadFlows": [
{
"locations": [
{
"location": {
"id": 0,
"physicalLocation": {
"artifactLocation": {
"uri": "innocent-script.sh"
},
"region": {
"startLine": 11,
"endLine": 11
}
},
"message": {
"text": "Use \"${var:?}\" to ensure this never expands to / ."
}
},
"nestingLevel": 0,
"kinds": [
"warning[SC2115]"
]
}
]
}
]
}
]
},
{
"ruleId": "SHELLCHECK_WARNING: warning[SC2115]",
"level": "warning",
"locations": [
{
"id": 0,
"physicalLocation": {
"artifactLocation": {
"uri": "innocent-script.sh"
},
"region": {
"startLine": 11,
"endLine": 11
}
}
}
],
"message": {
"text": "Use \"${var:?}\" to ensure this never expands to / ."
},
"codeFlows": [
{
"threadFlows": [
{
"locations": [
{
"location": {
"id": 0,
"physicalLocation": {
"artifactLocation": {
"uri": "innocent-script.sh"
},
"region": {
"startLine": 11,
"endLine": 11
}
},
"message": {
"text": "Use \"${var:?}\" to ensure this never expands to / ."
}
},
"nestingLevel": 0,
"kinds": [
"warning[SC2115]"
]
}
]
}
]
}
]
}
]
}
]
}
40 changes: 40 additions & 0 deletions test/generate_SARIF.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# SPDX-License-Identifier: GPL-3.0-or-later

setup_file () {
load 'test_helper/common-setup'
_common_setup
}

setup () {
load 'test_helper/bats-assert/load'
load 'test_helper/bats-support/load'
load 'test_helper/bats-file/load'
}

@test "generate_SARIF() - arguments" {
source "${PROJECT_ROOT}/src/functions.sh"

run generate_SARIF
assert_failure 1

run generate_SARIF "./test/fixtures/generate_SARIF/defects.log"
assert_failure 1

run generate_SARIF "./test/fixtures/generate_SARIF/defects.log" "test.sarif"
assert_success
}

@test "generate_SARIF()" {
source "${PROJECT_ROOT}/src/functions.sh"

run generate_SARIF "./test/fixtures/generate_SARIF/defects.log" "./test.sarif"
assert_success
assert_exists "./test.sarif"

run cmp -s "test.sarif" "./test/fixtures/generate_SARIF/test.sarif"
assert_success
}

teardown () {
rm -f test.sarif
}

0 comments on commit cb3a8c3

Please sign in to comment.