Skip to content

Commit ff350c7

Browse files
committed
handle windows better
1 parent 26982d5 commit ff350c7

File tree

4 files changed

+134
-109
lines changed

4 files changed

+134
-109
lines changed

src/locate/main.rs

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

7+
#[cfg(not(windows))]
78
fn main() {
89
let args = std::env::args().collect::<Vec<String>>();
910
let strs: Vec<&str> = args.iter().map(std::convert::AsRef::as_ref).collect();
10-
#[cfg(unix)]
1111
std::process::exit(findutils::locate::locate_main(strs.as_slice()));
1212
}
13+
14+
#[cfg(windows)]
15+
fn main() {
16+
println!("locate is unsupported on Windows");
17+
}

src/updatedb/main.rs

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

7+
#[cfg(not(windows))]
78
fn main() {
89
let args = std::env::args().collect::<Vec<String>>();
910
let strs: Vec<&str> = args.iter().map(std::convert::AsRef::as_ref).collect();
1011
std::process::exit(findutils::updatedb::updatedb_main(strs.as_slice()));
1112
}
13+
14+
#[cfg(windows)]
15+
fn main() {
16+
println!("updatedb is unsupported on Windows");
17+
}
184 Bytes
Binary file not shown.

tests/db_tests.rs

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

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_locate_statistics() {
73-
Command::cargo_bin("locate")
74-
.expect("couldn't find locate binary")
75-
.args(["abbbc", "--statistics", "--database=test_data_db"])
76-
.assert()
77-
.success();
78-
}
79-
80-
#[test]
81-
fn test_locate_regex() {
82-
Command::cargo_bin("locate")
83-
.expect("couldn't find locate binary")
84-
.args(["abbbc", "--regex", "--database=test_data_db"])
85-
.assert()
86-
.success();
87-
}
88-
89-
#[test]
90-
fn test_locate_all() {
91-
Command::cargo_bin("locate")
92-
.expect("couldn't find locate binary")
93-
.args(["abb", "bbc", "--regex", "--database=test_data_db"])
94-
.assert()
95-
.success();
96-
}
97-
98-
#[test]
99-
fn test_locate_all_regex() {
100-
Command::cargo_bin("locate")
101-
.expect("couldn't find locate binary")
102-
.args(["abb", "b*c", "--regex", "--database=test_data_db"])
103-
.assert()
104-
.success();
105-
}
106-
107-
#[test]
108-
fn test_updatedb() {
109-
Command::cargo_bin("updatedb")
110-
.expect("couldn't find updatedb binary")
111-
.args(["--localpaths=./test_data", "--output=/dev/null"])
112-
.assert()
113-
.success();
114-
}
7+
mod common;
8+
9+
use std::process::Command;
10+
11+
use assert_cmd::{assert::OutputAssertExt, cargo::CommandCargoExt};
12+
13+
use crate::common::test_helpers::fix_up_slashes;
14+
15+
#[cfg(not(windows))]
16+
const DB_FLAG: &str = "--database=test_data_db";
17+
18+
#[test]
19+
#[cfg(not(windows))]
20+
fn test_locate_no_matches() {
21+
Command::cargo_bin("locate")
22+
.expect("couldn't find locate binary")
23+
.args(["usr", DB_FLAG])
24+
.assert()
25+
.failure();
26+
}
27+
28+
#[test]
29+
#[cfg(not(windows))]
30+
fn test_locate_match() {
31+
Command::cargo_bin("locate")
32+
.expect("couldn't find locate binary")
33+
.args(["test_data", DB_FLAG])
34+
.assert()
35+
.success();
36+
}
37+
38+
#[test]
39+
#[cfg(not(windows))]
40+
fn test_locate_no_matches_basename() {
41+
Command::cargo_bin("locate")
42+
.expect("couldn't find locate binary")
43+
.args(["test_data1234567890", "--basename", DB_FLAG])
44+
.assert()
45+
.failure();
46+
}
47+
48+
#[test]
49+
#[cfg(not(windows))]
50+
fn test_locate_match_basename() {
51+
Command::cargo_bin("locate")
52+
.expect("couldn't find locate binary")
53+
.args(["abbbc", "--basename", DB_FLAG])
54+
.assert()
55+
.success();
56+
}
57+
58+
#[test]
59+
#[cfg(not(windows))]
60+
fn test_locate_existing() {
61+
Command::cargo_bin("locate")
62+
.expect("couldn't find locate binary")
63+
.args(["abbbc", "--existing", "--database={DB}"])
64+
.assert()
65+
.success();
66+
}
67+
68+
#[test]
69+
#[cfg(not(windows))]
70+
fn test_locate_non_existing() {
71+
Command::cargo_bin("locate")
72+
.expect("couldn't find locate binary")
73+
.args(["abbbc", "--non-existing", DB_FLAG])
74+
.assert()
75+
.failure();
76+
}
77+
78+
#[test]
79+
#[cfg(not(windows))]
80+
fn test_locate_statistics() {
81+
Command::cargo_bin("locate")
82+
.expect("couldn't find locate binary")
83+
.args(["abbbc", "--statistics", DB_FLAG])
84+
.assert()
85+
.success();
86+
}
87+
88+
#[test]
89+
#[cfg(not(windows))]
90+
fn test_locate_regex() {
91+
Command::cargo_bin("locate")
92+
.expect("couldn't find locate binary")
93+
.args(["abbbc", "--regex", DB_FLAG])
94+
.assert()
95+
.success();
96+
}
97+
98+
#[test]
99+
#[cfg(not(windows))]
100+
fn test_locate_all() {
101+
Command::cargo_bin("locate")
102+
.expect("couldn't find locate binary")
103+
.args(["abb", "bbc", "--regex", DB_FLAG])
104+
.assert()
105+
.success();
106+
}
107+
108+
#[test]
109+
#[cfg(not(windows))]
110+
fn test_locate_all_regex() {
111+
Command::cargo_bin("locate")
112+
.expect("couldn't find locate binary")
113+
.args(["abb", "b*c", "--regex", DB_FLAG])
114+
.assert()
115+
.success();
116+
}
117+
118+
#[test]
119+
#[cfg(not(windows))]
120+
fn test_updatedb() {
121+
Command::cargo_bin("updatedb")
122+
.expect("couldn't find updatedb binary")
123+
.args([
124+
fix_up_slashes("--localpaths=./test_data"),
125+
fix_up_slashes("--output=./test_data_db"),
126+
])
127+
.assert()
128+
.success();
115129
}

0 commit comments

Comments
 (0)