summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2018-08-21 20:26:33 -0400
committerAndrew Gallant <jamslam@gmail.com>2018-08-21 23:05:52 -0400
commit5b1ce8bdc2391df82f2e9b4d8cc7b64f46c6c9a2 (patch)
treec08604931cca74ab1046f2455f149c84e991cc55
parent1529ce33414f33eb432f9efadf3e38609ae89429 (diff)
tests: touch up tests on Windows
This fixes warnings and adds an additional invalid UTF-8 test that will run on Windows.
-rw-r--r--tests/json.rs43
-rw-r--r--tests/util.rs2
2 files changed, 45 insertions, 0 deletions
diff --git a/tests/json.rs b/tests/json.rs
index 4433103d..7a7bd4d0 100644
--- a/tests/json.rs
+++ b/tests/json.rs
@@ -241,6 +241,49 @@ rgtest!(notutf8, |dir: Dir, mut cmd: TestCommand| {
);
});
+rgtest!(notutf8_file, |dir: Dir, mut cmd: TestCommand| {
+ use std::ffi::OsStr;
+
+ // This test does not work with PCRE2 because PCRE2 does not support the
+ // `u` flag.
+ if dir.is_pcre2() {
+ return;
+ }
+
+ let name = "foo";
+ let contents = &b"quux\xFFbaz"[..];
+
+ // APFS does not support creating files with invalid UTF-8 bytes, so just
+ // skip the test if we can't create our file.
+ if !dir.try_create_bytes(OsStr::new(name), contents).is_ok() {
+ return;
+ }
+ cmd.arg("--json").arg(r"(?-u)\xFF");
+
+ let msgs = json_decode(&cmd.stdout());
+
+ assert_eq!(
+ msgs[0].unwrap_begin(),
+ Begin { path: Some(Data::text("foo")) }
+ );
+ assert_eq!(
+ msgs[1].unwrap_match(),
+ Match {
+ path: Some(Data::text("foo")),
+ lines: Data::bytes("cXV1eP9iYXo="),
+ line_number: Some(1),
+ absolute_offset: 0,
+ submatches: vec![
+ SubMatch {
+ m: Data::bytes("/w=="),
+ start: 4,
+ end: 5,
+ },
+ ],
+ }
+ );
+});
+
// See: https://github.com/BurntSushi/ripgrep/issues/416
//
// This test in particular checks that our match does _not_ include the `\r`
diff --git a/tests/util.rs b/tests/util.rs
index f8fa51a9..6cfa6fc7 100644
--- a/tests/util.rs
+++ b/tests/util.rs
@@ -103,6 +103,7 @@ impl Dir {
/// Try to create a new file with the given name and contents in this
/// directory.
+ #[allow(dead_code)] // unused on Windows
pub fn try_create<P: AsRef<Path>>(
&self,
name: P,
@@ -222,6 +223,7 @@ impl Dir {
/// Creates a file symlink to the src with the given target name
/// in this directory.
#[cfg(windows)]
+ #[allow(dead_code)] // unused on Windows
pub fn link_file<S: AsRef<Path>, T: AsRef<Path>>(
&self,
src: S,