From 7ad23e5565e9dca308c52929571c0609c28291c6 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Wed, 12 Apr 2017 17:21:07 -0400 Subject: [PATCH] Use for_label_no_replacement. This will cause certain unsupported legacy encodings to act as if they don't exist, in order to avoid using an unhelpful (in the context of file searching) "replacement" encoding. Kudos to @hsivonen for chirping about this! --- src/args.rs | 2 +- tests/tests.rs | 15 +++++++++++++++ tests/workdir.rs | 17 +++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/args.rs b/src/args.rs index 48c4ad5..9e941a7 100644 --- a/src/args.rs +++ b/src/args.rs @@ -737,7 +737,7 @@ impl<'a> ArgMatches<'a> { if label == "auto" { return Ok(None); } - match Encoding::for_label(label.as_bytes()) { + match Encoding::for_label_no_replacement(label.as_bytes()) { Some(enc) => Ok(Some(enc)), None => Err(From::from( format!("unsupported encoding: {}", label))), diff --git a/tests/tests.rs b/tests/tests.rs index ef332ae..38812c4 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1137,6 +1137,21 @@ clean!(feature_1_eucjp, "Шерлок Холмс", ".", assert_eq!(lines, "foo:Шерлок Холмс\n"); }); +// See: https://github.com/BurntSushi/ripgrep/issues/1 +sherlock!(feature_1_unknown_encoding, "Sherlock", ".", +|wd: WorkDir, mut cmd: Command| { + cmd.arg("-Efoobar"); + wd.assert_non_empty_stderr(&mut cmd); +}); + +// See: https://github.com/BurntSushi/ripgrep/issues/1 +// Specific: https://github.com/BurntSushi/ripgrep/pull/398/files#r111109265 +sherlock!(feature_1_replacement_encoding, "Sherlock", ".", +|wd: WorkDir, mut cmd: Command| { + cmd.arg("-Ecsiso2022kr"); + wd.assert_non_empty_stderr(&mut cmd); +}); + // See: https://github.com/BurntSushi/ripgrep/issues/7 sherlock!(feature_7, "-fpat", "sherlock", |wd: WorkDir, mut cmd: Command| { wd.create("pat", "Sherlock\nHolmes"); diff --git a/tests/workdir.rs b/tests/workdir.rs index a5fe9e5..0662153 100644 --- a/tests/workdir.rs +++ b/tests/workdir.rs @@ -256,6 +256,23 @@ impl WorkDir { String::from_utf8_lossy(&o.stderr)); } } + + /// Runs the given command and asserts that something was printed to + /// stderr. + pub fn assert_non_empty_stderr(&self, cmd: &mut process::Command) { + let o = cmd.output().unwrap(); + if o.status.success() || o.stderr.is_empty() { + panic!("\n\n===== {:?} =====\n\ + command succeeded but expected failure!\ + \n\ncwd: {}\ + \n\nstatus: {}\ + \n\nstdout: {}\n\nstderr: {}\ + \n\n=====\n", + cmd, self.dir.display(), o.status, + String::from_utf8_lossy(&o.stdout), + String::from_utf8_lossy(&o.stderr)); + } + } } fn nice_err, T, E: error::Error>(