Skip to content

Commit cb3a8c3

Browse files
committed
test: generate_SARIF()
1 parent c8739cb commit cb3a8c3

File tree

3 files changed

+299
-0
lines changed

3 files changed

+299
-0
lines changed
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"defects": [
3+
{
4+
"checker": "SHELLCHECK_WARNING",
5+
"language": "shell",
6+
"tool": "shellcheck",
7+
"key_event_idx": 0,
8+
"events": [
9+
{
10+
"file_name": "innocent-script.sh",
11+
"line": 7,
12+
"event": "warning[SC2034]",
13+
"message": "UNUSED_VAR2 appears unused. Verify use (or export if used externally).",
14+
"verbosity_level": 0
15+
}
16+
]
17+
},
18+
{
19+
"checker": "SHELLCHECK_WARNING",
20+
"language": "shell",
21+
"tool": "shellcheck",
22+
"key_event_idx": 0,
23+
"events": [
24+
{
25+
"file_name": "innocent-script.sh",
26+
"line": 11,
27+
"event": "warning[SC2115]",
28+
"message": "Use \"${var:?}\" to ensure this never expands to / .",
29+
"verbosity_level": 0
30+
}
31+
]
32+
},
33+
{
34+
"checker": "SHELLCHECK_WARNING",
35+
"language": "shell",
36+
"tool": "shellcheck",
37+
"key_event_idx": 0,
38+
"events": [
39+
{
40+
"file_name": "innocent-script.sh",
41+
"line": 11,
42+
"event": "warning[SC2115]",
43+
"message": "Use \"${var:?}\" to ensure this never expands to / .",
44+
"verbosity_level": 0
45+
}
46+
]
47+
}
48+
]
49+
}
+210
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
{
2+
"$schema": "https://json.schemastore.org/sarif-2.1.0.json",
3+
"version": "2.1.0",
4+
"inlineExternalProperties": [
5+
{
6+
"externalizedProperties": {
7+
"tool": "ShellCheck",
8+
"tool-url": "https://www.shellcheck.net/wiki/",
9+
"tool-version": "0.9.0"
10+
}
11+
}
12+
],
13+
"runs": [
14+
{
15+
"tool": {
16+
"driver": {
17+
"name": "ShellCheck",
18+
"version": "0.9.0",
19+
"informationUri": "https://www.shellcheck.net/wiki/",
20+
"rules": [
21+
{
22+
"id": "SHELLCHECK_WARNING: warning[SC2034]",
23+
"properties": {
24+
"tags": [
25+
"ShellCheck"
26+
]
27+
},
28+
"name": "SC2034",
29+
"help": {
30+
"text": "Defect reference: https://github.com/koalaman/shellcheck/wiki/SC2034",
31+
"markdown": "Defect reference: [SC2034](https://github.com/koalaman/shellcheck/wiki/SC2034)"
32+
}
33+
},
34+
{
35+
"id": "SHELLCHECK_WARNING: warning[SC2115]",
36+
"properties": {
37+
"tags": [
38+
"ShellCheck"
39+
]
40+
},
41+
"name": "SC2115",
42+
"help": {
43+
"text": "Defect reference: https://github.com/koalaman/shellcheck/wiki/SC2115",
44+
"markdown": "Defect reference: [SC2115](https://github.com/koalaman/shellcheck/wiki/SC2115)"
45+
}
46+
}
47+
]
48+
}
49+
},
50+
"results": [
51+
{
52+
"ruleId": "SHELLCHECK_WARNING: warning[SC2034]",
53+
"level": "warning",
54+
"locations": [
55+
{
56+
"id": 0,
57+
"physicalLocation": {
58+
"artifactLocation": {
59+
"uri": "innocent-script.sh"
60+
},
61+
"region": {
62+
"startLine": 7,
63+
"endLine": 7
64+
}
65+
}
66+
}
67+
],
68+
"message": {
69+
"text": "UNUSED_VAR2 appears unused. Verify use (or export if used externally)."
70+
},
71+
"codeFlows": [
72+
{
73+
"threadFlows": [
74+
{
75+
"locations": [
76+
{
77+
"location": {
78+
"id": 0,
79+
"physicalLocation": {
80+
"artifactLocation": {
81+
"uri": "innocent-script.sh"
82+
},
83+
"region": {
84+
"startLine": 7,
85+
"endLine": 7
86+
}
87+
},
88+
"message": {
89+
"text": "UNUSED_VAR2 appears unused. Verify use (or export if used externally)."
90+
}
91+
},
92+
"nestingLevel": 0,
93+
"kinds": [
94+
"warning[SC2034]"
95+
]
96+
}
97+
]
98+
}
99+
]
100+
}
101+
]
102+
},
103+
{
104+
"ruleId": "SHELLCHECK_WARNING: warning[SC2115]",
105+
"level": "warning",
106+
"locations": [
107+
{
108+
"id": 0,
109+
"physicalLocation": {
110+
"artifactLocation": {
111+
"uri": "innocent-script.sh"
112+
},
113+
"region": {
114+
"startLine": 11,
115+
"endLine": 11
116+
}
117+
}
118+
}
119+
],
120+
"message": {
121+
"text": "Use \"${var:?}\" to ensure this never expands to / ."
122+
},
123+
"codeFlows": [
124+
{
125+
"threadFlows": [
126+
{
127+
"locations": [
128+
{
129+
"location": {
130+
"id": 0,
131+
"physicalLocation": {
132+
"artifactLocation": {
133+
"uri": "innocent-script.sh"
134+
},
135+
"region": {
136+
"startLine": 11,
137+
"endLine": 11
138+
}
139+
},
140+
"message": {
141+
"text": "Use \"${var:?}\" to ensure this never expands to / ."
142+
}
143+
},
144+
"nestingLevel": 0,
145+
"kinds": [
146+
"warning[SC2115]"
147+
]
148+
}
149+
]
150+
}
151+
]
152+
}
153+
]
154+
},
155+
{
156+
"ruleId": "SHELLCHECK_WARNING: warning[SC2115]",
157+
"level": "warning",
158+
"locations": [
159+
{
160+
"id": 0,
161+
"physicalLocation": {
162+
"artifactLocation": {
163+
"uri": "innocent-script.sh"
164+
},
165+
"region": {
166+
"startLine": 11,
167+
"endLine": 11
168+
}
169+
}
170+
}
171+
],
172+
"message": {
173+
"text": "Use \"${var:?}\" to ensure this never expands to / ."
174+
},
175+
"codeFlows": [
176+
{
177+
"threadFlows": [
178+
{
179+
"locations": [
180+
{
181+
"location": {
182+
"id": 0,
183+
"physicalLocation": {
184+
"artifactLocation": {
185+
"uri": "innocent-script.sh"
186+
},
187+
"region": {
188+
"startLine": 11,
189+
"endLine": 11
190+
}
191+
},
192+
"message": {
193+
"text": "Use \"${var:?}\" to ensure this never expands to / ."
194+
}
195+
},
196+
"nestingLevel": 0,
197+
"kinds": [
198+
"warning[SC2115]"
199+
]
200+
}
201+
]
202+
}
203+
]
204+
}
205+
]
206+
}
207+
]
208+
}
209+
]
210+
}

test/generate_SARIF.bats

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# SPDX-License-Identifier: GPL-3.0-or-later
2+
3+
setup_file () {
4+
load 'test_helper/common-setup'
5+
_common_setup
6+
}
7+
8+
setup () {
9+
load 'test_helper/bats-assert/load'
10+
load 'test_helper/bats-support/load'
11+
load 'test_helper/bats-file/load'
12+
}
13+
14+
@test "generate_SARIF() - arguments" {
15+
source "${PROJECT_ROOT}/src/functions.sh"
16+
17+
run generate_SARIF
18+
assert_failure 1
19+
20+
run generate_SARIF "./test/fixtures/generate_SARIF/defects.log"
21+
assert_failure 1
22+
23+
run generate_SARIF "./test/fixtures/generate_SARIF/defects.log" "test.sarif"
24+
assert_success
25+
}
26+
27+
@test "generate_SARIF()" {
28+
source "${PROJECT_ROOT}/src/functions.sh"
29+
30+
run generate_SARIF "./test/fixtures/generate_SARIF/defects.log" "./test.sarif"
31+
assert_success
32+
assert_exists "./test.sarif"
33+
34+
run cmp -s "test.sarif" "./test/fixtures/generate_SARIF/test.sarif"
35+
assert_success
36+
}
37+
38+
teardown () {
39+
rm -f test.sarif
40+
}

0 commit comments

Comments
 (0)