Skip to content

Commit

Permalink
Added argfile test and documentation (#7138)
Browse files Browse the repository at this point in the history
Co-authored-by: konsti <konstin@mailbox.org>
  • Loading branch information
njgrisafi and konstin authored Sep 5, 2023
1 parent 10a8e4a commit 40ee490
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
41 changes: 41 additions & 0 deletions crates/ruff_cli/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
1 change: 1 addition & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 40ee490

Please sign in to comment.