Skip to content

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

Open

Description

@sckott
  • 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

Activity

  1. sckott commented on Jan 11, 2025

    @sckott
    OwnerAuthor

    @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?

  2. JosiahParry commented on Jan 11, 2025

    @JosiahParry
    Contributor

    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!(),
        }
    }
  3. sckott commented on Jan 16, 2025

    @sckott
    OwnerAuthor

    @JosiahParry Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions