Skip to content

Commit 1205e4d

Browse files
committed
[1 of 2]: filter (tests): exercise parse_spec() on empty, blank specs
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.
1 parent 6e8b7f5 commit 1205e4d

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/filter/mod.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,55 @@ mod tests {
557557
assert!(filter.is_none());
558558
}
559559

560+
#[test]
561+
fn parse_spec_empty_level_isolated() {
562+
// test parse_spec with "" as log level (and the entire spec str)
563+
let (dirs, filter) = parse_spec(""); // should be ignored
564+
assert_eq!(dirs.len(), 0);
565+
assert!(filter.is_none());
566+
}
567+
568+
#[test]
569+
fn parse_spec_blank_level_isolated() {
570+
// test parse_spec with a white-space-only string specified as the log
571+
// level (and the entire spec str)
572+
let (dirs, filter) = parse_spec(" "); // should be ignored
573+
assert_eq!(dirs.len(), 0);
574+
assert!(filter.is_none());
575+
}
576+
577+
#[test]
578+
fn parse_spec_blank_level_isolated_comma_only() {
579+
// The spec should contain zero or more comma-separated string slices,
580+
// so a comma-only string should be interpretted as two empty strings
581+
// (which should both be treated as invalid, so ignored).
582+
let (dirs, filter) = parse_spec(","); // should be ignored
583+
assert_eq!(dirs.len(), 0);
584+
assert!(filter.is_none());
585+
}
586+
587+
#[test]
588+
fn parse_spec_blank_level_isolated_comma_blank() {
589+
// The spec should contain zero or more comma-separated string slices,
590+
// so this bogus spec should be interpretted as containing one empty
591+
// string and one blank string. Both should both be treated as
592+
// invalid, so ignored.
593+
let (dirs, filter) = parse_spec(", "); // should be ignored
594+
assert_eq!(dirs.len(), 0);
595+
assert!(filter.is_none());
596+
}
597+
598+
#[test]
599+
fn parse_spec_blank_level_isolated_blank_comma() {
600+
// The spec should contain zero or more comma-separated string slices,
601+
// so this bogus spec should be interpretted as containing one blank
602+
// string and one empty string. Both should both be treated as
603+
// invalid, so ignored.
604+
let (dirs, filter) = parse_spec(" ,"); // should be ignored
605+
assert_eq!(dirs.len(), 0);
606+
assert!(filter.is_none());
607+
}
608+
560609
#[test]
561610
fn parse_spec_global() {
562611
// test parse_spec with no crate

0 commit comments

Comments
 (0)