Skip to content

Commit 6ef285f

Browse files
committed
fix(tests): refine feature checks for SELinux
1 parent 0baa689 commit 6ef285f

10 files changed

Lines changed: 30 additions & 30 deletions

File tree

tests/by-util/test_chcon.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// file that was distributed with this source code.
55
// spell-checker:ignore (jargon) xattributes
66
#![allow(clippy::missing_errors_doc, clippy::similar_names)]
7-
#![cfg(feature = "feat_selinux")]
7+
#![cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
88

99
use std::ffi::CString;
1010
use std::path::Path;

tests/by-util/test_cp.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#[cfg(unix)]
99
use rstest::rstest;
1010
use uucore::display::Quotable;
11-
#[cfg(feature = "feat_selinux")]
11+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
1212
use uucore::selinux::get_getfattr_output;
1313
use uutests::util::TestScenario;
1414
use uutests::{at_and_ucmd, new_ucmd, path_concat, util_name};
@@ -6771,7 +6771,7 @@ fn test_cp_from_stream_permission() {
67716771
}
67726772

67736773
#[test]
6774-
#[cfg(feature = "feat_selinux")]
6774+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
67756775
fn test_cp_selinux() {
67766776
let ts = TestScenario::new(util_name!());
67776777
let at = &ts.fixtures;
@@ -6820,7 +6820,7 @@ fn test_cp_selinux_invalid() {
68206820
}
68216821

68226822
#[test]
6823-
#[cfg(feature = "feat_selinux")]
6823+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
68246824
fn test_cp_preserve_selinux() {
68256825
let ts = TestScenario::new(util_name!());
68266826
let at = &ts.fixtures;
@@ -6858,7 +6858,7 @@ fn test_cp_preserve_selinux() {
68586858
}
68596859

68606860
#[test]
6861-
#[cfg(feature = "feat_selinux")]
6861+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
68626862
fn test_cp_preserve_selinux_admin_context() {
68636863
let ts = TestScenario::new(util_name!());
68646864
let at = &ts.fixtures;
@@ -6917,7 +6917,7 @@ fn test_cp_preserve_selinux_admin_context() {
69176917
}
69186918

69196919
#[test]
6920-
#[cfg(feature = "feat_selinux")]
6920+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
69216921
fn test_cp_selinux_context_priority() {
69226922
// This test verifies that -Z takes priority over --context
69236923

@@ -6997,7 +6997,7 @@ fn test_cp_selinux_context_priority() {
69976997
}
69986998

69996999
#[test]
7000-
#[cfg(feature = "feat_selinux")]
7000+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
70017001
fn test_cp_selinux_empty_context() {
70027002
// This test verifies that --context without a value works like -Z
70037003

@@ -7043,7 +7043,7 @@ fn test_cp_selinux_empty_context() {
70437043
}
70447044

70457045
#[test]
7046-
#[cfg(feature = "feat_selinux")]
7046+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
70477047
fn test_cp_selinux_recursive() {
70487048
// Test SELinux context preservation in recursive directory copies
70497049

@@ -7097,7 +7097,7 @@ fn test_cp_selinux_recursive() {
70977097
}
70987098

70997099
#[test]
7100-
#[cfg(feature = "feat_selinux")]
7100+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
71017101
fn test_cp_preserve_context_root() {
71027102
use uutests::util::run_ucmd_as_root;
71037103
let scene = TestScenario::new(util_name!());
@@ -7800,7 +7800,7 @@ fn test_cp_gnu_preserve_mode() {
78007800
}
78017801

78027802
#[test]
7803-
#[cfg(feature = "feat_selinux")]
7803+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
78047804
fn test_cp_a_z_overrides_context() {
78057805
// Verifies -aZ succeeds (-Z overrides implicit --preserve=context from -a)
78067806
use std::path::Path;
@@ -7818,7 +7818,7 @@ fn test_cp_a_z_overrides_context() {
78187818
}
78197819

78207820
#[test]
7821-
#[cfg(feature = "feat_selinux")]
7821+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
78227822
fn test_cp_a_preserves_context() {
78237823
use std::path::Path;
78247824
use uucore::selinux::{get_selinux_security_context, set_selinux_security_context};

tests/by-util/test_id.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ fn test_id_zero() {
383383
}
384384

385385
#[test]
386-
#[cfg(feature = "feat_selinux")]
386+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
387387
fn test_id_context() {
388388
if !uucore::selinux::is_selinux_enabled() {
389389
println!("test skipped: Kernel has no support for SElinux context");

tests/by-util/test_install.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::process;
1515
#[cfg(any(target_os = "linux", target_os = "android"))]
1616
use std::thread::sleep;
1717
use uucore::process::{getegid, geteuid};
18-
#[cfg(feature = "feat_selinux")]
18+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
1919
use uucore::selinux::get_getfattr_output;
2020
use uutests::at_and_ucmd;
2121
use uutests::new_ucmd;
@@ -2334,7 +2334,7 @@ fn test_install_no_target_basic() {
23342334
}
23352335

23362336
#[test]
2337-
#[cfg(feature = "feat_selinux")]
2337+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
23382338
fn test_selinux() {
23392339
let scene = TestScenario::new(util_name!());
23402340
let at = &scene.fixtures;

tests/by-util/test_ls.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4656,7 +4656,7 @@ fn test_ls_dangling_symlinks() {
46564656
}
46574657

46584658
#[test]
4659-
#[cfg(feature = "feat_selinux")]
4659+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
46604660
fn test_ls_context1() {
46614661
if !uucore::selinux::is_selinux_enabled() {
46624662
println!("test skipped: Kernel has no support for SElinux context");
@@ -4671,7 +4671,7 @@ fn test_ls_context1() {
46714671
}
46724672

46734673
#[test]
4674-
#[cfg(feature = "feat_selinux")]
4674+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
46754675
fn test_ls_context2() {
46764676
if !uucore::selinux::is_selinux_enabled() {
46774677
println!("test skipped: Kernel has no support for SElinux context");
@@ -4687,7 +4687,7 @@ fn test_ls_context2() {
46874687
}
46884688

46894689
#[test]
4690-
#[cfg(feature = "feat_selinux")]
4690+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
46914691
fn test_ls_context_long() {
46924692
if !uucore::selinux::is_selinux_enabled() {
46934693
return;
@@ -4706,7 +4706,7 @@ fn test_ls_context_long() {
47064706
}
47074707

47084708
#[test]
4709-
#[cfg(feature = "feat_selinux")]
4709+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
47104710
fn test_ls_context_format() {
47114711
if !uucore::selinux::is_selinux_enabled() {
47124712
println!("test skipped: Kernel has no support for SElinux context");
@@ -4736,7 +4736,7 @@ fn test_ls_context_format() {
47364736
}
47374737

47384738
/// Helper function to validate `SELinux` context format
4739-
#[cfg(feature = "feat_selinux")]
4739+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
47404740
fn validate_selinux_context(context: &str) {
47414741
assert!(
47424742
context.contains(':'),
@@ -4751,7 +4751,7 @@ fn validate_selinux_context(context: &str) {
47514751
}
47524752

47534753
#[test]
4754-
#[cfg(feature = "feat_selinux")]
4754+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
47554755
fn test_ls_selinux_context_format() {
47564756
if !uucore::selinux::is_selinux_enabled() {
47574757
println!("test skipped: Kernel has no support for SElinux context");
@@ -4784,7 +4784,7 @@ fn test_ls_selinux_context_format() {
47844784
}
47854785

47864786
#[test]
4787-
#[cfg(feature = "feat_selinux")]
4787+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
47884788
fn test_ls_selinux_context_indicator() {
47894789
if !uucore::selinux::is_selinux_enabled() {
47904790
println!("test skipped: Kernel has no support for SElinux context");

tests/by-util/test_mkdir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use libc::mode_t;
1212
#[cfg(not(windows))]
1313
use std::os::unix::fs::PermissionsExt;
14-
#[cfg(feature = "feat_selinux")]
14+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
1515
use uucore::selinux::get_getfattr_output;
1616
#[cfg(not(windows))]
1717
use uutests::at_and_ucmd;
@@ -449,7 +449,7 @@ fn test_empty_argument() {
449449
}
450450

451451
#[test]
452-
#[cfg(feature = "feat_selinux")]
452+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
453453
fn test_selinux() {
454454
let scene = TestScenario::new(util_name!());
455455
let at = &scene.fixtures;

tests/by-util/test_mkfifo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
// spell-checker:ignore nconfined
77

8-
#[cfg(feature = "feat_selinux")]
8+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
99
use uucore::selinux::get_getfattr_output;
1010
use uutests::new_ucmd;
1111
use uutests::util::TestScenario;
@@ -167,7 +167,7 @@ fn test_create_fifo_permission_denied() {
167167
}
168168

169169
#[test]
170-
#[cfg(feature = "feat_selinux")]
170+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
171171
fn test_mkfifo_selinux() {
172172
let ts = TestScenario::new(util_name!());
173173
let at = &ts.fixtures;

tests/by-util/test_mknod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use std::os::unix::fs::PermissionsExt;
99

10-
#[cfg(feature = "feat_selinux")]
10+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
1111
use uucore::selinux::get_getfattr_output;
1212
use uutests::new_ucmd;
1313
use uutests::util::TestScenario;
@@ -184,7 +184,7 @@ fn test_mknod_mode_comma_separated() {
184184
}
185185

186186
#[test]
187-
#[cfg(feature = "feat_selinux")]
187+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
188188
fn test_mknod_selinux() {
189189
let ts = TestScenario::new(util_name!());
190190
let at = &ts.fixtures;

tests/by-util/test_mv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rstest::rstest;
1010
use std::io::Write;
1111
#[cfg(not(windows))]
1212
use std::path::Path;
13-
#[cfg(feature = "feat_selinux")]
13+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
1414
use uucore::selinux::get_getfattr_output;
1515
use uutests::new_ucmd;
1616
#[cfg(unix)]
@@ -2617,7 +2617,7 @@ fn test_mv_cross_device_permission_denied() {
26172617
}
26182618

26192619
#[test]
2620-
#[cfg(feature = "feat_selinux")]
2620+
#[cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
26212621
fn test_mv_selinux_context() {
26222622
let test_cases = [
26232623
("-Z", None),

tests/by-util/test_runcon.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// file that was distributed with this source code.
55
// spell-checker:ignore (jargon) xattributes
66

7-
#![cfg(feature = "feat_selinux")]
7+
#![cfg(all(feature = "feat_selinux", any(target_os = "linux", target_os = "android")))]
88

99
use uutests::new_ucmd;
1010

0 commit comments

Comments
 (0)