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

rt file - change to handle many files and pattern match #2

Open
2 tasks
sckott opened this issue Sep 7, 2024 · 3 comments
Open
2 tasks

rt file - change to handle many files and pattern match #2

sckott opened this issue Sep 7, 2024 · 3 comments

Comments

@sckott
Copy link
Owner

sckott commented Sep 7, 2024

  • handle many files, both with regex matching > 1 and user supplying > 1 string
  • match on closest test file to given pattern

in the ruby library that's the predecessor to this https://github.com/sckott/rubrb rb test could handle the full file path or just a string and then match to the list of test files found - & handle more than 1 - it'd be nice to replicate this behavior as I've found it very useful

@sckott
Copy link
Owner Author

sckott commented Jan 11, 2025

@JosiahParry Trying to figure out how to modify the rt file subcommand https://github.com/sckott/rt-cli/blob/main/rt-cli/src/main.rs#L79 - to do a regex on the user input to the subcommand, but I'm not sure the best way to approach it.

One thought I had was to call the list subcommand from within the file subcommand, but I'm not sure if that's a bad idea or not. Idea is to find all the matches in the list of test files that match the user input to rt file probably with a new flag like rt file -r someregex - and then run all of those test files that match

Or we could factor out the code in the list subcommand https://github.com/sckott/rt-cli/blob/main/rt-cli/src/main.rs#L117-L153 and then be able to call that function

Thoughts?

@JosiahParry
Copy link
Contributor

JosiahParry commented Jan 11, 2025

I think you could add another argument to the struct like so:

#[derive(PartialEq, Clone, Debug, FromArgs)]
#[argh(subcommand, name = "file")]
/// Test a single file using testthat
struct TestThatFile {
    /// path to a test file
    #[argh(option, short = 'f', long = "file")]
    file: Option<String>,

    /// regex pattern to match test files
    #[argh(option, short = 'r', long = "regex")]
    regex: Option<String>,

    /// path to the package (default `.`)
    #[argh(option, short = 'P', default = r#"".".to_string()"#)]
    pkg_dir: String,

    /// do not load the development package
    #[argh(switch, short = 's')]
    standalone: bool,
}

Then the CLI can be modified to match on both of the arguments:

Subcommands::File(cmd) => {
    match (cmd.file, cmd.regex) {
        (None, None) => todo!(), // error here
        // use glob or something to find files that match the pattern 
        // then you can use run_rscript() over them
        (None, Some(_)) => todo!(), 
        // keep default behavior here
        (Some(_), None) => todo!(),
        // maybe error here or run a single file and both ?
        (Some(_), Some(_)) => todo!(),
    }
}

@sckott
Copy link
Owner Author

sckott commented Jan 16, 2025

@JosiahParry Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants