-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[compiletest] Ignore known paths when abbreviating output #96551
Changes from all commits
73497b1
47d8ba9
b7473be
e52fb6c
da13969
95e1bd0
e257f38
8ea9598
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
use crate::read2::{ProcOutput, FILTERED_PATHS_PLACEHOLDER_LEN, HEAD_LEN, TAIL_LEN}; | ||
|
||
#[test] | ||
fn test_abbreviate_short_string() { | ||
let mut out = ProcOutput::new(); | ||
out.extend(b"Hello world!", &[]); | ||
assert_eq!(b"Hello world!", &*out.into_bytes()); | ||
} | ||
|
||
#[test] | ||
fn test_abbreviate_short_string_multiple_steps() { | ||
let mut out = ProcOutput::new(); | ||
|
||
out.extend(b"Hello ", &[]); | ||
out.extend(b"world!", &[]); | ||
|
||
assert_eq!(b"Hello world!", &*out.into_bytes()); | ||
} | ||
|
||
#[test] | ||
fn test_abbreviate_long_string() { | ||
let mut out = ProcOutput::new(); | ||
|
||
let data = vec![b'.'; HEAD_LEN + TAIL_LEN + 16]; | ||
out.extend(&data, &[]); | ||
|
||
let mut expected = vec![b'.'; HEAD_LEN]; | ||
expected.extend_from_slice(b"\n\n<<<<<< SKIPPED 16 BYTES >>>>>>\n\n"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW, I think we should make the read2_abbreviated return an error or panic instead of inserting this skipped message -- that typically leads to a JSON de-serialization failure and a pretty opaque one at that, which I think isn't too helpful -- we can probably say something more useful like "captured X bytes, which is above the limit in compiletest. See abbreviated output: {output}". (Can be out of scope for this PR). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, let's do that in a separate PR though. |
||
expected.extend_from_slice(&vec![b'.'; TAIL_LEN]); | ||
|
||
// We first check the length to avoid endless terminal output if the length differs, since | ||
// `out` is hundreds of KBs in size. | ||
let out = out.into_bytes(); | ||
assert_eq!(expected.len(), out.len()); | ||
assert_eq!(expected, out); | ||
} | ||
|
||
#[test] | ||
fn test_abbreviate_long_string_multiple_steps() { | ||
let mut out = ProcOutput::new(); | ||
|
||
out.extend(&vec![b'.'; HEAD_LEN], &[]); | ||
out.extend(&vec![b'.'; TAIL_LEN], &[]); | ||
// Also test whether the rotation works | ||
out.extend(&vec![b'!'; 16], &[]); | ||
out.extend(&vec![b'?'; 16], &[]); | ||
|
||
let mut expected = vec![b'.'; HEAD_LEN]; | ||
expected.extend_from_slice(b"\n\n<<<<<< SKIPPED 32 BYTES >>>>>>\n\n"); | ||
expected.extend_from_slice(&vec![b'.'; TAIL_LEN - 32]); | ||
expected.extend_from_slice(&vec![b'!'; 16]); | ||
expected.extend_from_slice(&vec![b'?'; 16]); | ||
|
||
// We first check the length to avoid endless terminal output if the length differs, since | ||
// `out` is hundreds of KBs in size. | ||
let out = out.into_bytes(); | ||
assert_eq!(expected.len(), out.len()); | ||
assert_eq!(expected, out); | ||
} | ||
|
||
#[test] | ||
fn test_abbreviate_filterss_are_detected() { | ||
let mut out = ProcOutput::new(); | ||
let filters = &["foo".to_string(), "quux".to_string()]; | ||
|
||
out.extend(b"Hello foo", filters); | ||
// Check items from a previous extension are not double-counted. | ||
out.extend(b"! This is a qu", filters); | ||
// Check items are detected across extensions. | ||
out.extend(b"ux.", filters); | ||
|
||
match &out { | ||
ProcOutput::Full { bytes, filtered_len } => assert_eq!( | ||
*filtered_len, | ||
bytes.len() + FILTERED_PATHS_PLACEHOLDER_LEN * filters.len() | ||
- filters.iter().map(|i| i.len()).sum::<usize>() | ||
), | ||
ProcOutput::Abbreviated { .. } => panic!("out should not be abbreviated"), | ||
} | ||
|
||
assert_eq!(b"Hello foo! This is a quux.", &*out.into_bytes()); | ||
} | ||
|
||
#[test] | ||
fn test_abbreviate_filters_avoid_abbreviations() { | ||
let mut out = ProcOutput::new(); | ||
let filters = &[std::iter::repeat('a').take(64).collect::<String>()]; | ||
|
||
let mut expected = vec![b'.'; HEAD_LEN - FILTERED_PATHS_PLACEHOLDER_LEN as usize]; | ||
expected.extend_from_slice(filters[0].as_bytes()); | ||
expected.extend_from_slice(&vec![b'.'; TAIL_LEN]); | ||
|
||
out.extend(&expected, filters); | ||
|
||
// We first check the length to avoid endless terminal output if the length differs, since | ||
// `out` is hundreds of KBs in size. | ||
let out = out.into_bytes(); | ||
assert_eq!(expected.len(), out.len()); | ||
assert_eq!(expected, out); | ||
} | ||
|
||
#[test] | ||
fn test_abbreviate_filters_can_still_cause_abbreviations() { | ||
let mut out = ProcOutput::new(); | ||
let filters = &[std::iter::repeat('a').take(64).collect::<String>()]; | ||
|
||
let mut input = vec![b'.'; HEAD_LEN]; | ||
input.extend_from_slice(&vec![b'.'; TAIL_LEN]); | ||
input.extend_from_slice(filters[0].as_bytes()); | ||
|
||
let mut expected = vec![b'.'; HEAD_LEN]; | ||
expected.extend_from_slice(b"\n\n<<<<<< SKIPPED 64 BYTES >>>>>>\n\n"); | ||
expected.extend_from_slice(&vec![b'.'; TAIL_LEN - 64]); | ||
expected.extend_from_slice(&vec![b'a'; 64]); | ||
|
||
out.extend(&input, filters); | ||
|
||
// We first check the length to avoid endless terminal output if the length differs, since | ||
// `out` is hundreds of KBs in size. | ||
let out = out.into_bytes(); | ||
assert_eq!(expected.len(), out.len()); | ||
assert_eq!(expected, out); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is going to run into some problems if we have overlapping matches (e.g., one of the patterns is /home/mark and the other is /home/mark/rust, then we'll subtract out twice).
I think src_base and build_base won't do that in practice so we're OK for now, but ideally we'd either (a) assert that it doesn't happen or (b) somehow fix it. I'm not quite sure what the best approach to fixing it would be -- trying to detect this kind of overlap seems annoying.