-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support a human readable output format (#41)
Adds `--output-format=sarif|text` (default `sarif`) to allow us to produce more readable outputs. For now it's just `path:line:col msg (severity)`
- Loading branch information
1 parent
79518f6
commit 8488856
Showing
7 changed files
with
226 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{ | ||
"runs": [ | ||
{ | ||
"results": [ | ||
{ | ||
"level": "error", | ||
"locations": [ | ||
{ | ||
"physicalLocation": { | ||
"artifactLocation": { | ||
"uri": "alpha.foo" | ||
}, | ||
"region": { | ||
"endColumn": 12, | ||
"endLine": 2, | ||
"startColumn": 1, | ||
"startLine": 2 | ||
} | ||
} | ||
} | ||
], | ||
"message": { | ||
"text": "Found 'do-NOT-lAnD'" | ||
}, | ||
"ruleId": "do-not-land" | ||
}, | ||
{ | ||
"level": "error", | ||
"locations": [ | ||
{ | ||
"physicalLocation": { | ||
"artifactLocation": { | ||
"uri": "alpha.foo" | ||
}, | ||
"region": { | ||
"endColumn": 10, | ||
"endLine": 3, | ||
"startColumn": 1, | ||
"startLine": 3 | ||
} | ||
} | ||
} | ||
], | ||
"message": { | ||
"text": "Found 'DONOTLAND'" | ||
}, | ||
"ruleId": "do-not-land" | ||
}, | ||
{ | ||
"level": "note", | ||
"message": { | ||
"text": "1 files processed in ms" | ||
}, | ||
"ruleId": "toolbox-perf" | ||
} | ||
], | ||
"tool": { | ||
"driver": { | ||
"name": "trunk-toolbox" | ||
} | ||
} | ||
} | ||
], | ||
"version": "2.1.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// trunk-ignore-all(trunk-toolbox/do-not-land) | ||
extern crate regex; | ||
|
||
use spectral::prelude::*; | ||
use std::fs; | ||
use std::path::Path; | ||
|
||
use regex::Regex; | ||
mod integration_testing; | ||
use integration_testing::TestRepo; | ||
|
||
#[test] | ||
fn default_sarif() -> anyhow::Result<()> { | ||
let test_repo = TestRepo::make()?; | ||
|
||
let expected_file = Path::new(file!()).parent().unwrap().join("output.sarif"); | ||
let expected_sarif = fs::read_to_string(expected_file)?; | ||
|
||
test_repo.write( | ||
"alpha.foo", | ||
"lorem ipsum dolor\ndo-NOT-lAnD\nDONOTLAND sit amet\n".as_bytes(), | ||
); | ||
test_repo.git_add_all()?; | ||
let horton = test_repo.run_horton()?; | ||
|
||
let re = Regex::new(r"\d+\.\d+ms").unwrap(); | ||
let normalized_output = re.replace(&horton.stdout, "ms"); | ||
|
||
assert_that(&horton.exit_code).contains_value(0); | ||
assert_that(&normalized_output.to_string()).is_equal_to(expected_sarif); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn default_print() -> anyhow::Result<()> { | ||
let test_repo = TestRepo::make()?; | ||
|
||
test_repo.write( | ||
"alpha.foo", | ||
"lorem ipsum dolor\ndo-NOT-lAnD\nDONOTLAND sit amet\n".as_bytes(), | ||
); | ||
test_repo.git_add_all()?; | ||
let horton = test_repo.run_horton_with("HEAD", "text")?; | ||
let expected_text = String::from( | ||
"alpha.foo:1:0: Found 'do-NOT-lAnD' (error)\nalpha.foo:2:0: Found 'DONOTLAND' (error)\n", | ||
); | ||
|
||
assert_that(&horton.exit_code).contains_value(0); | ||
assert_that(&horton.stdout).is_equal_to(&expected_text); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters