From 1e2ca10b81345dec1757533691fc0c47fab20ced Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Mon, 24 Jun 2024 14:03:45 +0200 Subject: [PATCH] Add test for JSON output --- crates/ruff/tests/integration_test.rs | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/crates/ruff/tests/integration_test.rs b/crates/ruff/tests/integration_test.rs index 451bb6acc5982..60abf067cac99 100644 --- a/crates/ruff/tests/integration_test.rs +++ b/crates/ruff/tests/integration_test.rs @@ -860,6 +860,35 @@ fn show_statistics() { "###); } +#[test] +fn show_statistics_json() { + let mut cmd = RuffCheck::default() + .args([ + "--select", + "F401", + "--statistics", + "--output-format", + "json", + ]) + .build(); + assert_cmd_snapshot!(cmd + .pass_stdin("import sys\nimport os\n\nprint(os.getuid())\n"), @r###" + success: false + exit_code: 1 + ----- stdout ----- + [ + { + "code": "F401", + "name": "unused-import", + "count": 1, + "fixable": true + } + ] + + ----- stderr ----- + "###); +} + #[test] fn nursery_prefix() { // Should only detect RUF90X, but not the unstable test rules