| 1 |
// This file is part of the uutils coreutils package. |
| 2 |
// |
| 3 |
// For the full copyright and license information, please view the LICENSE |
| 4 |
// file that was distributed with this source code. |
| 5 |
|
| 6 |
// spell-checker:ignore getpriority setpriority |
| 7 |
#[cfg(unix)] |
| 8 |
use uutests::new_ucmd; |
| 9 |
|
| 10 |
#[test] |
| 11 |
#[cfg(unix)] |
| 12 |
#[cfg(not(target_os = "android"))] |
| 13 |
fn test_get_current_niceness() { |
| 14 |
// Test that the nice command with no arguments returns the default nice value |
| 15 |
let nice = rustix::process::getpriority_process(None).unwrap(); |
| 16 |
new_ucmd!().succeeds().stdout_is(format!("{nice}\n")); |
| 17 |
} |
| 18 |
|
| 19 |
#[test] |
| 20 |
#[cfg(unix)] |
| 21 |
#[cfg(not(target_os = "android"))] |
| 22 |
fn test_nice_adj_negative() { |
| 23 |
// This assumes the test suite is run as a normal (non-root) user, and as |
| 24 |
// such attempting to set a negative niceness value will be rejected by |
| 25 |
// the OS. If it gets denied, then we know a negative value was parsed |
| 26 |
// correctly. |
| 27 |
|
| 28 |
new_ucmd!() |
| 29 |
.args(&["--adj", "-20", "true"]) |
| 30 |
.succeeds() |
| 31 |
.stderr_is("nice: warning: setpriority: Permission denied\n"); |
| 32 |
} |
| 33 |
|
| 34 |
#[test] |
| 35 |
#[cfg(unix)] |
| 36 |
fn test_adjustment_with_no_command_should_error() { |
| 37 |
new_ucmd!() |
| 38 |
.args(&["-n", "19"]) |
| 39 |
.fails() |
| 40 |
.usage_error("A command must be given with an adjustment."); |
| 41 |
} |
| 42 |
|
| 43 |
#[test] |
| 44 |
#[cfg(unix)] |
| 45 |
fn test_command_with_no_adjustment() { |
| 46 |
new_ucmd!().args(&["echo", "a"]).succeeds().stdout_is("a\n"); |
| 47 |
} |
| 48 |
|
| 49 |
#[test] |
| 50 |
#[cfg(unix)] |
| 51 |
fn test_command_with_no_args() { |
| 52 |
new_ucmd!() |
| 53 |
.args(&["-n", "19", "echo"]) |
| 54 |
.succeeds() |
| 55 |
.stdout_is("\n"); |
| 56 |
} |
| 57 |
|
| 58 |
#[test] |
| 59 |
#[cfg(unix)] |
| 60 |
fn test_command_with_args() { |
| 61 |
new_ucmd!() |
| 62 |
.args(&["-n", "19", "echo", "a", "b", "c"]) |
| 63 |
.succeeds() |
| 64 |
.stdout_is("a b c\n"); |
| 65 |
} |
| 66 |
|
| 67 |
#[test] |
| 68 |
#[cfg(unix)] |
| 69 |
fn test_command_where_command_takes_n_flag() { |
| 70 |
new_ucmd!() |
| 71 |
.args(&["-n", "19", "echo", "-n", "a"]) |
| 72 |
.succeeds() |
| 73 |
.stdout_is("a"); |
| 74 |
} |
| 75 |
|
| 76 |
#[test] |
| 77 |
#[cfg(unix)] |
| 78 |
fn test_invalid_argument() { |
| 79 |
new_ucmd!().arg("--invalid").fails_with_code(125); |
| 80 |
} |
| 81 |
|
| 82 |
#[test] |
| 83 |
#[cfg(unix)] |
| 84 |
fn test_bare_adjustment() { |
| 85 |
new_ucmd!() |
| 86 |
.args(&["-1", "echo", "-n", "a"]) |
| 87 |
.succeeds() |
| 88 |
.stdout_is("a"); |
| 89 |
} |
| 90 |
|
| 91 |
#[test] |
| 92 |
#[cfg(unix)] |
| 93 |
fn test_trailing_empty_adjustment() { |
| 94 |
new_ucmd!() |
| 95 |
.args(&["-n", "1", "-n"]) |
| 96 |
.fails() |
| 97 |
.stderr_str() |
| 98 |
.starts_with( |
| 99 |
"error: The argument '--adjustment <adjustment>' requires a value but none was supplied", |
| 100 |
); |
| 101 |
} |
| 102 |
|
| 103 |
#[test] |
| 104 |
#[cfg(unix)] |
| 105 |
fn test_nice_huge() { |
| 106 |
new_ucmd!() |
| 107 |
.args(&[ |
| 108 |
"-n", |
| 109 |
"99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", |
| 110 |
"true", |
| 111 |
]) |
| 112 |
.succeeds() |
| 113 |
.no_stdout(); |
| 114 |
} |
| 115 |
|
| 116 |
#[test] |
| 117 |
#[cfg(unix)] |
| 118 |
fn test_nice_huge_negative() { |
| 119 |
new_ucmd!().args(&["-n", "-9999999999", "true"]).succeeds(); |
| 120 |
//.stderr_contains("Permission denied"); Depending on platform? |
| 121 |
} |
| 122 |
|
| 123 |
#[test] |
| 124 |
#[cfg(unix)] |
| 125 |
fn test_sign_middle() { |
| 126 |
new_ucmd!() |
| 127 |
.args(&["-n", "-2+4", "true"]) |
| 128 |
.fails_with_code(125) |
| 129 |
.no_stdout() |
| 130 |
.stderr_contains("invalid"); |
| 131 |
} |
| 132 |
//uu: "-2+4" is not a valid number: invalid digit found in string |
| 133 |
//gnu: invalid adjustment `-2+4' |
| 134 |
//Both message is fine |