Skip to content

Commit fe1f437

Browse files
Add tests for case where pyproject.toml exists.
1 parent 6b02f75 commit fe1f437

2 files changed

Lines changed: 57 additions & 4 deletions

File tree

  • crates/ruff_linter

crates/ruff_linter/resources/test/fixtures/flake8_executable/pyproject.toml

Whitespace-only changes.

crates/ruff_linter/src/rules/flake8_executable/mod.rs

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mod tests {
1111
use test_case::test_case;
1212

1313
use crate::registry::Rule;
14-
use crate::test::test_path;
14+
use crate::test::{test_path, test_resource_path};
1515
use crate::{assert_diagnostics, settings};
1616

1717
#[cfg_attr(
@@ -45,19 +45,72 @@ mod tests {
4545
#[test_case(Path::new("EXE005_1.py"))]
4646
#[test_case(Path::new("EXE005_2.py"))]
4747
#[test_case(Path::new("EXE005_3.py"))]
48-
fn rules(path: &Path) -> Result<()> {
48+
fn rules_no_pyproject_toml(path: &Path) -> Result<()> {
4949
let snapshot = path.to_string_lossy().into_owned();
50+
let settings = settings::LinterSettings::for_rules(vec![
51+
Rule::ShebangNotExecutable,
52+
Rule::ShebangMissingExecutableFile,
53+
Rule::ShebangLeadingWhitespace,
54+
Rule::ShebangNotFirstLine,
55+
Rule::ShebangMissingPython,
56+
]);
57+
assert!(!&settings.project_root.join("pyproject.toml").exists(), "unexpected pyproject.toml found: {}", &settings.project_root.join("pyproject.toml").to_string_lossy());
5058
let diagnostics = test_path(
5159
Path::new("flake8_executable").join(path).as_path(),
52-
&settings::LinterSettings::for_rules(vec![
60+
&settings,
61+
)?;
62+
assert_diagnostics!(snapshot, diagnostics);
63+
Ok(())
64+
}
65+
66+
#[cfg_attr(
67+
all(unix, not(test_environment = "ntfs")),
68+
test_case(Path::new("EXE001_1.py"))
69+
)]
70+
#[cfg_attr(
71+
any(windows, test_environment = "ntfs"),
72+
test_case(Path::new("EXE001_1_ntfs.py"))
73+
)]
74+
#[test_case(Path::new("EXE001_2.py"))]
75+
#[test_case(Path::new("EXE001_3.py"))]
76+
#[cfg_attr(
77+
all(unix, not(test_environment = "ntfs")),
78+
test_case(Path::new("EXE002_1.py"))
79+
)]
80+
#[cfg_attr(
81+
any(windows, test_environment = "ntfs"),
82+
test_case(Path::new("EXE002_1_ntfs.py"))
83+
)]
84+
#[test_case(Path::new("EXE002_2.py"))]
85+
#[test_case(Path::new("EXE002_3.py"))]
86+
#[test_case(Path::new("EXE003.py"))]
87+
#[test_case(Path::new("EXE003_uv.py"))]
88+
#[test_case(Path::new("EXE003_uv_tool.py"))]
89+
#[test_case(Path::new("EXE003_uvx.py"))]
90+
#[test_case(Path::new("EXE004_1.py"))]
91+
#[test_case(Path::new("EXE004_2.py"))]
92+
#[test_case(Path::new("EXE004_3.py"))]
93+
#[test_case(Path::new("EXE004_4.py"))]
94+
#[test_case(Path::new("EXE005_1.py"))]
95+
#[test_case(Path::new("EXE005_2.py"))]
96+
#[test_case(Path::new("EXE005_3.py"))]
97+
fn rules_with_pyproject_toml(path: &Path) -> Result<()> {
98+
let snapshot = path.to_string_lossy().into_owned();
99+
let mut settings = settings::LinterSettings::for_rules(vec![
53100
Rule::ShebangNotExecutable,
54101
Rule::ShebangMissingExecutableFile,
55102
Rule::ShebangLeadingWhitespace,
56103
Rule::ShebangNotFirstLine,
57104
Rule::ShebangMissingPython,
58-
]),
105+
]);
106+
settings.project_root = test_resource_path("fixtures").join("flake8_executable");
107+
assert!(&settings.project_root.join("pyproject.toml").exists(), "{} not found", &settings.project_root.join("pyproject.toml").to_string_lossy());
108+
let diagnostics = test_path(
109+
Path::new("flake8_executable").join(path).as_path(),
110+
&settings,
59111
)?;
60112
assert_diagnostics!(snapshot, diagnostics);
61113
Ok(())
62114
}
115+
63116
}

0 commit comments

Comments
 (0)