Skip to content

Commit dcad690

Browse files
committed
refactor tests
1 parent 92c6b88 commit dcad690

3 files changed

Lines changed: 28 additions & 24 deletions

File tree

tests/by-util/test_hostname.rs

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/test_wrapper_binaries.rs

Whitespace-only changes.

tests/tests.rs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
1-
// This file is part of the uutils hostname package.
2-
//
3-
// For the full copyright and license information, please view the LICENSE
4-
// file that was distributed with this source code.
51
use std::env;
2+
use std::sync::Once;
63

7-
pub const TESTS_BINARY: &str = env!("CARGO_BIN_EXE_hostname");
4+
static INIT: Once = Once::new();
85

9-
// Use the ctor attribute to run this function before any tests
10-
#[ctor::ctor]
11-
fn init() {
12-
unsafe {
13-
// Necessary for uutests to be able to find the binary
14-
std::env::set_var("UUTESTS_BINARY_PATH", TESTS_BINARY);
15-
}
6+
fn init_binary_path() {
7+
INIT.call_once(|| {
8+
if let Ok(binary_path) = env::var("CARGO_BIN_EXE_hostname") {
9+
unsafe {
10+
env::set_var("UUTESTS_BINARY_PATH", binary_path);
11+
}
12+
}
13+
});
1614
}
1715

16+
// Call init in each test module that needs it
1817
#[cfg(feature = "hostname")]
19-
#[path = "by-util/test_hostname.rs"]
18+
#[path = "by_util/hostname.rs"]
2019
mod test_hostname;
20+
21+
#[cfg(feature = "domainname")]
22+
#[path = "by_util/domainname.rs"]
23+
mod test_domainname;
24+
25+
#[cfg(feature = "dnsdomainname")]
26+
#[path = "by_util/domainname.rs"]
27+
mod test_dnsdomainname;
28+
29+
#[cfg(feature = "nisdomainname")]
30+
#[path = "by_util/domainname.rs"]
31+
mod test_nisdomainname;
32+
33+
#[cfg(feature = "ypdomainname")]
34+
#[path = "by_util/domainname.rs"]
35+
mod test_ypdomainname;

0 commit comments

Comments
 (0)