Skip to content

Commit

Permalink
fix 'long_and_detailed' test for differing rustc versions
Browse files Browse the repository at this point in the history
- customize expected pretty-print output for windows platforms
  - work-around for debug print format changes between versions (see <rust-lang/rust#62794>)
  • Loading branch information
rivy committed Aug 24, 2019
1 parent a5d97a4 commit 0694e18
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ features = ["consoleapi", "errhandlingapi", "fileapi", "handleapi", "processenv"

[dev-dependencies]
doc-comment = "0.3"
regex = "1.1.9"

[dev-dependencies.serde_json]
version = "1.0.39"
44 changes: 28 additions & 16 deletions src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::fmt;

use style::Style;


/// Styles have a special `Debug` implementation that only shows the fields that
/// are set. Fields that haven’t been touched aren’t included in the output.
///
Expand Down Expand Up @@ -103,20 +102,33 @@ mod test {

#[test]
fn long_and_detailed() {
let debug = r##"Style {
foreground: Some(
Blue,
),
background: None,
blink: false,
bold: true,
dimmed: false,
hidden: false,
italic: false,
reverse: false,
strikethrough: false,
underline: false,
}"##;
assert_eq!(debug, format!("{:#?}", Blue.bold()));
extern crate regex;
let expected_debug = "Style { fg(Blue), bold }";
let expected_pretty_repat = r##"(?x)
Style\s+\{\s+
foreground:\s+Some\(\s+
Blue,?\s+
\),\s+
background:\s+None,\s+
blink:\s+false,\s+
bold:\s+true,\s+
dimmed:\s+false,\s+
hidden:\s+false,\s+
italic:\s+false,\s+
reverse:\s+false,\s+
strikethrough:\s+
false,\s+
underline:\s+false,?\s+
\}"##;
let re = regex::Regex::new(expected_pretty_repat).unwrap();

let style = Blue.bold();
let style_fmt_debug = format!("{:?}", style);
let style_fmt_pretty = format!("{:#?}", style);
println!("style_fmt_debug:\n{}", style_fmt_debug);
println!("style_fmt_pretty:\n{}", style_fmt_pretty);

assert_eq!(expected_debug, style_fmt_debug);
assert!(re.is_match(&style_fmt_pretty));
}
}

0 comments on commit 0694e18

Please sign in to comment.