From 40ee4909b5264b531d11910cddc5060e799b3916 Mon Sep 17 00:00:00 2001 From: Nicholas Grisafi Date: Tue, 5 Sep 2023 02:13:58 -0700 Subject: [PATCH] Added argfile test and documentation (#7138) Co-authored-by: konsti --- crates/ruff_cli/tests/integration_test.rs | 41 +++++++++++++++++++++++ docs/usage.md | 1 + 2 files changed, 42 insertions(+) diff --git a/crates/ruff_cli/tests/integration_test.rs b/crates/ruff_cli/tests/integration_test.rs index bbb88ad0ecc36..1c411fd52e9d7 100644 --- a/crates/ruff_cli/tests/integration_test.rs +++ b/crates/ruff_cli/tests/integration_test.rs @@ -389,3 +389,44 @@ fn unreadable_dir() -> Result<()> { ); Ok(()) } + +/// Check that reading arguments from an argfile works +#[cfg(unix)] +#[test] +fn check_input_from_argfile() -> Result<()> { + let tempdir = TempDir::new()?; + + // Create python files + let file_a_path = tempdir.path().join("a.py"); + let file_b_path = tempdir.path().join("b.py"); + fs::write(&file_a_path, b"import os")?; + fs::write(&file_b_path, b"print('hello, world!')")?; + + // Create a the input file for argfile to expand + let input_file_path = tempdir.path().join("file_paths.txt"); + fs::write( + &input_file_path, + format!("{}\n{}", file_a_path.display(), file_b_path.display()), + )?; + + // Generate the args with the argfile notation + let args = vec![ + "check".to_string(), + "--no-cache".to_string(), + format!("@{}", &input_file_path.display()), + ]; + + let mut cmd = Command::cargo_bin(BIN_NAME)?; + let output = cmd.args(args).write_stdin("").assert().failure(); + assert_eq!( + str::from_utf8(&output.get_output().stdout)?, + format!( + "{}:1:8: F401 [*] `os` imported but unused +Found 1 error. +[*] 1 potentially fixable with the --fix option. +", + file_a_path.display() + ) + ); + Ok(()) +} diff --git a/docs/usage.md b/docs/usage.md index 23fb1174bcca6..af9e9f6b871ff 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -7,6 +7,7 @@ ruff check . # Lint all files in the current directory (a ruff check path/to/code/ # Lint all files in `/path/to/code` (and any subdirectories) ruff check path/to/code/*.py # Lint all `.py` files in `/path/to/code` ruff check path/to/code/to/file.py # Lint `file.py` +ruff check @file_paths.txt # Lint using an input file and treat its contents as command-line arguments (newline delimiter) ``` You can run Ruff in `--watch` mode to automatically re-run on-change: