Skip to content

Commit

Permalink
Fix snapshots on Windows?
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Feb 1, 2024
1 parent d467bc6 commit f46c2e4
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions crates/ruff/tests/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#![cfg(not(target_family = "wasm"))]

use regex::escape;
use std::fs;
use std::process::Command;
use std::str;
Expand All @@ -13,6 +14,10 @@ use tempfile::TempDir;
const BIN_NAME: &str = "ruff";
const STDIN_BASE_OPTIONS: &[&str] = &["--no-cache", "--output-format", "concise"];

fn tempdir_filter(tempdir: &TempDir) -> String {
format!(r"{}\\?/?", escape(tempdir.path().to_str().unwrap()))
}

#[test]
fn top_level_options() -> Result<()> {
let tempdir = TempDir::new()?;
Expand All @@ -28,7 +33,7 @@ inline-quotes = "single"
)?;

insta::with_settings!({
filters => vec![(tempdir.path().to_str().unwrap(), "[TMP]")]
filters => vec![(tempdir_filter(&tempdir).as_str(), "[TMP]/")]
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.args(STDIN_BASE_OPTIONS)
Expand Down Expand Up @@ -72,7 +77,7 @@ inline-quotes = "single"
)?;

insta::with_settings!({
filters => vec![(tempdir.path().to_str().unwrap(), "[TMP]")]
filters => vec![(tempdir_filter(&tempdir).as_str(), "[TMP]/")]
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.args(STDIN_BASE_OPTIONS)
Expand Down Expand Up @@ -112,7 +117,7 @@ inline-quotes = "single"
)?;

insta::with_settings!({
filters => vec![(tempdir.path().to_str().unwrap(), "[TMP]")]
filters => vec![(tempdir_filter(&tempdir).as_str(), "[TMP]/")]
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.args(STDIN_BASE_OPTIONS)
Expand Down Expand Up @@ -158,7 +163,7 @@ inline-quotes = "single"
)?;

insta::with_settings!({
filters => vec![(tempdir.path().to_str().unwrap(), "[TMP]")]
filters => vec![(tempdir_filter(&tempdir).as_str(), "[TMP]/")]
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.args(STDIN_BASE_OPTIONS)
Expand Down Expand Up @@ -237,7 +242,7 @@ OTHER = "OTHER"
fs::write(out_dir.join("a.py"), r#"a = "a""#)?;

insta::with_settings!({
filters => vec![(tempdir.path().to_str().unwrap(), "[TMP]")]
filters => vec![(tempdir_filter(&tempdir).as_str(), "[TMP]/")]
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.current_dir(tempdir.path())
Expand Down Expand Up @@ -284,7 +289,7 @@ inline-quotes = "single"
)?;

insta::with_settings!({
filters => vec![(tempdir.path().to_str().unwrap(), "[TMP]")]
filters => vec![(tempdir_filter(&tempdir).as_str(), "[TMP]/")]
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.current_dir(tempdir.path())
Expand Down Expand Up @@ -332,7 +337,7 @@ max-line-length = 100
)?;

insta::with_settings!({
filters => vec![(tempdir.path().to_str().unwrap(), "[TMP]")]
filters => vec![(tempdir_filter(&tempdir).as_str(), "[TMP]/")]
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.args(STDIN_BASE_OPTIONS)
Expand Down Expand Up @@ -377,7 +382,7 @@ inline-quotes = "single"
)?;

insta::with_settings!({
filters => vec![(tempdir.path().to_str().unwrap(), "[TMP]")]
filters => vec![(tempdir_filter(&tempdir).as_str(), "[TMP]/")]
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.current_dir(tempdir.path())
Expand Down Expand Up @@ -426,7 +431,7 @@ inline-quotes = "single"
)?;

insta::with_settings!({
filters => vec![(tempdir.path().to_str().unwrap(), "[TMP]")]
filters => vec![(tempdir_filter(&tempdir).as_str(), "[TMP]/")]
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.current_dir(tempdir.path())
Expand Down Expand Up @@ -486,7 +491,7 @@ ignore = ["D203", "D212"]
)?;

insta::with_settings!({
filters => vec![(tempdir.path().to_str().unwrap(), "[TMP]")]
filters => vec![(tempdir_filter(&tempdir).as_str(), "[TMP]/")]
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.current_dir(sub_dir)
Expand Down Expand Up @@ -559,7 +564,7 @@ include = ["*.ipy"]
)?;

insta::with_settings!({
filters => vec![(tempdir.path().to_str().unwrap(), "[TMP]")]
filters => vec![(tempdir_filter(&tempdir).as_str(), "[TMP]/")]
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.current_dir(tempdir.path())
Expand Down

0 comments on commit f46c2e4

Please sign in to comment.