@@ -131,6 +131,11 @@ fn exit_0_without_a_valid_report_is_not_a_run() {
131131/// `assail` prints REAL, `assay` writes `ASSAY_JSON` to its `-o` path,
132132/// `--version` and `diagnostics` answer.
133133fn full_stub_body ( assay_json : & str ) -> String {
134+ stub_body_with_report ( assay_json, REAL )
135+ }
136+
137+ /// As `full_stub_body`, but `assail` prints `report` instead of REAL.
138+ fn stub_body_with_report ( assay_json : & str , report : & str ) -> String {
134139 format ! (
135140 r#"case "$1" in
136141 --version) echo "panic-attack 2.5.5" ;;
@@ -143,7 +148,7 @@ fn full_stub_body(assay_json: &str) -> String {
143148J
144149 ;;
145150 *) cat <<'J'
146- {REAL }
151+ {report }
147152J
148153 ;;
149154esac
@@ -750,3 +755,55 @@ fn staggered_pipe_holders_share_one_deadline() {
750755 ) ;
751756 assert ! ( !o. status. success( ) ) ;
752757}
758+
759+ /// One weak point at each panic-attack severity level.
760+ const ALL_LEVELS : & str = r#"Running assail analysis on: .
761+ {"program_path":"/t","language":"rust","statistics":{"total_lines":40},"weak_points":[
762+ {"category":"UnsafeCode","location":"a.rs:1","severity":"Critical","description":"c"},
763+ {"category":"UnsafeCode","location":"a.rs:2","severity":"High","description":"h"},
764+ {"category":"UnsafeCode","location":"a.rs:3","severity":"Medium","description":"m"},
765+ {"category":"UnsafeCode","location":"a.rs:4","severity":"Low","description":"l"}]}"# ;
766+
767+ /// `panicbot --format json scan` reports panic-attack's own severity word, so
768+ /// the verdict grid grades panicbot's row exactly as it grades the direct
769+ /// panic-attack row. Before this, panicbot printed the fleet word (`error` for
770+ /// a Critical), which the grid reads as `high`: every finding read one level
771+ /// milder, though both rows ran the same panic-attack revision.
772+ #[ test]
773+ fn json_scan_reports_panic_attack_severity_at_every_level ( ) {
774+ let bin = TempDir :: new ( ) . unwrap ( ) ;
775+ stub ( bin. path ( ) , & stub_body_with_report ( ASSAY_NONE , ALL_LEVELS ) ) ;
776+ let tree = TempDir :: new ( ) . unwrap ( ) ;
777+ fs:: write ( tree. path ( ) . join ( "a.rs" ) , "fn main() {}\n " ) . unwrap ( ) ;
778+
779+ let o = scan ( bin. path ( ) , tree. path ( ) ) ;
780+ // A Critical blocks release (fleet `error`), so exit 1 with a findings array.
781+ assert_eq ! (
782+ o. status. code( ) ,
783+ Some ( 1 ) ,
784+ "stderr: {}" ,
785+ String :: from_utf8_lossy( & o. stderr)
786+ ) ;
787+ let v: serde_json:: Value = serde_json:: from_slice ( & o. stdout ) . expect ( "a findings array" ) ;
788+ let mut got: Vec < ( u64 , & str , & str ) > = v
789+ . as_array ( )
790+ . unwrap ( )
791+ . iter ( )
792+ . filter ( |f| f[ "rule_id" ] . as_str ( ) . unwrap ( ) . starts_with ( "PA" ) )
793+ . map ( |f| {
794+ (
795+ f[ "line" ] . as_u64 ( ) . unwrap ( ) ,
796+ f[ "severity" ] . as_str ( ) . unwrap ( ) ,
797+ f[ "fleet_severity" ] . as_str ( ) . unwrap ( ) ,
798+ )
799+ } )
800+ . collect ( ) ;
801+ got. sort ( ) ;
802+ let want = vec ! [
803+ ( 1 , "critical" , "error" ) ,
804+ ( 2 , "high" , "warning" ) ,
805+ ( 3 , "medium" , "info" ) ,
806+ ( 4 , "low" , "suggestion" ) ,
807+ ] ;
808+ assert_eq ! ( got, want, "{v}" ) ;
809+ }
0 commit comments