Skip to content

Commit afeae83

Browse files
committed
locate fixes, implement updatedb, add tests
1 parent 3ecea97 commit afeae83

File tree

10 files changed

+1155
-176
lines changed

10 files changed

+1155
-176
lines changed

Cargo.lock

Lines changed: 376 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ onig = { version = "6.4", default-features = false }
1919
uucore = { version = "0.0.30", features = ["entries", "fs", "fsext", "mode"] }
2020
nix = { version = "0.29", features = ["fs", "user"] }
2121
argmax = "0.3.1"
22+
itertools = "0.14.0"
23+
quick-error = "2.0.1"
24+
uutests = "0.0.30"
2225

2326
[dev-dependencies]
2427
assert_cmd = "2"
@@ -37,6 +40,10 @@ path = "src/find/main.rs"
3740
name = "locate"
3841
path = "src/locate/main.rs"
3942

43+
[[bin]]
44+
name = "updatedb"
45+
path = "src/updatedb/main.rs"
46+
4047
[[bin]]
4148
name = "xargs"
4249
path = "src/xargs/main.rs"

src/db_tests.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#[cfg(test)]
2+
mod tests {
3+
use std::process::Command;
4+
5+
use assert_cmd::{assert::OutputAssertExt, cargo::CommandCargoExt};
6+
7+
#[test]
8+
fn test_locate_no_matches() {
9+
Command::cargo_bin("locate")
10+
.expect("couldn't find locate binary")
11+
.args(["usr", "--database=test_data_db"])
12+
.assert()
13+
.failure();
14+
}
15+
16+
#[test]
17+
fn test_locate_match() {
18+
Command::cargo_bin("locate")
19+
.expect("couldn't find locate binary")
20+
.args(["test_data", "--database=test_data_db"])
21+
.assert()
22+
.success();
23+
}
24+
25+
#[test]
26+
fn test_locate_no_matches_basename() {
27+
Command::cargo_bin("locate")
28+
.expect("couldn't find locate binary")
29+
.args([
30+
"test_data1234567890",
31+
"--basename",
32+
"--database=test_data_db",
33+
])
34+
.assert()
35+
.failure();
36+
}
37+
38+
#[test]
39+
fn test_locate_match_basename() {
40+
Command::cargo_bin("locate")
41+
.expect("couldn't find locate binary")
42+
.args(["abbbc", "--basename", "--database=test_data_db"])
43+
.assert()
44+
.success();
45+
}
46+
47+
#[test]
48+
fn test_locate_existing() {
49+
Command::cargo_bin("locate")
50+
.expect("couldn't find locate binary")
51+
.args(["abbbc", "--existing", "--database=test_data_db"])
52+
.assert()
53+
.success();
54+
}
55+
56+
#[test]
57+
fn test_locate_non_existing() {
58+
Command::cargo_bin("locate")
59+
.expect("couldn't find locate binary")
60+
.args(["abbbc", "--non-existing", "--database=test_data_db"])
61+
.assert()
62+
.failure();
63+
}
64+
65+
#[test]
66+
fn test_updatedb() {
67+
Command::cargo_bin("updatedb")
68+
.expect("couldn't find updatedb binary")
69+
.args(["--localpaths=./test_data", "--output=/dev/null"])
70+
.assert()
71+
.success();
72+
}
73+
}

src/find/matchers/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ use std::{
7474
use super::{Config, Dependencies};
7575

7676
pub use entry::{FileType, WalkEntry, WalkError};
77+
pub use regex::RegexType;
7778

7879
/// Symlink following mode.
7980
#[derive(Clone, Copy, Debug, Eq, PartialEq)]

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// license that can be found in the LICENSE file or at
55
// https://opensource.org/licenses/MIT.
66

7+
mod db_tests;
78
pub mod find;
89
pub mod locate;
10+
pub mod updatedb;
911
pub mod xargs;

src/locate/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// Copyright 2017 Google Inc.
2+
//
3+
// Use of this source code is governed by a MIT-style
4+
// license that can be found in the LICENSE file or at
5+
// https://opensource.org/licenses/MIT.
6+
17
fn main() {
28
let args = std::env::args().collect::<Vec<String>>();
39
let strs: Vec<&str> = args.iter().map(std::convert::AsRef::as_ref).collect();

0 commit comments

Comments
 (0)