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

Further testing to oof cli #38

Merged
merged 4 commits into from
Jun 12, 2021
Merged

Conversation

demfabris
Copy link

@demfabris demfabris commented May 28, 2021

@marcospb19 So i'm kinda having a hard time here. Not sure if parse_args_from is misbehaving. 😕

Please have a look at these test attempts

Also, how should we approach these tests?
I did two variants, let me know which approach is best (if you like the second best i think we should consider using assert_cmd and assert_fs

src/cli.rs Outdated Show resolved Hide resolved
@marcospb19
Copy link
Member

It's more for the direction of the first test you made. Here are some examples I was elaborating.

fn gen_args(text: &str) -> Vec<OsString> {
    let args = text.split_whitespace();
    args.map(OsString::from).collect()
}

fn test_cli(args: &str) -> crate::Result<ParsedArgs> {
    let args = gen_args(args);
    parse_args_from(args)
}

#[test]
fn test_cli_commands() {
    assert_eq!(test_cli("--help").unwrap().command, Command::ShowHelp);

    assert_eq!(test_cli("--version").unwrap().command, Command::ShowVersion);
    assert_eq!(test_cli("--version").unwrap().flags, oof::Flags::default());

    // Testing for errors
    // // Not currently possible because of PartialEq trait limits on io::Error
    // assert_eq!(
    //     test_cli("compress").unwrap_err(),
    //     Err(crate::Error::MissingArgumentsForCompression)
    // );
}

#[test]
fn test_cli_flags() {
    // --help and --version flags are considered commands that are ran over anything else
    assert_eq!(test_cli("--help").unwrap().flags, oof::Flags::default());
    assert_eq!(test_cli("--version").unwrap().flags, oof::Flags::default());

    // Just for reference:
    // pub struct Flags {
    //     pub boolean_flags: BTreeSet<&'static str>,
    //     pub argument_flags: BTreeMap<&'static str, OsString>,
    // }

    assert_eq!(test_cli("a b c -o hey --yes").unwrap().flags, oof::Flags {
        boolean_flags: vec!["yes"].into_iter().collect(),
        argument_flags: vec![("--output", OsString::from("hey"))].into_iter().collect(),
    });
}

@marcospb19
Copy link
Member

It looks like there is already an error with the -o not being detected.

I don't know exactly why.

But yeah the main idea for this testing part is to have lines like this:

    assert_eq!(test_cli(INPUT).unwrap().command, Command:: .. );
    assert_eq!(test_cli(INPUT).unwrap().command, Command:: .. );
    assert_eq!(test_cli(INPUT).unwrap().command, Command:: .. );
    assert_eq!(test_cli(INPUT).unwrap().command, Command:: .. );

With different inputs. Some with .unwrap_err(), covering the usage cases we mentioned in the readme.

I was thought this would be easier but we ran into some issues with some trait implementations, I pushed new commits solving some of then already.

@demfabris
Copy link
Author

So i added a couple more tests, all passing.

Indeed seems to be a misbehaviour with that last assert_eq! in test_cli_flags.
It doesn't correctly parse the --output flag

@marcospb19
Copy link
Member

Tomorrow I will try to review this and figure out the --output flag problem, I have no idea what the problem is.

let output_folder = flags.take_arg("output").map(PathBuf::from);
let output_folder = flags.arg("output").map(PathBuf::from);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabricio7p I have now fixed the --output error, we were using take_arg which removes the flag from our oof::Flags struct, that's why we couldn't find that later.

Not, by using .arg() instead, we clone (kindof) the content, and now the output_folder can be found in our Command::Decompress as well as oof::Flags.

I adapted the tests, and now they are passing correctly, sorry for the late response.

src/cli.rs Outdated Show resolved Hide resolved
@demfabris
Copy link
Author

Done. Sorry about that, i've had a busy week

@marcospb19
Copy link
Member

marcospb19 commented Jun 12, 2021

No problem! You're the one helping here, thanks for your contribution, I was working on an big change on ouch compression and decompression system,.

Istead of loading everything to a Vec inbetween each compression or decompression, I can concatenate some decoder and encoder writers, to create a compression stream that writes directly into the final file.

Now ouch will support more than 2 extensions, .tar.gz.xz.bz.gz.gz will be possible, I just don't know when I'll be able to finish it, am having fever, even suspecting I got COVID.

~
Como você é brasileiro, se quiser manter contato, eu e Vinícius nos comunicamos pelo do telegram, no meu perfil aqui do GitHub tem meu username, que é @marcospb19 também, se quiser conversar por lá, só chamar :) , pode ser mais fácil ajudar novos PRs também com um canal mais fácil de conversação
~

@marcospb19
Copy link
Member

Anyway, merging!

@marcospb19 marcospb19 merged commit 58c7393 into ouch-org:master Jun 12, 2021
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

Successfully merging this pull request may close these issues.

None yet

2 participants