mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 06:41:23 +00:00
[Minor] Improve the style of some tests in crates/ruff/tests/format.rs
(#10132)
This commit is contained in:
parent
0421c41ff7
commit
14fa1c5b52
1 changed files with 42 additions and 34 deletions
|
@ -7,10 +7,15 @@ use std::str;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
|
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
|
||||||
|
use regex::escape;
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
const BIN_NAME: &str = "ruff";
|
const BIN_NAME: &str = "ruff";
|
||||||
|
|
||||||
|
fn tempdir_filter(tempdir: &TempDir) -> String {
|
||||||
|
format!(r"{}\\?/?", escape(tempdir.path().to_str().unwrap()))
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn default_options() {
|
fn default_options() {
|
||||||
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
|
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
|
||||||
|
@ -147,28 +152,29 @@ fn too_many_config_files() -> Result<()> {
|
||||||
let ruff2_dot_toml = tempdir.path().join("ruff2.toml");
|
let ruff2_dot_toml = tempdir.path().join("ruff2.toml");
|
||||||
fs::File::create(&ruff_dot_toml)?;
|
fs::File::create(&ruff_dot_toml)?;
|
||||||
fs::File::create(&ruff2_dot_toml)?;
|
fs::File::create(&ruff2_dot_toml)?;
|
||||||
let expected_stderr = format!(
|
insta::with_settings!({
|
||||||
"\
|
filters => vec![(tempdir_filter(&tempdir).as_str(), "[TMP]/")]
|
||||||
ruff failed
|
}, {
|
||||||
Cause: You cannot specify more than one configuration file on the command line.
|
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
|
||||||
|
|
||||||
tip: remove either `--config={}` or `--config={}`.
|
|
||||||
For more information, try `--help`.
|
|
||||||
|
|
||||||
",
|
|
||||||
ruff_dot_toml.display(),
|
|
||||||
ruff2_dot_toml.display(),
|
|
||||||
);
|
|
||||||
let cmd = Command::new(get_cargo_bin(BIN_NAME))
|
|
||||||
.arg("format")
|
.arg("format")
|
||||||
.arg("--config")
|
.arg("--config")
|
||||||
.arg(&ruff_dot_toml)
|
.arg(&ruff_dot_toml)
|
||||||
.arg("--config")
|
.arg("--config")
|
||||||
.arg(&ruff2_dot_toml)
|
.arg(&ruff2_dot_toml)
|
||||||
.arg(".")
|
.arg("."), @r###"
|
||||||
.output()?;
|
success: false
|
||||||
let stderr = std::str::from_utf8(&cmd.stderr)?;
|
exit_code: 2
|
||||||
assert_eq!(stderr, expected_stderr);
|
----- stdout -----
|
||||||
|
|
||||||
|
----- stderr -----
|
||||||
|
ruff failed
|
||||||
|
Cause: You cannot specify more than one configuration file on the command line.
|
||||||
|
|
||||||
|
tip: remove either `--config=[TMP]/ruff.toml` or `--config=[TMP]/ruff2.toml`.
|
||||||
|
For more information, try `--help`.
|
||||||
|
|
||||||
|
"###);
|
||||||
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,27 +183,29 @@ fn config_file_and_isolated() -> Result<()> {
|
||||||
let tempdir = TempDir::new()?;
|
let tempdir = TempDir::new()?;
|
||||||
let ruff_dot_toml = tempdir.path().join("ruff.toml");
|
let ruff_dot_toml = tempdir.path().join("ruff.toml");
|
||||||
fs::File::create(&ruff_dot_toml)?;
|
fs::File::create(&ruff_dot_toml)?;
|
||||||
let expected_stderr = format!(
|
insta::with_settings!({
|
||||||
"\
|
filters => vec![(tempdir_filter(&tempdir).as_str(), "[TMP]/")]
|
||||||
ruff failed
|
}, {
|
||||||
Cause: The argument `--config={}` cannot be used with `--isolated`
|
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
|
||||||
|
|
||||||
tip: You cannot specify a configuration file and also specify `--isolated`,
|
|
||||||
as `--isolated` causes ruff to ignore all configuration files.
|
|
||||||
For more information, try `--help`.
|
|
||||||
|
|
||||||
",
|
|
||||||
ruff_dot_toml.display(),
|
|
||||||
);
|
|
||||||
let cmd = Command::new(get_cargo_bin(BIN_NAME))
|
|
||||||
.arg("format")
|
.arg("format")
|
||||||
.arg("--config")
|
.arg("--config")
|
||||||
.arg(&ruff_dot_toml)
|
.arg(&ruff_dot_toml)
|
||||||
.arg("--isolated")
|
.arg("--isolated")
|
||||||
.arg(".")
|
.arg("."), @r###"
|
||||||
.output()?;
|
success: false
|
||||||
let stderr = std::str::from_utf8(&cmd.stderr)?;
|
exit_code: 2
|
||||||
assert_eq!(stderr, expected_stderr);
|
----- stdout -----
|
||||||
|
|
||||||
|
----- stderr -----
|
||||||
|
ruff failed
|
||||||
|
Cause: The argument `--config=[TMP]/ruff.toml` cannot be used with `--isolated`
|
||||||
|
|
||||||
|
tip: You cannot specify a configuration file and also specify `--isolated`,
|
||||||
|
as `--isolated` causes ruff to ignore all configuration files.
|
||||||
|
For more information, try `--help`.
|
||||||
|
|
||||||
|
"###);
|
||||||
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue