]> git.lizzy.rs Git - rust.git/blob - src/tools/compiletest/src/read2/tests.rs
Rollup merge of #97709 - compiler-errors:normalize-const-param-ty, r=oli-obk
[rust.git] / src / tools / compiletest / src / read2 / tests.rs
1 use crate::read2::{ProcOutput, FILTERED_PATHS_PLACEHOLDER_LEN, HEAD_LEN, TAIL_LEN};
2
3 #[test]
4 fn test_abbreviate_short_string() {
5     let mut out = ProcOutput::new();
6     out.extend(b"Hello world!", &[]);
7     assert_eq!(b"Hello world!", &*out.into_bytes());
8 }
9
10 #[test]
11 fn test_abbreviate_short_string_multiple_steps() {
12     let mut out = ProcOutput::new();
13
14     out.extend(b"Hello ", &[]);
15     out.extend(b"world!", &[]);
16
17     assert_eq!(b"Hello world!", &*out.into_bytes());
18 }
19
20 #[test]
21 fn test_abbreviate_long_string() {
22     let mut out = ProcOutput::new();
23
24     let data = vec![b'.'; HEAD_LEN + TAIL_LEN + 16];
25     out.extend(&data, &[]);
26
27     let mut expected = vec![b'.'; HEAD_LEN];
28     expected.extend_from_slice(b"\n\n<<<<<< SKIPPED 16 BYTES >>>>>>\n\n");
29     expected.extend_from_slice(&vec![b'.'; TAIL_LEN]);
30
31     // We first check the length to avoid endless terminal output if the length differs, since
32     // `out` is hundreds of KBs in size.
33     let out = out.into_bytes();
34     assert_eq!(expected.len(), out.len());
35     assert_eq!(expected, out);
36 }
37
38 #[test]
39 fn test_abbreviate_long_string_multiple_steps() {
40     let mut out = ProcOutput::new();
41
42     out.extend(&vec![b'.'; HEAD_LEN], &[]);
43     out.extend(&vec![b'.'; TAIL_LEN], &[]);
44     // Also test whether the rotation works
45     out.extend(&vec![b'!'; 16], &[]);
46     out.extend(&vec![b'?'; 16], &[]);
47
48     let mut expected = vec![b'.'; HEAD_LEN];
49     expected.extend_from_slice(b"\n\n<<<<<< SKIPPED 32 BYTES >>>>>>\n\n");
50     expected.extend_from_slice(&vec![b'.'; TAIL_LEN - 32]);
51     expected.extend_from_slice(&vec![b'!'; 16]);
52     expected.extend_from_slice(&vec![b'?'; 16]);
53
54     // We first check the length to avoid endless terminal output if the length differs, since
55     // `out` is hundreds of KBs in size.
56     let out = out.into_bytes();
57     assert_eq!(expected.len(), out.len());
58     assert_eq!(expected, out);
59 }
60
61 #[test]
62 fn test_abbreviate_filterss_are_detected() {
63     let mut out = ProcOutput::new();
64     let filters = &["foo".to_string(), "quux".to_string()];
65
66     out.extend(b"Hello foo", filters);
67     // Check items from a previous extension are not double-counted.
68     out.extend(b"! This is a qu", filters);
69     // Check items are detected across extensions.
70     out.extend(b"ux.", filters);
71
72     match &out {
73         ProcOutput::Full { bytes, filtered_len } => assert_eq!(
74             *filtered_len,
75             bytes.len() + FILTERED_PATHS_PLACEHOLDER_LEN * filters.len()
76                 - filters.iter().map(|i| i.len()).sum::<usize>()
77         ),
78         ProcOutput::Abbreviated { .. } => panic!("out should not be abbreviated"),
79     }
80
81     assert_eq!(b"Hello foo! This is a quux.", &*out.into_bytes());
82 }
83
84 #[test]
85 fn test_abbreviate_filters_avoid_abbreviations() {
86     let mut out = ProcOutput::new();
87     let filters = &[std::iter::repeat('a').take(64).collect::<String>()];
88
89     let mut expected = vec![b'.'; HEAD_LEN - FILTERED_PATHS_PLACEHOLDER_LEN as usize];
90     expected.extend_from_slice(filters[0].as_bytes());
91     expected.extend_from_slice(&vec![b'.'; TAIL_LEN]);
92
93     out.extend(&expected, filters);
94
95     // We first check the length to avoid endless terminal output if the length differs, since
96     // `out` is hundreds of KBs in size.
97     let out = out.into_bytes();
98     assert_eq!(expected.len(), out.len());
99     assert_eq!(expected, out);
100 }
101
102 #[test]
103 fn test_abbreviate_filters_can_still_cause_abbreviations() {
104     let mut out = ProcOutput::new();
105     let filters = &[std::iter::repeat('a').take(64).collect::<String>()];
106
107     let mut input = vec![b'.'; HEAD_LEN];
108     input.extend_from_slice(&vec![b'.'; TAIL_LEN]);
109     input.extend_from_slice(filters[0].as_bytes());
110
111     let mut expected = vec![b'.'; HEAD_LEN];
112     expected.extend_from_slice(b"\n\n<<<<<< SKIPPED 64 BYTES >>>>>>\n\n");
113     expected.extend_from_slice(&vec![b'.'; TAIL_LEN - 64]);
114     expected.extend_from_slice(&vec![b'a'; 64]);
115
116     out.extend(&input, filters);
117
118     // We first check the length to avoid endless terminal output if the length differs, since
119     // `out` is hundreds of KBs in size.
120     let out = out.into_bytes();
121     assert_eq!(expected.len(), out.len());
122     assert_eq!(expected, out);
123 }