mirror of
https://github.com/uutils/findutils.git
synced 2026-06-10 15:48:30 -07:00
1a6262cd5f
* Deleted vertical whitespace In an attempt to get around a mistake I made when merging from the master fork * Added a default implementation for has_side_effects And removed all the "return false" implementations (as specified by most of the Matchers). * Added support for -exec and -execdir * Fixed path_to_testing_commandline * Minor tweaks from code review * Added support for -perm * Fixed string constant * Fixed error caused by merging changes * Tweaks after code review * Fixed windows compatability. This required - changing a lot of test code to supply/expect backslashes rather than slashes when running on windows - tweaking the way testing-commandline reported its args (debug format escapes backslashes when printing strings) - changing the NewerMatcher to get metadata from fs::metadata() rather than from File's metadata method (the latter caused mysterious test failures, which I didn't bother tracking down becasue the former is more efficient anyway) - hiding more of perm.rs behind #[cfg(unix)] to stop "unused X" warnings * Revert "Fixed windows compatability. This required" This reverts commit0e2c385237. * Revert "Revert "Fixed windows compatability. This required"" This reverts commit384da6d2f4.
99 lines
3.9 KiB
Rust
99 lines
3.9 KiB
Rust
// Copyright 2017 Google Inc.
|
|
//
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file or at
|
|
// https://opensource.org/licenses/MIT.
|
|
|
|
|
|
/// ! This file contains what would be normally be unit tests for find::matchers::exec.
|
|
/// ! But as the tests require running an external executable, they need to be run
|
|
/// ! as integration tests so we can ensure that our testing-commandline binary
|
|
/// ! has been built.
|
|
extern crate findutils;
|
|
extern crate tempdir;
|
|
extern crate walkdir;
|
|
|
|
|
|
use std::env;
|
|
use std::fs::File;
|
|
use std::io::Read;
|
|
use tempdir::TempDir;
|
|
|
|
|
|
use findutils::find::matchers::Matcher;
|
|
use findutils::find::matchers::exec::*;
|
|
use common::test_helpers::*;
|
|
|
|
mod common;
|
|
|
|
#[test]
|
|
fn matching_executes_code() {
|
|
|
|
let temp_dir = TempDir::new("matching_executes_code").unwrap();
|
|
let temp_dir_path = temp_dir.path().to_string_lossy();
|
|
|
|
let abbbc = get_dir_entry_for("test_data/simple", "abbbc");
|
|
let matcher = SingleExecMatcher::new(&path_to_testing_commandline(),
|
|
&vec![temp_dir_path.as_ref(), "abc", "{}", "xyz"],
|
|
false)
|
|
.expect("Failed to create matcher");
|
|
let deps = FakeDependencies::new();
|
|
assert!(matcher.matches(&abbbc, &mut deps.new_matcher_io()));
|
|
|
|
let mut f = File::open(temp_dir.path().join("1.txt")).expect("Failed to open output file");
|
|
let mut s = String::new();
|
|
f.read_to_string(&mut s).expect("failed to read output file");
|
|
assert_eq!(s,
|
|
fix_up_slashes(&format!("cwd={}\nargs=\nabc\ntest_data/simple/abbbc\nxyz\n",
|
|
env::current_dir().unwrap().to_string_lossy())));
|
|
}
|
|
|
|
#[test]
|
|
fn matching_executes_code_in_files_directory() {
|
|
|
|
let temp_dir = TempDir::new("matching_executes_code_in_files_directory").unwrap();
|
|
let temp_dir_path = temp_dir.path().to_string_lossy();
|
|
|
|
let abbbc = get_dir_entry_for("test_data/simple", "abbbc");
|
|
let matcher = SingleExecMatcher::new(&path_to_testing_commandline(),
|
|
&vec![temp_dir_path.as_ref(), "abc", "{}", "xyz"],
|
|
true)
|
|
.expect("Failed to create matcher");
|
|
let deps = FakeDependencies::new();
|
|
assert!(matcher.matches(&abbbc, &mut deps.new_matcher_io()));
|
|
|
|
let mut f = File::open(temp_dir.path().join("1.txt")).expect("Failed to open output file");
|
|
let mut s = String::new();
|
|
f.read_to_string(&mut s).expect("failed to read output file");
|
|
assert_eq!(s,
|
|
fix_up_slashes(&format!("cwd={}/test_data/simple\nargs=\nabc\n./abbbc\nxyz\n",
|
|
env::current_dir().unwrap().to_string_lossy())));
|
|
}
|
|
|
|
#[test]
|
|
fn matching_fails_if_executable_fails() {
|
|
|
|
let temp_dir = TempDir::new("matching_fails_if_executable_fails").unwrap();
|
|
let temp_dir_path = temp_dir.path().to_string_lossy();
|
|
|
|
let abbbc = get_dir_entry_for("test_data/simple", "abbbc");
|
|
let matcher = SingleExecMatcher::new(&path_to_testing_commandline(),
|
|
&vec![temp_dir_path.as_ref(),
|
|
"--exit_with_failure",
|
|
"abc",
|
|
"{}",
|
|
"xyz"],
|
|
true)
|
|
.expect("Failed to create matcher");
|
|
let deps = FakeDependencies::new();
|
|
assert!(!matcher.matches(&abbbc, &mut deps.new_matcher_io()));
|
|
|
|
let mut f = File::open(temp_dir.path().join("1.txt")).expect("Failed to open output file");
|
|
let mut s = String::new();
|
|
f.read_to_string(&mut s).expect("failed to read output file");
|
|
assert_eq!(s,
|
|
fix_up_slashes(&format!("cwd={}/test_data/simple\nargs=\n--exit_with_failure\nabc\n.\
|
|
/abbbc\nxyz\n",
|
|
env::current_dir().unwrap().to_string_lossy())));
|
|
}
|