Skip to content

Remove clap dependency #127

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

Merged
merged 1 commit into from
Aug 3, 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
121 changes: 3 additions & 118 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ rustfix = "0.6.1"
cargo-platform = "0.1.2"
comma = "1.0.0"
distance = "0.4.0"
clap = { version = "4.3.11", features = ["derive"] }
anyhow = "1.0.6"
indicatif = "0.17.6"
prettydiff = "0.6.4"
Expand Down
35 changes: 19 additions & 16 deletions src/config/args.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
//! Default argument processing when `ui_test` is used
//! as a test driver.

use clap::Parser;

/// Plain arguments if `ui_test` is used as a binary.
#[derive(Parser, Debug, Clone)]
#[command(author, version, about, long_about = None)]
pub struct Args {
/// Filters that will be used to match on individual tests
pub filters: Vec<String>,

/// Whether to minimize output given to the user.
#[arg(short, long, default_value_t = false)]
pub quiet: bool,

/// Whether error on mismatches between `.stderr` files and actual
/// output. Will update the files otherwise.
#[arg(long, default_value_t = false)]
pub check: bool,
}

impl Default for Args {
fn default() -> Self {
Self::parse_from([std::env::current_exe().unwrap()])
}
}

impl Args {
/// Arguments if `ui_test` is used as a `cargo test`, so we need
/// to skip a level of `--` in order to not pick up `cargo`'s test
/// flags.
/// Arguments if `ui_test` is used as a `harness=false` test, called from `cargo test`.
pub fn test() -> Self {
Args::parse_from(std::env::args().skip_while(|arg| arg != "--"))
let mut args = Args {
filters: vec![],
quiet: false,
check: false,
};
for arg in std::env::args().skip(1) {
if arg == "--" {
continue;
}
if arg == "--quiet" {
args.quiet = true;
} else if arg == "--check" {
args.check = true;
} else {
args.filters.push(arg);
}
}
args
}
}
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
//! A crate to run the Rust compiler (or other binaries) and test their command line output.

use bstr::ByteSlice;
pub use clap;
use clap::Parser;
pub use color_eyre;
use color_eyre::eyre::{eyre, Result};
use crossbeam_channel::{unbounded, Receiver, Sender};
Expand Down Expand Up @@ -120,7 +118,7 @@ pub type Filter = Vec<(Match, &'static [u8])>;
/// Run all tests as described in the config argument.
/// Will additionally process command line arguments.
pub fn run_tests(config: Config) -> Result<()> {
let args = Args::parse();
let args = Args::test();
if !args.quiet {
eprintln!(" Compiler: {}", config.program.display());
}
Expand Down
3 changes: 1 addition & 2 deletions tests/integration.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::path::Path;

use clap::Parser;
use colored::Colorize;
use ui_test::color_eyre::Result;
use ui_test::*;
Expand All @@ -22,7 +21,7 @@ fn run(name: &str, mode: Mode) -> Result<()> {
mode,
..Config::cargo(root_dir.clone())
};
let args = Args::parse();
let args = Args::test();

if !args.check {
config.output_conflict_handling = OutputConflictHandling::Bless;
Expand Down
Loading