From 0bf74535621d511b7cf6eff87475872947224dab Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Thu, 23 Jan 2025 10:11:39 +0100 Subject: [PATCH] Fix `rule_severity` test --- crates/red_knot/tests/cli.rs | 40 ++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/crates/red_knot/tests/cli.rs b/crates/red_knot/tests/cli.rs index 2156c787452a0..3cdf906d04824 100644 --- a/crates/red_knot/tests/cli.rs +++ b/crates/red_knot/tests/cli.rs @@ -194,22 +194,12 @@ fn rule_severity() -> anyhow::Result<()> { let project_dir = tempdir.path().canonicalize()?; - std::fs::write( - project_dir.join("pyproject.toml"), - r#" -[tool.knot.rules] -division-by-zero = "warn" # demote to warn -possibly-unresolved-reference = "ignore" -"#, - ) - .context("Failed to write `pyproject.toml`")?; - std::fs::write( project_dir.join("test.py"), r#" -y = x / 0 +y = 4 / 0 -for a in range(0, 1): +for a in range(0, y): x = a print(x) # possibly-unresolved-reference @@ -217,12 +207,36 @@ print(x) # possibly-unresolved-reference ) .context("Failed to write `test.py`")?; + // Assert that there's a possibly unresolved reference diagnostic + // and that division-by-zero has a severity of error by default. + insta::with_settings!({filters => vec![(&*tempdir_filter(&project_dir), "/")]}, { + assert_cmd_snapshot!(knot().current_dir(&project_dir), @r" + success: false + exit_code: 1 + ----- stdout ----- + error[lint:division-by-zero] /test.py:2:5 Cannot divide object of type `Literal[4]` by zero + warning[lint:possibly-unresolved-reference] /test.py:7:7 Name `x` used when possibly not defined + + ----- stderr ----- + "); + }); + + std::fs::write( + project_dir.join("pyproject.toml"), + r#" +[tool.knot.rules] +division-by-zero = "warn" # demote to warn +possibly-unresolved-reference = "ignore" +"#, + ) + .context("Failed to write `pyproject.toml`")?; + insta::with_settings!({filters => vec![(&*tempdir_filter(&project_dir), "/")]}, { assert_cmd_snapshot!(knot().current_dir(project_dir), @r" success: false exit_code: 1 ----- stdout ----- - warning[lint:unresolved-reference] /test.py:2:5 Name `x` used when not defined + warning[lint:division-by-zero] /test.py:2:5 Cannot divide object of type `Literal[4]` by zero ----- stderr ----- ");