Debian Codegraph @

tests/by-util/test_false.rs

raw
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 use regex::Regex;
7 #[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))]
8 use std::fs::OpenOptions;
9 use uutests::new_ucmd;
10
11 #[test]
12 fn test_no_args() {
13 new_ucmd!().fails().no_output();
14 }
15
16 #[test]
17 fn test_version() {
18 let re = Regex::new(r"^false .*\d+\.\d+\.\d+\n$").unwrap();
19
20 new_ucmd!().args(&["--version"]).fails().stdout_matches(&re);
21 }
22
23 #[test]
24 fn test_help() {
25 new_ucmd!()
26 .args(&["--help"])
27 .fails()
28 .stdout_contains("false");
29 }
30
31 #[test]
32 fn test_short_options() {
33 for option in ["-h", "-V"] {
34 new_ucmd!().arg(option).fails().no_output();
35 }
36 }
37
38 #[test]
39 fn test_extra_args() {
40 for option in ["--help", "--version"] {
41 new_ucmd!().args(&[option, "test"]).fails().no_output();
42 }
43 }
44
45 #[test]
46 fn test_conflict() {
47 new_ucmd!()
48 .args(&["--help", "--version"])
49 .fails()
50 .no_output();
51 }
52
53 #[test]
54 #[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))]
55 fn test_full() {
56 for option in ["--version", "--help"] {
57 let dev_full = OpenOptions::new().write(true).open("/dev/full").unwrap();
58
59 new_ucmd!()
60 .arg(option)
61 .set_stdout(dev_full)
62 .fails()
63 .stderr_is("false: No space left on device\n");
64 }
65 }