mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-09-16 19:56:17 +00:00
Merge branch 'main' into cp-lb
This commit is contained in:
commit
430a6650e0
10 changed files with 939 additions and 355 deletions
|
@ -1,3 +1,4 @@
|
|||
// spell-checker:ignore udev
|
||||
use crate::common::util::*;
|
||||
|
||||
#[test]
|
||||
|
@ -77,4 +78,47 @@ fn test_type_option() {
|
|||
new_ucmd!().args(&["-t", "ext4", "-t", "ext3"]).succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_total() {
|
||||
// Example output:
|
||||
//
|
||||
// Filesystem 1K-blocks Used Available Use% Mounted on
|
||||
// udev 3858016 0 3858016 0% /dev
|
||||
// ...
|
||||
// /dev/loop14 63488 63488 0 100% /snap/core20/1361
|
||||
// total 258775268 98099712 148220200 40% -
|
||||
let output = new_ucmd!().arg("--total").succeeds().stdout_move_str();
|
||||
|
||||
// Skip the header line.
|
||||
let lines: Vec<&str> = output.lines().skip(1).collect();
|
||||
|
||||
// Parse the values from the last row.
|
||||
let last_line = lines.last().unwrap();
|
||||
let mut iter = last_line.split_whitespace();
|
||||
assert_eq!(iter.next().unwrap(), "total");
|
||||
let reported_total_size = iter.next().unwrap().parse().unwrap();
|
||||
let reported_total_used = iter.next().unwrap().parse().unwrap();
|
||||
let reported_total_avail = iter.next().unwrap().parse().unwrap();
|
||||
|
||||
// Loop over each row except the last, computing the sum of each column.
|
||||
let mut computed_total_size = 0;
|
||||
let mut computed_total_used = 0;
|
||||
let mut computed_total_avail = 0;
|
||||
let n = lines.len();
|
||||
for line in &lines[..n - 1] {
|
||||
let mut iter = line.split_whitespace();
|
||||
iter.next().unwrap();
|
||||
computed_total_size += iter.next().unwrap().parse::<u64>().unwrap();
|
||||
computed_total_used += iter.next().unwrap().parse::<u64>().unwrap();
|
||||
computed_total_avail += iter.next().unwrap().parse::<u64>().unwrap();
|
||||
}
|
||||
|
||||
// Check that the sum of each column matches the reported value in
|
||||
// the last row.
|
||||
assert_eq!(computed_total_size, reported_total_size);
|
||||
assert_eq!(computed_total_used, reported_total_used);
|
||||
assert_eq!(computed_total_avail, reported_total_avail);
|
||||
// TODO We could also check here that the use percentage matches.
|
||||
}
|
||||
|
||||
// ToDO: more tests...
|
||||
|
|
|
@ -448,3 +448,16 @@ fn test_with_join_lines_option() {
|
|||
&valid_last_modified_template_vars(start),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_value_for_number_lines() {
|
||||
// *5 is of the form [SEP[NUMBER]] so is accepted and succeeds
|
||||
new_ucmd!().args(&["-n", "*5", "test.log"]).succeeds();
|
||||
|
||||
// a is of the form [SEP[NUMBER]] so is accepted and succeeds
|
||||
new_ucmd!().args(&["-n", "a", "test.log"]).succeeds();
|
||||
|
||||
// foo5.txt is of not the form [SEP[NUMBER]] so is not used as value.
|
||||
// Therefore, pr tries to access the file, which does not exist.
|
||||
new_ucmd!().args(&["-n", "foo5.txt", "test.log"]).fails();
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// *
|
||||
// * For the full copyright and license information, please view the LICENSE
|
||||
// * file that was distributed with this source code.
|
||||
// spell-checker:ignore xzaaa sixhundredfiftyonebytes ninetyonebytes threebytes asciilowercase fghij klmno pqrst uvwxyz fivelines twohundredfortyonebytes
|
||||
// spell-checker:ignore xzaaa sixhundredfiftyonebytes ninetyonebytes threebytes asciilowercase fghij klmno pqrst uvwxyz fivelines twohundredfortyonebytes onehundredlines
|
||||
extern crate rand;
|
||||
extern crate regex;
|
||||
|
||||
|
@ -587,3 +587,11 @@ fn test_lines() {
|
|||
assert_eq!(file_read("xaa"), "1\n2\n3\n");
|
||||
assert_eq!(file_read("xab"), "4\n5\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_lines_kth() {
|
||||
new_ucmd!()
|
||||
.args(&["-n", "l/3/10", "onehundredlines.txt"])
|
||||
.succeeds()
|
||||
.stdout_only("20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n");
|
||||
}
|
||||
|
|
100
tests/fixtures/split/onehundredlines.txt
vendored
Normal file
100
tests/fixtures/split/onehundredlines.txt
vendored
Normal file
|
@ -0,0 +1,100 @@
|
|||
00
|
||||
01
|
||||
02
|
||||
03
|
||||
04
|
||||
05
|
||||
06
|
||||
07
|
||||
08
|
||||
09
|
||||
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
|
Loading…
Add table
Add a link
Reference in a new issue