use std::collections::BTreeMap;
use std::io::{BufRead, BufReader};
use std::path::{Path, PathBuf};
use std::process::{Child, Command, Stdio};
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::mpsc::{Receiver, Sender};
use std::sync::{Arc, Mutex};
use super::model::{Activity, TestCase, TestStatus};
use super::parse::{
parse_jest_json, parse_list_line, parse_pytest_collect_line, parse_pytest_line,
parse_test_line, parse_vitest_list_json, parse_vitest_list_line, parse_vitest_tap_line,
};
use super::regex_escape;
use crate::jobs::{Start, Worker, WorkerPoll};
use crate::output::{self, OutputLevel};
use crate::widgets::testing::TestingPanel;
pub const RUNNER_THREAD: &str = "test-runner";
mod commands;
mod control;
mod coverage;
mod discovery;
mod go_and_codeql;
mod handle;
mod js_args;
mod main_loop;
mod pytest;
mod runners;
mod runs;
mod streaming;
mod test_binaries;
pub(crate) use commands::cargo_progress;
use commands::*;
pub use coverage::CoverageScope;
use coverage::*;
use discovery::*;
use go_and_codeql::*;
use js_args::*;
use main_loop::*;
use pytest::*;
pub use runners::runner_for;
pub use runners::runner_for_file;
pub use runners::runners_for;
use runners::*;
use runs::*;
use streaming::*;
pub use test_binaries::build_test_binary;
#[cfg(test)]
use test_binaries::*;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Runner {
Cargo,
Pytest,
Vitest,
Jest,
Go,
Codeql,
}
pub enum TestRequest {
RunAll,
RunOne(String),
RunFilter(String, Option<PathBuf>),
RunMany(Vec<String>),
RunSuite(String),
RunCoverage(Option<CoverageScope>),
Discover {
quiet: bool,
},
SetRoot(PathBuf),
SetCodeqlProgram(PathBuf),
SetExtensionsDir(PathBuf),
}
pub enum TestResponse {
Started(Activity),
Case(TestCase),
Progress(String),
Finished {
ok: Option<bool>,
},
Refused,
QuietDiscovery,
Coverage(Result<crate::testing::coverage::Coverage, CoverageError>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CoverageError {
Missing { tool: &'static str, install: String },
NoReport,
Unsupported { runner: &'static str },
}
#[derive(Clone, Default)]
pub struct RunControl {
running: Arc<Mutex<Option<i32>>>,
cancelled_upto: Arc<AtomicU64>,
}
struct Sent {
number: u64,
epoch: u64,
request: TestRequest,
}
pub struct TestWorker {
worker: Worker<Sent, (u64, TestResponse)>,
control: RunControl,
#[cfg(test)]
owners: Arc<Owners>,
sent: u64,
cancel_pending: bool,
discover_queued: bool,
expected_epoch: u64,
root: PathBuf,
codeql: Option<PathBuf>,
extensions: Option<PathBuf>,
stopped_news: bool,
}
struct EpochTx<'a> {
tx: &'a Sender<(u64, TestResponse)>,
epoch: u64,
codeql: &'a Path,
extensions: &'a Path,
control: &'a RunControl,
request: u64,
owners: Option<&'a Owners>,
tag: Option<Runner>,
}
#[derive(Default)]
pub(super) struct Owners(Mutex<OwnerMap>);
#[derive(Default)]
pub(super) struct OwnerMap {
epoch: u64,
by_test: BTreeMap<String, Runner>,
}
#[cfg(test)]
mod tests;