-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathqltest.rs
More file actions
72 lines (68 loc) · 1.92 KB
/
qltest.rs
File metadata and controls
72 lines (68 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use crate::config::Config;
use anyhow::Context;
use glob::glob;
use itertools::Itertools;
use log::info;
use std::ffi::OsStr;
use std::fs;
use std::process::Command;
fn dump_lib() -> anyhow::Result<()> {
let path_iterator = glob("*.rs").context("globbing test sources")?;
let paths = path_iterator
.collect::<Result<Vec<_>, _>>()
.context("fetching test sources")?;
let lib = paths
.iter()
.map(|p| p.file_stem().expect("results of glob must have a name"))
.filter(|&p| !["main", "lib"].map(OsStr::new).contains(&p))
.map(|p| format!("mod {};", p.to_string_lossy()))
.join("\n");
fs::write("lib.rs", lib).context("writing lib.rs")
}
fn dump_cargo_manifest() -> anyhow::Result<()> {
let mut manifest = String::from(
r#"[workspace]
[package]
name = "test"
version="0.0.1"
edition="2021"
[lib]
path="lib.rs"
"#,
);
if fs::exists("main.rs").context("checking existence of main.rs")? {
manifest.push_str(
r#"[[bin]]
name = "main"
path = "main.rs"
"#,
);
}
fs::write("Cargo.toml", manifest).context("writing Cargo.toml")
}
fn set_sources(config: &mut Config) -> anyhow::Result<()> {
let path_iterator = glob("*.rs").context("globbing test sources")?;
config.inputs = path_iterator
.collect::<Result<Vec<_>, _>>()
.context("fetching test sources")?;
Ok(())
}
pub(crate) fn prepare(config: &mut Config) -> anyhow::Result<()> {
dump_lib()?;
set_sources(config)?;
dump_cargo_manifest()?;
if config.qltest_cargo_check {
let status = Command::new("cargo")
.env("RUSTFLAGS", "-Awarnings")
.arg("check")
.arg("-q")
.status()
.context("spawning cargo check")?;
if status.success() {
info!("cargo check successful");
} else {
anyhow::bail!("requested cargo check failed");
}
}
Ok(())
}