Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added argfile test and documentation #7138

Merged
merged 3 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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