Skip to content

Commit ea99817

Browse files
committed
Auto merge of #526 - Zeegomo:html-test-exp, r=pietroalbini
Tests for HTML reports This adds support for other report types in minicrater. `IndexMap` is used instead of `HashMap` to ensure consistent serialization. Needs to be merged after #520
2 parents a435eca + 3181b02 commit ea99817

30 files changed

+2035
-76
lines changed

Cargo.lock

Lines changed: 13 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ remove_dir_all = "0.5.2"
6969
ctrlc = "3.1.3"
7070
prometheus = "0.7.0"
7171
cargo_metadata = "0.9.1"
72+
indexmap = "1.4.0"
7273

7374
[dev-dependencies]
7475
assert_cmd = "0.10.1"

src/cli.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ pub enum Crater {
243243
dest: Dest,
244244
#[structopt(name = "force", long = "force")]
245245
force: bool,
246+
#[structopt(name = "output-templates", long = "output-templates")]
247+
output_templates: bool,
246248
},
247249

248250
#[structopt(name = "publish-report", about = "publish the experiment report to S3")]
@@ -258,6 +260,8 @@ pub enum Crater {
258260
s3_prefix: report::S3Prefix,
259261
#[structopt(name = "force", long = "force")]
260262
force: bool,
263+
#[structopt(name = "output-templates", long = "output-templates")]
264+
output_templates: bool,
261265
},
262266

263267
#[structopt(name = "server")]
@@ -503,6 +507,7 @@ impl Crater {
503507
ref ex,
504508
ref dest,
505509
force,
510+
output_templates,
506511
} => {
507512
let config = Config::load()?;
508513
let db = Database::open()?;
@@ -527,6 +532,7 @@ impl Crater {
527532
&experiment.get_crates(&db)?,
528533
&report::FileWriter::create(dest.0.clone())?,
529534
&config,
535+
output_templates,
530536
);
531537

532538
if let Err(err) = res {
@@ -543,6 +549,7 @@ impl Crater {
543549
ref ex,
544550
ref s3_prefix,
545551
force,
552+
output_templates,
546553
} => {
547554
let config = Config::load()?;
548555
let db = Database::open()?;
@@ -569,6 +576,7 @@ impl Crater {
569576
&experiment.get_crates(&db)?,
570577
&report::S3Writer::create(client, s3_prefix.clone())?,
571578
&config,
579+
output_templates,
572580
);
573581

574582
if let Err(err) = res {

src/report/analyzer.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use crate::results::{
44
FailureReason,
55
TestResult::{self, BuildFail},
66
};
7+
use indexmap::IndexMap;
78
use std::collections::BTreeSet;
8-
use std::collections::HashMap;
99

1010
pub enum ToolchainSelect {
1111
Start,
@@ -22,20 +22,20 @@ pub enum ReportConfig {
2222
pub enum ReportCrates {
2323
Plain(Vec<CrateResult>),
2424
Complete {
25-
tree: HashMap<Crate, Vec<CrateResult>>,
26-
results: HashMap<TestResult, Vec<CrateResult>>,
25+
tree: IndexMap<Crate, Vec<CrateResult>>,
26+
results: IndexMap<TestResult, Vec<CrateResult>>,
2727
},
2828
}
2929

3030
#[cfg_attr(test, derive(Debug, PartialEq))]
3131
pub struct TestResults {
32-
pub categories: HashMap<Comparison, ReportCrates>,
33-
pub info: HashMap<Comparison, u32>,
32+
pub categories: IndexMap<Comparison, ReportCrates>,
33+
pub info: IndexMap<Comparison, u32>,
3434
}
3535

3636
fn analyze_detailed(toolchain: usize, crates: Vec<CrateResult>) -> ReportCrates {
37-
let mut tree = HashMap::new();
38-
let mut results = HashMap::new();
37+
let mut tree = IndexMap::new();
38+
let mut results = IndexMap::new();
3939

4040
let mut root = Vec::new();
4141
for krate in crates {
@@ -75,7 +75,7 @@ fn analyze_detailed(toolchain: usize, crates: Vec<CrateResult>) -> ReportCrates
7575
}
7676

7777
pub fn analyze_report(test: RawTestResults) -> TestResults {
78-
let mut comparison = HashMap::new();
78+
let mut comparison = IndexMap::new();
7979
for krate in test.crates {
8080
comparison
8181
.entry(krate.res)
@@ -86,9 +86,9 @@ pub fn analyze_report(test: RawTestResults) -> TestResults {
8686
let info = comparison
8787
.iter()
8888
.map(|(&key, vec)| (key, vec.len() as u32))
89-
.collect::<HashMap<_, _>>();
89+
.collect::<IndexMap<_, _>>();
9090

91-
let mut categories = HashMap::new();
91+
let mut categories = IndexMap::new();
9292
for (cat, crates) in comparison {
9393
if let ReportConfig::Complete(toolchain) = cat.report_config() {
9494
// variants in an enum are numbered following an
@@ -191,18 +191,18 @@ mod tests {
191191
panic!("invalid crate type")
192192
}
193193
})
194-
.collect::<HashMap<_, _>>();
194+
.collect::<IndexMap<_, _>>();
195195
let analyzed = analyze_report(raw);
196196

197-
let mut info = HashMap::new();
197+
let mut info = IndexMap::new();
198198
info.insert(Comparison::Regressed, 5);
199199
info.insert(Comparison::Fixed, 2);
200200
info.insert(Comparison::SameTestPass, 1);
201201

202202
macro_rules! create_results {
203203
($src:expr, $($key:expr => ($($krate:expr),*)),*) => {
204204
{
205-
let mut map = HashMap::new();
205+
let mut map = IndexMap::new();
206206
$(
207207
let mut crates = Vec::new();
208208
$(
@@ -248,7 +248,7 @@ mod tests {
248248

249249
let test_pass = ReportCrates::Plain(vec![crates.remove("test-pass").unwrap()]);
250250

251-
let mut categories = HashMap::new();
251+
let mut categories = IndexMap::new();
252252
categories.insert(Comparison::Regressed, regressed);
253253
categories.insert(Comparison::Fixed, fixed);
254254
categories.insert(Comparison::SameTestPass, test_pass);

src/report/archives.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::prelude::*;
55
use crate::report::{compare, ReportWriter};
66
use crate::results::{EncodedLog, EncodingType, ReadResults};
77
use flate2::{write::GzEncoder, Compression};
8-
use std::collections::HashMap;
8+
use indexmap::IndexMap;
99
use tar::{Builder as TarBuilder, Header as TarHeader};
1010

1111
#[derive(Serialize)]
@@ -23,7 +23,7 @@ pub fn write_logs_archives<DB: ReadResults, W: ReportWriter>(
2323
) -> Fallible<Vec<Archive>> {
2424
let mut archives = Vec::new();
2525
let mut all = TarBuilder::new(GzEncoder::new(Vec::new(), Compression::default()));
26-
let mut by_comparison = HashMap::new();
26+
let mut by_comparison = IndexMap::new();
2727

2828
for krate in crates {
2929
if config.should_skip(krate) {
@@ -86,7 +86,7 @@ pub fn write_logs_archives<DB: ReadResults, W: ReportWriter>(
8686
path: "logs-archives/all.tar.gz".to_string(),
8787
});
8888

89-
for (comparison, archive) in by_comparison.drain() {
89+
for (comparison, archive) in by_comparison.drain(..) {
9090
let data = archive.into_inner()?.finish()?;
9191
dest.write_bytes(
9292
&format!("logs-archives/{}.tar.gz", comparison),

src/report/html.rs

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::report::{
66
ResultColor, ResultName, TestResults,
77
};
88
use crate::results::{EncodingType, FailureReason, TestResult};
9-
use std::collections::HashMap;
9+
use indexmap::IndexMap;
1010

1111
#[derive(Serialize)]
1212
struct NavbarItem {
@@ -27,11 +27,11 @@ enum ReportCratesHTML {
2727
Plain(Vec<CrateResultHTML>),
2828
Tree {
2929
count: u32,
30-
tree: HashMap<String, Vec<CrateResultHTML>>,
30+
tree: IndexMap<String, Vec<CrateResultHTML>>,
3131
},
3232
RootResults {
3333
count: u32,
34-
results: HashMap<String, Vec<CrateResultHTML>>,
34+
results: IndexMap<String, Vec<CrateResultHTML>>,
3535
},
3636
}
3737

@@ -62,11 +62,10 @@ struct ResultsContext<'a> {
6262
ex: &'a Experiment,
6363
nav: Vec<NavbarItem>,
6464
categories: Vec<(Comparison, ReportCratesHTML)>,
65-
info: HashMap<Comparison, u32>,
65+
info: IndexMap<Comparison, u32>,
6666
full: bool,
6767
crates_count: usize,
68-
69-
comparison_colors: HashMap<Comparison, Color>,
68+
comparison_colors: IndexMap<Comparison, Color>,
7069
result_colors: Vec<Color>,
7170
result_names: Vec<String>,
7271
}
@@ -102,9 +101,10 @@ fn write_report<W: ReportWriter>(
102101
full: bool,
103102
to: &str,
104103
dest: &W,
104+
output_templates: bool,
105105
) -> Fallible<()> {
106-
let mut comparison_colors = HashMap::new();
107-
let mut test_results_to_int = HashMap::new();
106+
let mut comparison_colors = IndexMap::new();
107+
let mut test_results_to_int = IndexMap::new();
108108
let mut result_colors = Vec::new();
109109
let mut result_names = Vec::new();
110110

@@ -165,7 +165,7 @@ fn write_report<W: ReportWriter>(
165165
.collect::<Vec<_>>(),
166166
)
167167
})
168-
.collect::<HashMap<_, _>>();
168+
.collect::<IndexMap<_, _>>();
169169
let results = results
170170
.into_iter()
171171
.map(|(res, krates)| {
@@ -182,7 +182,7 @@ fn write_report<W: ReportWriter>(
182182
.collect::<Vec<_>>(),
183183
)
184184
})
185-
.collect::<HashMap<_, _>>();
185+
.collect::<IndexMap<_, _>>();
186186

187187
vec![
188188
(
@@ -227,6 +227,14 @@ fn write_report<W: ReportWriter>(
227227
let html = minifier::html::minify(&assets::render_template("report/results.html", &context)?);
228228
dest.write_string(to, html.into(), &mime::TEXT_HTML)?;
229229

230+
if output_templates {
231+
dest.write_string(
232+
[to, ".context.json"].concat(),
233+
serde_json::to_string(&context)?.into(),
234+
&mime::APPLICATION_JSON,
235+
)?;
236+
}
237+
230238
Ok(())
231239
}
232240

@@ -235,6 +243,7 @@ fn write_downloads<W: ReportWriter>(
235243
crates_count: usize,
236244
available_archives: Vec<Archive>,
237245
dest: &W,
246+
output_templates: bool,
238247
) -> Fallible<()> {
239248
let context = DownloadsContext {
240249
ex,
@@ -247,6 +256,14 @@ fn write_downloads<W: ReportWriter>(
247256
let html = minifier::html::minify(&assets::render_template("report/downloads.html", &context)?);
248257
dest.write_string("downloads.html", html.into(), &mime::TEXT_HTML)?;
249258

259+
if output_templates {
260+
dest.write_string(
261+
"downloads.html.context.json",
262+
serde_json::to_string(&context)?.into(),
263+
&mime::APPLICATION_JSON,
264+
)?;
265+
}
266+
250267
Ok(())
251268
}
252269

@@ -256,12 +273,29 @@ pub fn write_html_report<W: ReportWriter>(
256273
res: &TestResults,
257274
available_archives: Vec<Archive>,
258275
dest: &W,
276+
output_templates: bool,
259277
) -> Fallible<()> {
260278
let js_in = assets::load("report.js")?;
261279
let css_in = assets::load("report.css")?;
262-
write_report(ex, crates_count, res, false, "index.html", dest)?;
263-
write_report(ex, crates_count, res, true, "full.html", dest)?;
264-
write_downloads(ex, crates_count, available_archives, dest)?;
280+
write_report(
281+
ex,
282+
crates_count,
283+
res,
284+
false,
285+
"index.html",
286+
dest,
287+
output_templates,
288+
)?;
289+
write_report(
290+
ex,
291+
crates_count,
292+
res,
293+
true,
294+
"full.html",
295+
dest,
296+
output_templates,
297+
)?;
298+
write_downloads(ex, crates_count, available_archives, dest, output_templates)?;
265299

266300
info!("copying static assets");
267301
dest.write_bytes(

0 commit comments

Comments
 (0)