mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:48:32 +00:00
show-settings: Properly filter out backslashes on windows (#15612)
<!-- Thank you for contributing to Ruff! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary <!-- What's the purpose of the change? What does it do, and why? --> ## Test Plan <!-- How was it tested? -->
This commit is contained in:
parent
36c90ebe86
commit
80345e72c4
1 changed files with 11 additions and 12 deletions
|
@ -1,5 +1,6 @@
|
|||
use anyhow::Context;
|
||||
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
use tempfile::TempDir;
|
||||
|
||||
|
@ -11,7 +12,10 @@ fn display_default_settings() -> anyhow::Result<()> {
|
|||
|
||||
// Tempdir path's on macos are symlinks, which doesn't play nicely with
|
||||
// our snapshot filtering.
|
||||
let project_dir = tempdir.path();
|
||||
let project_dir = tempdir
|
||||
.path()
|
||||
.canonicalize()
|
||||
.context("Failed to canonical tempdir path.")?;
|
||||
|
||||
std::fs::write(
|
||||
project_dir.join("pyproject.toml"),
|
||||
|
@ -36,7 +40,10 @@ ignore = [
|
|||
std::fs::write(project_dir.join("test.py"), r#"print("Hello")"#)
|
||||
.context("Failed to write test.py.")?;
|
||||
|
||||
insta::with_settings!({filters => vec![(&*tempdir_filter(&tempdir)?, "<temp_dir>/")]}, {
|
||||
insta::with_settings!({filters => vec![
|
||||
(&*tempdir_filter(&project_dir), "<temp_dir>/"),
|
||||
(r#"\\(\w\w|\s|\.|")"#, "/$1"),
|
||||
]}, {
|
||||
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
|
||||
.args(["check", "--show-settings", "test.py"])
|
||||
.current_dir(project_dir));
|
||||
|
@ -45,14 +52,6 @@ ignore = [
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn tempdir_filter(tempdir: &TempDir) -> anyhow::Result<String> {
|
||||
let project_dir = tempdir
|
||||
.path()
|
||||
.canonicalize()
|
||||
.context("Failed to canonical tempdir path.")?;
|
||||
|
||||
Ok(format!(
|
||||
r#"{}\\?/?"#,
|
||||
regex::escape(project_dir.to_str().unwrap())
|
||||
))
|
||||
fn tempdir_filter(project_dir: &Path) -> String {
|
||||
format!(r#"{}\\?/?"#, regex::escape(project_dir.to_str().unwrap()))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue