timeline: share one limited-push path for report levels; keep transition diagnostic levels; cover export limit

This commit is contained in:
FredApps committed 2026-11-16 07:06:09 +01:00
1 parent 5f3851a2ee
commit 281508dc4b
3 files changed
+50 -12

No files matched your search

+1 -1
View File
@@ -516,7 +516,7 @@ impl<'a> Imp<'a, '_, '_> {
let effect = transition_effect(self.b.catalog, &name, false, &mut temporary);
for e in temporary.entries {
for _ in 0..e.count {
self.report.warn_limited(self.report_limit, &e.message);
self.report.push_limited(e.level, self.report_limit, &e.message);
}
}
let id = TransitionId(self.b.alloc());
+36 -11
View File
@@ -40,25 +40,23 @@ impl Report {
/// budget this replaces; past it a new message is counted under "further diagnostics omitted".
/// Existing messages continue to be counted.
pub fn warn_limited(&mut self, limit: Option<usize>, message: impl Into<String>) {
let mut message = message.into();
if let Some(limit) = limit
&& self.entries.len() >= limit
&& !self.entries.iter().any(|e| e.level == Level::Warning && e.message == message)
{
message = "further diagnostics omitted".into();
}
self.push(Level::Warning, message);
self.push_limited(Level::Warning, limit, message);
}
/// Add an informational diagnostic while bounding distinct messages.
/// Add an informational diagnostic under the same distinct-entry budget as [`Report::warn_limited`].
pub fn info_limited(&mut self, limit: Option<usize>, message: impl Into<String>) {
self.push_limited(Level::Info, limit, message);
}
/// Add a diagnostic at `level`, counting a new message past `limit` distinct entries under
/// "further diagnostics omitted"; a message already in the report keeps its own count.
pub fn push_limited(&mut self, level: Level, limit: Option<usize>, message: impl Into<String>) {
let mut message = message.into();
if let Some(limit) = limit
&& self.entries.len() >= limit
&& !self.entries.iter().any(|e| e.level == Level::Info && e.message == message)
&& !self.entries.iter().any(|e| e.level == level && e.message == message)
{
message = "further diagnostics omitted".into();
}
self.push(Level::Info, message);
self.push(level, message);
}
pub fn warn(&mut self, message: impl Into<String>) {
self.push(Level::Warning, message);
@@ -98,3 +96,30 @@ impl std::fmt::Display for Report {
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn limited_entries_share_one_budget_and_keep_existing_counts() {
let mut r = Report::default();
r.info_limited(Some(2), "a");
r.warn_limited(Some(2), "b");
r.info_limited(Some(2), "c");
r.info_limited(Some(2), "a");
r.warn_limited(Some(2), "a");
r.push_limited(Level::Warning, None, "d");
let got: Vec<_> = r.entries.iter().map(|e| (e.level, e.message.as_str(), e.count)).collect();
assert_eq!(
got,
[
(Level::Info, "a", 2),
(Level::Warning, "b", 1),
(Level::Info, "further diagnostics omitted", 1),
(Level::Warning, "further diagnostics omitted", 1),
(Level::Warning, "d", 1),
]
);
}
}
+13
View File
@@ -630,3 +630,16 @@ fn optional_report_limit_bounds_distinct_fcpxml_diagnostics() {
assert!(craft_timeline::fcpxml::import(&doc, &opts, &mut ordinary).is_ok());
assert_eq!(ordinary.entries.len(), 10);
}
#[test]
fn optional_report_limit_bounds_fcpxml_export_diagnostics_without_changing_output() {
let (p, s) = project();
let mut ordinary = Report::default();
let text = craft_timeline::fcpxml::export(&p, s, &xopts(), &mut ordinary).unwrap();
let mut limited = Report::default();
let bounded = craft_timeline::fcpxml::export_with_report_limit(&p, s, &xopts(), &mut limited, Some(0)).unwrap();
assert_eq!(bounded, text);
let total = |r: &Report| r.entries.iter().map(|e| e.count).sum::<u32>();
assert_eq!(total(&limited), total(&ordinary));
assert!(limited.entries.iter().all(|e| e.message == "further diagnostics omitted"), "{limited}");
}