"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "cli/tools/test_runner.rs" between
deno-1.12.0.tar.gz and deno-1.12.1.tar.gz

About: Deno is is a simple, modern and secure runtime for JavaScript and TypeScript that uses the V8 JavaScript engine and is built in Rust.

test_runner.rs  (deno-1.12.0):test_runner.rs  (deno-1.12.1)
skipping to change at line 34 skipping to change at line 34
use rand::rngs::SmallRng; use rand::rngs::SmallRng;
use rand::seq::SliceRandom; use rand::seq::SliceRandom;
use rand::SeedableRng; use rand::SeedableRng;
use regex::Regex; use regex::Regex;
use serde::Deserialize; use serde::Deserialize;
use std::path::Path; use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::mpsc::channel; use std::sync::mpsc::channel;
use std::sync::mpsc::Sender; use std::sync::mpsc::Sender;
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration;
use std::time::Instant; use std::time::Instant;
use swc_common::comments::CommentKind; use swc_common::comments::CommentKind;
#[derive(Debug, Clone, PartialEq, Deserialize)] #[derive(Debug, Clone, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct TestDescription {
pub origin: String,
pub name: String,
}
#[derive(Debug, Clone, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum TestResult { pub enum TestResult {
Ok, Ok,
Ignored, Ignored,
Failed(String), Failed(String),
} }
#[derive(Debug, Clone, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TestPlan {
pub origin: String,
pub total: usize,
pub filtered_out: usize,
pub used_only: bool,
}
#[derive(Debug, Clone, Deserialize)] #[derive(Debug, Clone, Deserialize)]
#[serde(tag = "kind", content = "data", rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub enum TestMessage { pub enum TestEvent {
Plan { Plan(TestPlan),
pending: usize, Wait(TestDescription),
filtered: usize, Result(TestDescription, TestResult, u64),
only: bool,
},
Wait {
name: String,
},
Result {
name: String,
duration: usize,
result: TestResult,
},
} }
#[derive(Debug, Clone, Deserialize)] #[derive(Debug, Clone, Deserialize)]
pub struct TestEvent { pub struct TestSummary {
pub origin: String, pub total: usize,
pub message: TestMessage, pub passed: usize,
pub failed: usize,
pub ignored: usize,
pub filtered_out: usize,
pub measured: usize,
pub failures: Vec<(TestDescription, String)>,
}
impl TestSummary {
fn new() -> TestSummary {
TestSummary {
total: 0,
passed: 0,
failed: 0,
ignored: 0,
filtered_out: 0,
measured: 0,
failures: Vec::new(),
}
}
fn has_failed(&self) -> bool {
self.failed > 0 || !self.failures.is_empty()
}
fn has_pending(&self) -> bool {
self.total - self.passed - self.failed - self.ignored > 0
}
} }
trait TestReporter { trait TestReporter {
fn visit_event(&mut self, event: TestEvent); fn report_plan(&mut self, plan: &TestPlan);
fn done(&mut self); fn report_wait(&mut self, description: &TestDescription);
fn report_result(
&mut self,
description: &TestDescription,
result: &TestResult,
elapsed: u64,
);
fn report_summary(&mut self, summary: &TestSummary, elapsed: &Duration);
} }
struct PrettyTestReporter { struct PrettyTestReporter {
time: Instant,
failed: usize,
filtered_out: usize,
ignored: usize,
passed: usize,
measured: usize,
pending: usize,
failures: Vec<(String, String)>,
concurrent: bool, concurrent: bool,
} }
impl PrettyTestReporter { impl PrettyTestReporter {
fn new(concurrent: bool) -> PrettyTestReporter { fn new(concurrent: bool) -> PrettyTestReporter {
PrettyTestReporter { PrettyTestReporter { concurrent }
time: Instant::now(),
failed: 0,
filtered_out: 0,
ignored: 0,
passed: 0,
measured: 0,
pending: 0,
failures: Vec::new(),
concurrent,
}
} }
} }
impl TestReporter for PrettyTestReporter { impl TestReporter for PrettyTestReporter {
fn visit_event(&mut self, event: TestEvent) { fn report_plan(&mut self, plan: &TestPlan) {
match &event.message { let inflection = if plan.total == 1 { "test" } else { "tests" };
TestMessage::Plan { println!("running {} {} from {}", plan.total, inflection, plan.origin);
pending, }
filtered,
only: _,
} => {
if *pending == 1 {
println!("running {} test from {}", pending, event.origin);
} else {
println!("running {} tests from {}", pending, event.origin);
}
self.pending += pending;
self.filtered_out += filtered;
}
TestMessage::Wait { name } => {
if !self.concurrent {
print!("test {} ...", name);
}
}
TestMessage::Result {
name,
duration,
result,
} => {
self.pending -= 1;
if self.concurrent {
print!("test {} ...", name);
}
match result { fn report_wait(&mut self, description: &TestDescription) {
TestResult::Ok => { if !self.concurrent {
println!( print!("test {} ...", description.name);
" {} {}", }
colors::green("ok"), }
colors::gray(format!("({}ms)", duration))
);
self.passed += 1; fn report_result(
} &mut self,
TestResult::Ignored => { description: &TestDescription,
println!( result: &TestResult,
" {} {}", elapsed: u64,
colors::yellow("ignored"), ) {
colors::gray(format!("({}ms)", duration)) if self.concurrent {
); print!("test {} ...", description.name);
}
self.ignored += 1; let status = match result {
} TestResult::Ok => colors::green("ok").to_string(),
TestResult::Failed(error) => { TestResult::Ignored => colors::yellow("ignored").to_string(),
println!( TestResult::Failed(_) => colors::red("FAILED").to_string(),
" {} {}", };
colors::red("FAILED"),
colors::gray(format!("({}ms)", duration))
);
self.failed += 1; println!(
self.failures.push((name.to_string(), error.to_string())); " {} {}",
} status,
} colors::gray(format!("({}ms)", elapsed)).to_string()
} );
}
} }
fn done(&mut self) { fn report_summary(&mut self, summary: &TestSummary, elapsed: &Duration) {
if !self.failures.is_empty() { if !summary.failures.is_empty() {
println!("\nfailures:\n"); println!("\nfailures:\n");
for (name, error) in &self.failures { for (description, error) in &summary.failures {
println!("{}", name); println!("{}", description.name);
println!("{}", error); println!("{}", error);
println!(); println!();
} }
println!("failures:\n"); println!("failures:\n");
for (name, _) in &self.failures { for (description, _) in &summary.failures {
println!("\t{}", name); println!("\t{}", description.name);
} }
} }
let status = if self.pending > 0 || !self.failures.is_empty() { let status = if summary.has_failed() || summary.has_pending() {
colors::red("FAILED").to_string() colors::red("FAILED").to_string()
} else { } else {
colors::green("ok").to_string() colors::green("ok").to_string()
}; };
println!( println!(
"\ntest result: {}. {} passed; {} failed; {} ignored; {} measured; {} fi "\ntest result: {}. {} passed; {} failed; {} ignored; {} measured; {} filt
ltered out {}\n", ered out {}\n",
status, status,
self.passed, summary.passed,
self.failed, summary.failed,
self.ignored, summary.ignored,
self.measured, summary.measured,
self.filtered_out, summary.filtered_out,
colors::gray(format!("({}ms)", self.time.elapsed().as_millis())), colors::gray(format!("({}ms)", elapsed.as_millis())),
); );
} }
} }
fn create_reporter(concurrent: bool) -> Box<dyn TestReporter + Send> { fn create_reporter(concurrent: bool) -> Box<dyn TestReporter + Send> {
Box::new(PrettyTestReporter::new(concurrent)) Box::new(PrettyTestReporter::new(concurrent))
} }
pub(crate) fn is_supported(p: &Path) -> bool { pub(crate) fn is_supported(p: &Path) -> bool {
use std::path::Component; use std::path::Component;
if let Some(Component::Normal(basename_os_str)) = p.components().next_back() { if let Some(Component::Normal(basename_os_str)) = p.components().next_back() {
skipping to change at line 514 skipping to change at line 503
}) })
}); });
let join_futures = stream::iter(join_handles) let join_futures = stream::iter(join_handles)
.buffer_unordered(concurrent_jobs) .buffer_unordered(concurrent_jobs)
.collect::<Vec<Result<Result<(), AnyError>, tokio::task::JoinError>>>(); .collect::<Vec<Result<Result<(), AnyError>, tokio::task::JoinError>>>();
let mut reporter = create_reporter(concurrent_jobs > 1); let mut reporter = create_reporter(concurrent_jobs > 1);
let handler = { let handler = {
tokio::task::spawn_blocking(move || { tokio::task::spawn_blocking(move || {
let earlier = Instant::now();
let mut summary = TestSummary::new();
let mut used_only = false; let mut used_only = false;
let mut has_error = false;
let mut planned = 0;
let mut reported = 0;
let mut failed = 0;
for event in receiver.iter() { for event in receiver.iter() {
match event.message.clone() { match event {
TestMessage::Plan { TestEvent::Plan(plan) => {
pending, summary.total += plan.total;
filtered: _, summary.filtered_out += plan.filtered_out;
only,
} => { if plan.used_only {
if only {
used_only = true; used_only = true;
} }
planned += pending; reporter.report_plan(&plan);
}
TestEvent::Wait(description) => {
reporter.report_wait(&description);
} }
TestMessage::Result {
name: _, TestEvent::Result(description, result, elapsed) => {
duration: _, match &result {
result, TestResult::Ok => {
} => { summary.passed += 1;
reported += 1; }
if let TestResult::Failed(_) = result { TestResult::Ignored => {
has_error = true; summary.ignored += 1;
failed += 1; }
TestResult::Failed(error) => {
summary.failed += 1;
summary.failures.push((description.clone(), error.clone()));
}
} }
reporter.report_result(&description, &result, elapsed);
} }
_ => {}
} }
reporter.visit_event(event);
if let Some(x) = fail_fast { if let Some(x) = fail_fast {
if failed >= x { if summary.failed >= x {
break; break;
} }
} }
} }
if planned > reported { let elapsed = Instant::now().duration_since(earlier);
has_error = true; reporter.report_summary(&summary, &elapsed);
}
reporter.done();
if planned > reported {
has_error = true;
}
if used_only { if used_only {
println!( println!(
"{} because the \"only\" option was used\n", "{} because the \"only\" option was used\n",
colors::red("FAILED") colors::red("FAILED")
); );
has_error = true;
} }
has_error used_only || summary.failed > 0
}) })
}; };
let (result, join_results) = future::join(handler, join_futures).await; let (result, join_results) = future::join(handler, join_futures).await;
let mut join_errors = join_results.into_iter().filter_map(|join_result| { let mut join_errors = join_results.into_iter().filter_map(|join_result| {
join_result join_result
.ok() .ok()
.map(|handle_result| handle_result.err()) .map(|handle_result| handle_result.err())
.flatten() .flatten()
 End of changes. 30 change blocks. 
156 lines changed or deleted 141 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)