From 55366a2a3156c79d04fbf7ef7e6ef9002836ed9d Mon Sep 17 00:00:00 2001 From: Vladislav Kuzmin <67874880+principalwater@users.noreply.github.com> Date: Sat, 28 Nov 2026 02:37:09 +0300 Subject: [PATCH] test(build): report Gradle output when fixture preparation fails (#6564) When the Gradle model fixture could not be prepared, the test panicked with only the unsupported reason and hid the build error. It now appends the last 150 lines of the build output from both streams, with a unit test for the tail. Fixes #6555 Co-authored-by: principalwater <67874880+principalwater@users.noreply.github.com> --- crates/ide-build/src/jbuild/tests.rs | 31 +++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/crates/ide-build/src/jbuild/tests.rs b/crates/ide-build/src/jbuild/tests.rs index 38ff33bb8d..9986974bfe 100644 --- a/crates/ide-build/src/jbuild/tests.rs +++ b/crates/ide-build/src/jbuild/tests.rs @@ -11,6 +11,32 @@ fn write(root: &Path, rel: &str, text: &str) { fs::write(path, text).unwrap(); } +fn build_output_tail(events: &[BuildEvent]) -> String { + let mut lines: Vec<_> = events + .iter() + .filter_map(|event| match event { + BuildEvent::Output { text, .. } => Some(text.as_str()), + _ => None, + }) + .flat_map(str::lines) + .rev() + .take(150) + .collect(); + lines.reverse(); + lines.join("\n") +} + +#[test] +fn build_output_tail_keeps_the_last_150_lines_across_streams() { + let lines = |range: std::ops::Range| range.map(|n| n.to_string()).collect::>().join("\n"); + let events = [ + BuildEvent::Output { text: lines(0..100), stderr: false }, + BuildEvent::Progress { message: "building".into(), fraction: None }, + BuildEvent::Output { text: lines(100..155), stderr: true }, + ]; + assert_eq!(build_output_tail(&events), lines(5..155)); +} + /// A JDK (`JAVA_HOME`) and Maven on the search path, else `None` (the test is skipped). fn tools() -> Option<(PathBuf, PathBuf)> { let home = std::env::var_os("JAVA_HOME").map(PathBuf::from).filter(|h| h.join("bin").is_dir())?; @@ -139,7 +165,10 @@ impl Fixture { let on_event = |e: BuildEvent| self.events.lock().unwrap().push(e); match build.build(target, BuildKind::Build, &CancellationToken::new(), &on_event) { Ok(Built::Done(outputs)) => outputs, - Ok(Built::Unsupported(reason)) => panic!("unsupported: {reason}"), + Ok(Built::Unsupported(reason)) => { + let output = build_output_tail(&self.events.lock().unwrap()); + panic!("unsupported: {reason}\n{output}"); + } Err(e) => panic!("{e:?}"), } }