Skip to content

Commit e5980d4

Browse files
sylvestrejtracey
authored andcommitted
printf: simplify and dedup some tests
1 parent 8ff0db1 commit e5980d4

File tree

1 file changed

+20
-117
lines changed

1 file changed

+20
-117
lines changed

tests/by-util/test_printf.rs

Lines changed: 20 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,6 @@ fn basic_literal() {
1616
.stdout_only("hello world");
1717
}
1818

19-
#[test]
20-
fn escaped_tab() {
21-
new_ucmd!()
22-
.args(&["hello\\t world"])
23-
.succeeds()
24-
.stdout_only("hello\t world");
25-
}
26-
27-
#[test]
28-
fn escaped_newline() {
29-
new_ucmd!()
30-
.args(&["hello\\n world"])
31-
.succeeds()
32-
.stdout_only("hello\n world");
33-
}
34-
35-
#[test]
36-
fn escaped_slash() {
37-
new_ucmd!()
38-
.args(&["hello\\\\ world"])
39-
.succeeds()
40-
.stdout_only("hello\\ world");
41-
}
42-
43-
#[test]
44-
fn unescaped_double_quote() {
45-
new_ucmd!().args(&["\\\""]).succeeds().stdout_only("\"");
46-
}
47-
48-
#[test]
49-
fn escaped_hex() {
50-
new_ucmd!().args(&["\\x41"]).succeeds().stdout_only("A");
51-
}
52-
5319
#[test]
5420
fn test_missing_escaped_hex_value() {
5521
new_ucmd!()
@@ -58,17 +24,12 @@ fn test_missing_escaped_hex_value() {
5824
.stderr_only("printf: missing hexadecimal number in escape\n");
5925
}
6026

61-
#[test]
62-
fn escaped_octal() {
63-
new_ucmd!().args(&["\\101"]).succeeds().stdout_only("A");
64-
}
65-
6627
#[test]
6728
fn escaped_octal_and_newline() {
6829
new_ucmd!()
69-
.args(&["\\0377\\n"])
30+
.args(&["\\101\\0377\\n"])
7031
.succeeds()
71-
.stdout_only("\x1F7\n");
32+
.stdout_only("A\x1F7\n");
7233
}
7334

7435
#[test]
@@ -145,38 +106,6 @@ fn escaped_unrecognized() {
145106
new_ucmd!().args(&["c\\d"]).succeeds().stdout_only("c\\d");
146107
}
147108

148-
#[test]
149-
fn sub_string() {
150-
new_ucmd!()
151-
.args(&["hello %s", "world"])
152-
.succeeds()
153-
.stdout_only("hello world");
154-
}
155-
156-
#[test]
157-
fn sub_multi_field() {
158-
new_ucmd!()
159-
.args(&["%s %s", "hello", "world"])
160-
.succeeds()
161-
.stdout_only("hello world");
162-
}
163-
164-
#[test]
165-
fn sub_repeat_format_str() {
166-
new_ucmd!()
167-
.args(&["%s.", "hello", "world"])
168-
.succeeds()
169-
.stdout_only("hello.world.");
170-
}
171-
172-
#[test]
173-
fn sub_string_ignore_escapes() {
174-
new_ucmd!()
175-
.args(&["hello %s", "\\tworld"])
176-
.succeeds()
177-
.stdout_only("hello \\tworld");
178-
}
179-
180109
#[test]
181110
fn sub_b_string_handle_escapes() {
182111
new_ucmd!()
@@ -705,27 +634,11 @@ fn sub_any_asterisk_second_param_with_integer() {
705634
}
706635

707636
#[test]
708-
fn sub_any_specifiers_no_params() {
709-
new_ucmd!()
710-
.args(&["%ztlhLji", "3"]) //spell-checker:disable-line
711-
.succeeds()
712-
.stdout_only("3");
713-
}
714-
715-
#[test]
716-
fn sub_any_specifiers_after_first_param() {
717-
new_ucmd!()
718-
.args(&["%0ztlhLji", "3"]) //spell-checker:disable-line
719-
.succeeds()
720-
.stdout_only("3");
721-
}
722-
723-
#[test]
724-
fn sub_any_specifiers_after_period() {
725-
new_ucmd!()
726-
.args(&["%0.ztlhLji", "3"]) //spell-checker:disable-line
727-
.succeeds()
728-
.stdout_only("3");
637+
fn sub_any_specifiers() {
638+
// spell-checker:disable-next-line
639+
for format in ["%ztlhLji", "%0ztlhLji", "%0.ztlhLji"] {
640+
new_ucmd!().args(&[format, "3"]).succeeds().stdout_only("3");
641+
}
729642
}
730643

731644
#[test]
@@ -1027,33 +940,23 @@ fn pad_string() {
1027940
}
1028941

1029942
#[test]
1030-
fn format_spec_zero_char_fails() {
1031-
// It is invalid to have the format spec '%0c'
1032-
new_ucmd!().args(&["%0c", "3"]).fails_with_code(1);
1033-
}
1034-
1035-
#[test]
1036-
fn format_spec_zero_string_fails() {
1037-
// It is invalid to have the format spec '%0s'
1038-
new_ucmd!().args(&["%0s", "3"]).fails_with_code(1);
1039-
}
1040-
1041-
#[test]
1042-
fn invalid_precision_fails() {
1043-
// It is invalid to have length of output string greater than i32::MAX
1044-
new_ucmd!()
1045-
.args(&["%.*d", "2147483648", "0"])
1046-
.fails()
1047-
.stderr_is("printf: invalid precision: '2147483648'\n");
943+
fn format_spec_zero_fails() {
944+
// It is invalid to have the format spec
945+
for format in ["%0c", "%0s"] {
946+
new_ucmd!().args(&[format, "3"]).fails_with_code(1);
947+
}
1048948
}
1049949

1050950
#[test]
1051-
fn float_invalid_precision_fails() {
951+
fn invalid_precision_tests() {
1052952
// It is invalid to have length of output string greater than i32::MAX
1053-
new_ucmd!()
1054-
.args(&["%.*f", "2147483648", "0"])
1055-
.fails()
1056-
.stderr_is("printf: invalid precision: '2147483648'\n");
953+
for format in ["%.*d", "%.*f"] {
954+
let expected_error = "printf: invalid precision: '2147483648'\n";
955+
new_ucmd!()
956+
.args(&[format, "2147483648", "0"])
957+
.fails()
958+
.stderr_is(expected_error);
959+
}
1057960
}
1058961

1059962
// The following padding-tests test for the cases in which flags in ['0', ' '] are given.

0 commit comments

Comments
 (0)