Skip to content

Commit d9e144e

Browse files
committed
add test for shared config
1 parent 80501d0 commit d9e144e

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

crates/ruff/tests/lint.rs

+76
Original file line numberDiff line numberDiff line change
@@ -2339,6 +2339,82 @@ from typing import Union;foo: Union[int, str] = 1
23392339
Ok(())
23402340
}
23412341

2342+
/// ```
2343+
/// tmp
2344+
/// ├── pyproject.toml <-- requires >=3.9
2345+
/// ├── ruff.toml <--- extends base
2346+
/// ├── shared
2347+
/// │   └── base_config.toml <-- targets 3.10
2348+
/// └── test.py
2349+
/// ```
2350+
#[test]
2351+
fn requires_python_extend_from_shared_config() -> Result<()> {
2352+
let tempdir = TempDir::new()?;
2353+
let project_dir = tempdir.path().canonicalize()?;
2354+
let ruff_toml = tempdir.path().join("ruff.toml");
2355+
fs::write(
2356+
&ruff_toml,
2357+
r#"
2358+
extend = "./shared/base_config.toml"
2359+
[lint]
2360+
select = ["UP007"]
2361+
"#,
2362+
)?;
2363+
2364+
let shared_dir = tempdir.path().join("shared");
2365+
fs::create_dir(shared_dir)?;
2366+
2367+
let pyproject_toml = tempdir.path().join("pyproject.toml");
2368+
fs::write(
2369+
&pyproject_toml,
2370+
r#"[project]
2371+
requires-python = ">= 3.9"
2372+
"#,
2373+
)?;
2374+
2375+
let shared_toml = tempdir.path().join("shared/base_config.toml");
2376+
fs::write(
2377+
&shared_toml,
2378+
r#"
2379+
target-version = "py310"
2380+
"#,
2381+
)?;
2382+
2383+
let testpy = tempdir.path().join("test.py");
2384+
fs::write(
2385+
&testpy,
2386+
r#"
2387+
from typing import Union;foo: Union[int, str] = 1
2388+
"#,
2389+
)?;
2390+
2391+
let testpy_canon = testpy.canonicalize()?;
2392+
2393+
insta::with_settings!({
2394+
filters => vec![(tempdir_filter(&testpy_canon).as_str(), "[TMP]/test.py"),(tempdir_filter(&project_dir).as_str(), "[TMP]/"),(r"(?m)\n.*\[ruff::commands::check\].*$",""),(r"(?m)^.*(\[.*\])\[DEBUG\](.*)$","$1[DEBUG]$2")]
2395+
}, {
2396+
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
2397+
.args(STDIN_BASE_OPTIONS)
2398+
.arg("-v")
2399+
.arg("test.py")
2400+
.current_dir(&project_dir), @r###"
2401+
success: true
2402+
exit_code: 0
2403+
----- stdout -----
2404+
All checks passed!
2405+
2406+
----- stderr -----
2407+
[ruff::resolve][DEBUG] Using configuration file (via parent) at: [TMP]/ruff.toml
2408+
[ruff_workspace::pyproject][DEBUG] No `target-version` found in `ruff.toml`
2409+
[ruff_workspace::pyproject][DEBUG] Detected minimum supported `requires-python` version: 3.9
2410+
[ruff_workspace::pyproject][DEBUG] Derived `target-version` from `requires-python` in `pyproject.toml`
2411+
[ruff::diagnostics][DEBUG] Checking: [TMP]/test.py
2412+
"###);
2413+
});
2414+
2415+
Ok(())
2416+
}
2417+
23422418
#[test]
23432419
fn checks_notebooks_in_stable() -> anyhow::Result<()> {
23442420
let tempdir = TempDir::new()?;

0 commit comments

Comments
 (0)