summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBalaji Sivaraman <balaji@balajisivaraman.com>2018-02-12 22:47:22 +0530
committerAndrew Gallant <jamslam@gmail.com>2018-03-10 10:59:00 -0500
commit00520b30f5f38e543e17b1a4cc5e8417bc488ea4 (patch)
tree154aee40835b6a0d2fe945ccc065ff3ee0b8d8c0 /tests
parent11a8f0eaf0f661c5b20c20fa2399314905d84fc1 (diff)
output: add --stats flag
This commit provides basic support for a --stats flag, which will print various aggregate statistics about a search after all of the results have been printed. This is mostly intended to support a similar feature found in the Silver Searcher. Note though that we don't emit the total bytes searched; this is a first pass at an implementation and we can improve upon it later. Closes #411, Closes #799
Diffstat (limited to 'tests')
-rw-r--r--tests/tests.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/tests.rs b/tests/tests.rs
index 4ffb6d6d..8cb87184 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -1811,6 +1811,50 @@ be, to a very large extent, the result of luck. Sherlock Holmes
assert_eq!(lines, expected);
});
+sherlock!(feature_411_single_threaded_search_stats,
+|wd: WorkDir, mut cmd: Command| {
+ cmd.arg("--stats");
+
+ let lines: String = wd.stdout(&mut cmd);
+ assert_eq!(lines.contains("2 matched lines"), true);
+ assert_eq!(lines.contains("1 files contained matches"), true);
+ assert_eq!(lines.contains("1 files searched"), true);
+ assert_eq!(lines.contains("seconds"), true);
+});
+
+#[test]
+fn feature_411_parallel_search_stats() {
+ let wd = WorkDir::new("feature_411");
+ wd.create("sherlock_1", hay::SHERLOCK);
+ wd.create("sherlock_2", hay::SHERLOCK);
+
+ let mut cmd = wd.command();
+ cmd.arg("--stats");
+ cmd.arg("Sherlock");
+
+ let lines: String = wd.stdout(&mut cmd);
+ assert_eq!(lines.contains("4 matched lines"), true);
+ assert_eq!(lines.contains("2 files contained matches"), true);
+ assert_eq!(lines.contains("2 files searched"), true);
+ assert_eq!(lines.contains("seconds"), true);
+}
+
+sherlock!(feature_411_ignore_stats_1, |wd: WorkDir, mut cmd: Command| {
+ cmd.arg("--files-with-matches");
+ cmd.arg("--stats");
+
+ let lines: String = wd.stdout(&mut cmd);
+ assert_eq!(lines.contains("seconds"), false);
+});
+
+sherlock!(feature_411_ignore_stats_2, |wd: WorkDir, mut cmd: Command| {
+ cmd.arg("--files-without-match");
+ cmd.arg("--stats");
+
+ let lines: String = wd.stdout(&mut cmd);
+ assert_eq!(lines.contains("seconds"), false);
+});
+
#[test]
fn feature_740_passthru() {
let wd = WorkDir::new("feature_740");