File: test_nice.rs

package info (click to toggle)
rust-coreutils 0.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 485,976 kB
  • sloc: ansic: 103,608; asm: 28,570; sh: 8,672; python: 5,662; makefile: 474; cpp: 97; javascript: 72
file content (122 lines) | stat: -rw-r--r-- 3,145 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// This file is part of the uutils coreutils package.
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore libc's setpriority
use uutests::new_ucmd;

#[test]
#[cfg(not(target_os = "android"))]
fn test_get_current_niceness() {
    // Test that the nice command with no arguments returns the default nice
    // value, which we determine by querying libc's `nice` in our own process.
    new_ucmd!()
        .succeeds()
        .stdout_is(format!("{}\n", unsafe { libc::nice(0) }));
}

#[test]
#[cfg(not(target_os = "android"))]
fn test_negative_adjustment() {
    // This assumes the test suite is run as a normal (non-root) user, and as
    // such attempting to set a negative niceness value will be rejected by
    // the OS.  If it gets denied, then we know a negative value was parsed
    // correctly.

    let res = new_ucmd!().args(&["-n", "-1", "true"]).succeeds();
    assert!(
        res.stderr_str()
            .starts_with("nice: warning: setpriority: Permission denied")
    ); // spell-checker:disable-line
}

#[test]
fn test_adjustment_with_no_command_should_error() {
    new_ucmd!()
        .args(&["-n", "19"])
        .fails()
        .usage_error("A command must be given with an adjustment.");
}

#[test]
fn test_command_with_no_adjustment() {
    new_ucmd!().args(&["echo", "a"]).succeeds().stdout_is("a\n");
}

#[test]
fn test_command_with_no_args() {
    new_ucmd!()
        .args(&["-n", "19", "echo"])
        .succeeds()
        .stdout_is("\n");
}

#[test]
fn test_command_with_args() {
    new_ucmd!()
        .args(&["-n", "19", "echo", "a", "b", "c"])
        .succeeds()
        .stdout_is("a b c\n");
}

#[test]
fn test_command_where_command_takes_n_flag() {
    new_ucmd!()
        .args(&["-n", "19", "echo", "-n", "a"])
        .succeeds()
        .stdout_is("a");
}

#[test]
fn test_invalid_argument() {
    new_ucmd!().arg("--invalid").fails_with_code(125);
}

#[test]
fn test_bare_adjustment() {
    new_ucmd!()
        .args(&["-1", "echo", "-n", "a"])
        .succeeds()
        .stdout_is("a");
}

#[test]
fn test_trailing_empty_adjustment() {
    new_ucmd!()
        .args(&["-n", "1", "-n"])
        .fails()
        .stderr_str()
        .starts_with(
        "error: The argument '--adjustment <adjustment>' requires a value but none was supplied",
    );
}

#[test]
fn test_nice_huge() {
    new_ucmd!()
        .args(&[
            "-n",
            "99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999",
            "true",
        ])
        .succeeds()
        .no_stdout();
}

#[test]
fn test_nice_huge_negative() {
    new_ucmd!().args(&["-n", "-9999999999", "true"]).succeeds();
    //.stderr_contains("Permission denied"); Depending on platform?
}

#[test]
fn test_sign_middle() {
    new_ucmd!()
        .args(&["-n", "-2+4", "true"])
        .fails_with_code(125)
        .no_stdout()
        .stderr_contains("invalid");
}
//uu: "-2+4" is not a valid number: invalid digit found in string
//gnu: invalid adjustment `-2+4'
//Both message is fine