Skip to content

Commit

Permalink
[1 of 2]: filter (tests): exercise parse_spec() on empty, blank specs
Browse files Browse the repository at this point in the history
These unit tests demonstrate filter::parse_spec() accepting as legit
empty and blank spec strings that it should be ignoring:

    $ cargo test 'filter::tests::'
    ...
    failures:
        filter::tests::parse_spec_blank_level_isolated
        filter::tests::parse_spec_blank_level_isolated_blank_comma
        filter::tests::parse_spec_blank_level_isolated_comma_blank

    test result: FAILED. 21 passed; 3 failed; 0 ignored; 0 measured; 11 filtered out

Fix to come in follow-up commit.
  • Loading branch information
salewski committed Dec 5, 2020
1 parent d4606a3 commit 6453eb1
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/filter/mod.rs
Expand Up @@ -557,6 +557,55 @@ mod tests {
assert!(filter.is_none());
}

#[test]
fn parse_spec_empty_level_isolated() {
// test parse_spec with "" as log level (and the entire spec str)
let (dirs, filter) = parse_spec(""); // should be ignored
assert_eq!(dirs.len(), 0);
assert!(filter.is_none());
}

#[test]
fn parse_spec_blank_level_isolated() {
// test parse_spec with a white-space-only string specified as the log
// level (and the entire spec str)
let (dirs, filter) = parse_spec(" "); // should be ignored
assert_eq!(dirs.len(), 0);
assert!(filter.is_none());
}

#[test]
fn parse_spec_blank_level_isolated_comma_only() {
// The spec should contain zero or more comma-separated string slices,
// so a comma-only string should be interpretted as two empty strings
// (which should both be treated as invalid, so ignored).
let (dirs, filter) = parse_spec(","); // should be ignored
assert_eq!(dirs.len(), 0);
assert!(filter.is_none());
}

#[test]
fn parse_spec_blank_level_isolated_comma_blank() {
// The spec should contain zero or more comma-separated string slices,
// so this bogus spec should be interpretted as containing one empty
// string and one blank string. Both should both be treated as
// invalid, so ignored.
let (dirs, filter) = parse_spec(", "); // should be ignored
assert_eq!(dirs.len(), 0);
assert!(filter.is_none());
}

#[test]
fn parse_spec_blank_level_isolated_blank_comma() {
// The spec should contain zero or more comma-separated string slices,
// so this bogus spec should be interpretted as containing one blank
// string and one empty string. Both should both be treated as
// invalid, so ignored.
let (dirs, filter) = parse_spec(" ,"); // should be ignored
assert_eq!(dirs.len(), 0);
assert!(filter.is_none());
}

#[test]
fn parse_spec_global() {
// test parse_spec with no crate
Expand Down

0 comments on commit 6453eb1

Please sign in to comment.