Add more runner events to the reporter and refine the structure

This commit is contained in:
Omar Abdulla
2025-08-24 20:13:48 +03:00
parent cbb6a11404
commit 4d7d7ed843
6 changed files with 88 additions and 22 deletions
+37 -6
View File
@@ -2,23 +2,25 @@
//! reporters and combines them into a single unified report.
use std::{
collections::BTreeSet,
collections::{BTreeSet, HashMap, HashSet},
fs::OpenOptions,
path::PathBuf,
time::{SystemTime, UNIX_EPOCH},
};
use anyhow::Result;
use revive_dt_compiler::Mode;
use revive_dt_config::Arguments;
use revive_dt_format::corpus::Corpus;
use revive_dt_format::{case::CaseIdx, corpus::Corpus};
use serde::Serialize;
use serde_with::{DisplayFromStr, serde_as};
use tokio::sync::{
broadcast::{Sender, channel},
mpsc::{UnboundedReceiver, UnboundedSender, unbounded_channel},
};
use crate::{
SubscribeToEventsEvent,
SubscribeToEventsEvent, TestIgnoredEvent,
common::MetadataFilePath,
reporter_event::ReporterEvent,
runner_event::{CorpusFileDiscoveryEvent, MetadataFileDiscoveryEvent, Reporter, RunnerEvent},
};
@@ -26,6 +28,7 @@ use crate::{
pub struct ReportAggregator {
/* Internal Report State */
report: Report,
remaining_cases: HashMap<MetadataFilePath, HashSet<CaseIdx>>,
/* Channels */
runner_tx: Option<UnboundedSender<RunnerEvent>>,
runner_rx: UnboundedReceiver<RunnerEvent>,
@@ -38,6 +41,7 @@ impl ReportAggregator {
let (listener_tx, _) = channel::<ReporterEvent>(1024);
Self {
report: Report::new(config),
remaining_cases: Default::default(),
runner_tx: Some(runner_tx),
runner_rx,
listener_tx,
@@ -66,6 +70,9 @@ impl ReportAggregator {
RunnerEvent::MetadataFileDiscovery(event) => {
self.handle_metadata_file_discovery_event(*event);
}
RunnerEvent::TestIgnored(event) => {
self.handle_test_ignored_event(*event);
}
}
}
@@ -96,10 +103,26 @@ impl ReportAggregator {
}
fn handle_metadata_file_discovery_event(&mut self, event: MetadataFileDiscoveryEvent) {
self.report.metadata_files.insert(event.path);
self.report.metadata_files.insert(event.path.clone());
self.remaining_cases.insert(
event.path,
event
.metadata
.cases
.iter()
.enumerate()
.map(|(id, _)| id)
.map(CaseIdx::new)
.collect(),
);
}
fn handle_test_ignored_event(&mut self, _: TestIgnoredEvent) {
todo!()
}
}
#[serde_as]
#[derive(Clone, Debug, Serialize)]
pub struct Report {
/// The configuration that the tool was started up with.
@@ -107,7 +130,11 @@ pub struct Report {
/// The list of corpus files that the tool found.
pub corpora: Vec<Corpus>,
/// The list of metadata files that were found by the tool.
pub metadata_files: BTreeSet<PathBuf>,
pub metadata_files: BTreeSet<MetadataFilePath>,
/// Information relating to each test case.
#[serde_as(as = "HashMap<_, HashMap<DisplayFromStr, HashMap<DisplayFromStr, _>>>")]
pub test_case_information:
HashMap<MetadataFilePath, HashMap<Mode, HashMap<CaseIdx, TestCaseReport>>>,
}
impl Report {
@@ -116,6 +143,10 @@ impl Report {
config,
corpora: Default::default(),
metadata_files: Default::default(),
test_case_information: Default::default(),
}
}
}
#[derive(Clone, Debug, Serialize)]
pub struct TestCaseReport {}
+1
View File
@@ -10,6 +10,7 @@ use serde_with::{DisplayFromStr, serde_as};
define_wrapper_type!(
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[serde(transparent)]
pub struct MetadataFilePath(PathBuf);
);
+29 -4
View File
@@ -1,12 +1,11 @@
//! The types associated with the events sent by the runner to the reporter.
use std::path::PathBuf;
#![allow(dead_code)]
use revive_dt_format::corpus::Corpus;
use revive_dt_format::metadata::Metadata;
use tokio::sync::{broadcast, oneshot};
use crate::ReporterEvent;
use crate::{ReporterEvent, common::MetadataFilePath};
macro_rules! keep_if_doc {
(#[doc = $doc:expr]) => {
@@ -91,6 +90,16 @@ macro_rules! define_event {
}
impl [< $ident Reporter >] {
pub fn test_specific_reporter(
&self,
test_specifier: impl Into<std::sync::Arc<crate::common::TestSpecifier>>
) -> [< $ident TestSpecificReporter >] {
[< $ident TestSpecificReporter >] {
reporter: self.clone(),
test_specifier: test_specifier.into(),
}
}
fn report(&self, event: impl Into<$ident>) -> anyhow::Result<()> {
self.0.send(event.into()).map_err(Into::into)
}
@@ -104,6 +113,18 @@ macro_rules! define_event {
}
)*
}
/// A reporter that's tied to a specific test case.
pub struct [< $ident TestSpecificReporter >] {
$vis reporter: [< $ident Reporter >],
$vis test_specifier: std::sync::Arc<crate::common::TestSpecifier>,
}
impl [< $ident TestSpecificReporter >] {
fn report(&self, event: impl Into<$ident>) -> anyhow::Result<()> {
self.reporter.report(event)
}
}
}
};
}
@@ -125,9 +146,13 @@ define_event! {
/// An event emitted by runners when they've discovered a metadata file.
MetadataFileDiscovery {
/// The path of the metadata file discovered.
path: PathBuf,
path: MetadataFilePath,
/// The content of the metadata file.
metadata: Metadata
},
/// An event emitted by the runners when a test case is ignored.
TestIgnored {
},
/// An event emitted by the runners when the execution is completed and the aggregator can
/// stop.