Skip to content

Commit c661abe

Browse files
committed
CodeHealth: remove testing-commandline from production builds #19
1 parent 1266b7f commit c661abe

6 files changed

Lines changed: 39 additions & 7 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646

4747
- name: Test
4848
run: |
49-
cargo test
49+
cargo test --features testing_commandline
5050
5151
fmt:
5252
name: cargo fmt --all -- --check

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ path = "src/xargs/main.rs"
3838
[[bin]]
3939
name = "testing-commandline"
4040
path = "src/testing/commandline/main.rs"
41+
required-features = ["testing_commandline"]
42+
43+
[features]
44+
testing_commandline = []
4145

4246
[profile.release]
4347
lto = "thin"

tests/common/test_helpers.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// https://opensource.org/licenses/MIT.
66

77
use std::cell::RefCell;
8+
#[cfg(feature = "testing_commandline")]
89
use std::env;
910
use std::io::{Cursor, Read, Write};
1011
use std::path::Path;
@@ -52,6 +53,7 @@ impl Dependencies for FakeDependencies {
5253
}
5354
}
5455

56+
#[cfg(feature = "testing_commandline")]
5557
pub fn path_to_testing_commandline() -> String {
5658
let mut path_to_use = env::current_exe()
5759
// this will be something along the lines of /my/homedir/findutils/target/debug/deps/findutils-5532804878869ef1

tests/exec_unit_tests.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,28 @@
88
/// ! But as the tests require running an external executable, they need to be run
99
/// ! as integration tests so we can ensure that our testing-commandline binary
1010
/// ! has been built.
11-
use std::env;
12-
use std::fs::File;
13-
use std::io::Read;
11+
#[cfg(feature = "testing_commandline")]
12+
use std::{env, fs::File, io::Read};
1413
use std::path::Path;
14+
15+
#[cfg(feature = "testing_commandline")]
1516
use tempfile::Builder;
1617

18+
#[cfg(feature = "testing_commandline")]
19+
use common::test_helpers::{fix_up_slashes, path_to_testing_commandline};
1720
use common::test_helpers::{
18-
fix_up_slashes, get_dir_entry_for, path_to_testing_commandline, FakeDependencies,
21+
get_dir_entry_for, FakeDependencies,
1922
};
20-
use findutils::find::matchers::exec::{MultiExecMatcher, SingleExecMatcher};
21-
use findutils::find::matchers::{Matcher, MatcherIO};
23+
#[cfg(feature = "testing_commandline")]
24+
use findutils::find::matchers::exec::SingleExecMatcher;
25+
use findutils::find::matchers::exec::MultiExecMatcher;
26+
#[cfg(feature = "testing_commandline")]
27+
use findutils::find::matchers::MatcherIO;
28+
use findutils::find::matchers::Matcher;
2229

2330
mod common;
2431

32+
#[cfg(feature = "testing_commandline")]
2533
#[test]
2634
fn matching_executes_code() {
2735
let temp_dir = Builder::new()
@@ -53,6 +61,7 @@ fn matching_executes_code() {
5361
);
5462
}
5563

64+
#[cfg(feature = "testing_commandline")]
5665
#[test]
5766
fn matching_executes_code_in_files_directory() {
5867
let temp_dir = Builder::new()
@@ -84,6 +93,7 @@ fn matching_executes_code_in_files_directory() {
8493
);
8594
}
8695

96+
#[cfg(feature = "testing_commandline")]
8797
#[test]
8898
fn matching_embedded_filename() {
8999
let temp_dir = Builder::new()
@@ -115,6 +125,7 @@ fn matching_embedded_filename() {
115125
);
116126
}
117127

128+
#[cfg(feature = "testing_commandline")]
118129
#[test]
119130
/// Running "find . -execdir whatever \;" failed with a No such file or directory error.
120131
/// It's now fixed, and this is a regression test to check that it stays fixed.
@@ -148,6 +159,7 @@ fn execdir_in_current_directory() {
148159
);
149160
}
150161

162+
#[cfg(feature = "testing_commandline")]
151163
#[test]
152164
/// Regression test for "find / -execdir whatever \;"
153165
fn execdir_in_root_directory() {
@@ -187,6 +199,7 @@ fn execdir_in_root_directory() {
187199
);
188200
}
189201

202+
#[cfg(feature = "testing_commandline")]
190203
#[test]
191204
fn matching_fails_if_executable_fails() {
192205
let temp_dir = Builder::new()
@@ -225,6 +238,7 @@ fn matching_fails_if_executable_fails() {
225238
);
226239
}
227240

241+
#[cfg(feature = "testing_commandline")]
228242
#[test]
229243
fn matching_multi_executes_code() {
230244
let temp_dir = Builder::new()
@@ -258,6 +272,7 @@ fn matching_multi_executes_code() {
258272
);
259273
}
260274

275+
#[cfg(feature = "testing_commandline")]
261276
#[test]
262277
fn execdir_multi_in_current_directory() {
263278
let temp_dir = Builder::new()
@@ -292,6 +307,7 @@ fn execdir_multi_in_current_directory() {
292307
);
293308
}
294309

310+
#[cfg(feature = "testing_commandline")]
295311
#[test]
296312
fn multi_set_exit_code_if_executable_fails() {
297313
let temp_dir = Builder::new()

tests/find_exec_tests.rs

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

7+
#![cfg(feature = "testing_commandline")]
78
/// ! This file contains what would be normally be unit tests for `find::find_main`
89
/// ! related to -exec[dir] and ok[dir] clauses.
910
/// ! But as the tests require running an external executable, they need to be run

tests/test_xargs.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// testing-commandline binary is guaranteed to be built first.
1010
use uutests::util::TestScenario;
1111

12+
#[cfg(feature = "testing_commandline")]
1213
use common::test_helpers::path_to_testing_commandline;
1314

1415
mod common;
@@ -185,6 +186,7 @@ fn xargs_exit_on_large() {
185186
.no_stdout();
186187
}
187188

189+
#[cfg(feature = "testing_commandline")]
188190
#[test]
189191
fn xargs_exec() {
190192
let result = ucmd()
@@ -205,6 +207,7 @@ fn xargs_exec() {
205207
);
206208
}
207209

210+
#[cfg(feature = "testing_commandline")]
208211
#[test]
209212
fn xargs_exec_stdin_open() {
210213
let temp_file = tempfile::NamedTempFile::new().unwrap();
@@ -228,6 +231,7 @@ fn xargs_exec_stdin_open() {
228231
);
229232
}
230233

234+
#[cfg(feature = "testing_commandline")]
231235
#[test]
232236
fn xargs_exec_failure() {
233237
let result = ucmd()
@@ -249,6 +253,7 @@ fn xargs_exec_failure() {
249253
);
250254
}
251255

256+
#[cfg(feature = "testing_commandline")]
252257
#[test]
253258
fn xargs_exec_urgent_failure() {
254259
let result = ucmd()
@@ -272,6 +277,7 @@ fn xargs_exec_urgent_failure() {
272277
);
273278
}
274279

280+
#[cfg(feature = "testing_commandline")]
275281
#[test]
276282
#[cfg(unix)]
277283
fn xargs_exec_with_signal() {
@@ -305,6 +311,7 @@ fn xargs_exec_not_found() {
305311
.no_stdout();
306312
}
307313

314+
#[cfg(feature = "testing_commandline")]
308315
#[test]
309316
fn xargs_exec_verbose() {
310317
ucmd()
@@ -325,6 +332,7 @@ fn xargs_exec_verbose() {
325332
);
326333
}
327334

335+
#[cfg(feature = "testing_commandline")]
328336
#[test]
329337
fn xargs_unterminated_quote() {
330338
ucmd()
@@ -341,6 +349,7 @@ fn xargs_unterminated_quote() {
341349
.no_stdout();
342350
}
343351

352+
#[cfg(feature = "testing_commandline")]
344353
#[test]
345354
fn xargs_zero_lines() {
346355
ucmd()

0 commit comments

Comments
 (0)