Skip to content

Commit eeb7ab5

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

File tree

10 files changed

+1161
-176
lines changed

10 files changed

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

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)