summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSebastian Nowicki <sebnow@gmail.com>2017-10-16 11:45:20 +0200
committerAndrew Gallant <jamslam@gmail.com>2017-10-20 20:51:12 -0400
commit8dc513b5d2fad3bfc820c60724575c02b0c259ae (patch)
treec8b86f554c4f8dc537fa8e8b14cccbd816d052e9 /tests
parenta98156e71cc2aefd2d3e18c76c6d09cc1ef8c5ac (diff)
Skip regression 210 test on APFS
APFS does not support creating filenames with invalid UTF-8 byte codes, thus this test doesn't make sense. Skip it on file systems where this shouldn't be possible. Fixes #559
Diffstat (limited to 'tests')
-rw-r--r--tests/tests.rs11
-rw-r--r--tests/workdir.rs20
2 files changed, 22 insertions, 9 deletions
diff --git a/tests/tests.rs b/tests/tests.rs
index dfb681d7..218ca56a 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -1015,11 +1015,14 @@ fn regression_210() {
let wd = WorkDir::new("regression_210");
let mut cmd = wd.command();
- wd.create(badutf8, "test");
- cmd.arg("-H").arg("test").arg(badutf8);
+ // APFS does not support creating files with invalid UTF-8 bytes.
+ // https://github.com/BurntSushi/ripgrep/issues/559
+ if wd.try_create(badutf8, "test").is_ok() {
+ cmd.arg("-H").arg("test").arg(badutf8);
- let out = wd.output(&mut cmd);
- assert_eq!(out.stdout, b"foo\xffbar:test\n".to_vec());
+ let out = wd.output(&mut cmd);
+ assert_eq!(out.stdout, b"foo\xffbar:test\n".to_vec());
+ }
}
// See: https://github.com/BurntSushi/ripgrep/issues/228
diff --git a/tests/workdir.rs b/tests/workdir.rs
index 06621532..fb3ef4f5 100644
--- a/tests/workdir.rs
+++ b/tests/workdir.rs
@@ -41,11 +41,16 @@ impl WorkDir {
}
}
- /// Create a new file with the given name and contents in this directory.
+ /// Create a new file with the given name and contents in this directory, or panic on error.
pub fn create<P: AsRef<Path>>(&self, name: P, contents: &str) {
self.create_bytes(name, contents.as_bytes());
}
+ /// Try to create a new file with the given name and contents in this directory.
+ pub fn try_create<P: AsRef<Path>>(&self, name: P, contents: &str) -> io::Result<()> {
+ self.try_create_bytes(name, contents.as_bytes())
+ }
+
/// Create a new file with the given name and size.
pub fn create_size<P: AsRef<Path>>(&self, name: P, filesize: u64) {
let path = self.dir.join(name);
@@ -53,12 +58,17 @@ impl WorkDir {
nice_err(&path, file.set_len(filesize));
}
- /// Create a new file with the given name and contents in this directory.
+ /// Create a new file with the given name and contents in this directory, or panic on error.
pub fn create_bytes<P: AsRef<Path>>(&self, name: P, contents: &[u8]) {
let path = self.dir.join(name);
- let mut file = nice_err(&path, File::create(&path));
- nice_err(&path, file.write_all(contents));
- nice_err(&path, file.flush());
+ nice_err(&path, self.try_create_bytes(&path, contents));
+ }
+
+ /// Try to create a new file with the given name and contents in this directory.
+ fn try_create_bytes<P: AsRef<Path>>(&self, path: P, contents: &[u8]) -> io::Result<()> {
+ let mut file = File::create(&path)?;
+ file.write_all(contents)?;
+ file.flush()
}
/// Remove a file with the given name from this directory.