Skip to content

Commit 69d8676

Browse files
committed
config: Make doctest options optional when disabled (#3)
1 parent 37dc907 commit 69d8676

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

example/cppdoc.toml

-2
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,3 @@ base_url = "/cppdoc"
1717

1818
[doctests]
1919
enable = false
20-
run = true
21-
compiler_invocation = ["clang++", "{file}", "-o", "{out}", "-Iinclude", "-std=c++20"]

src/config.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ pub struct Output {
3939
#[derive(Deserialize, Serialize, Clone, Debug)]
4040
pub struct Doctest {
4141
pub enable: bool,
42-
pub run: bool,
43-
pub compiler_invocation: Vec<String>,
42+
pub run: Option<bool>,
43+
pub compiler_invocation: Option<Vec<String>>,
4444
}
4545

4646
impl Config {

src/doctest.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ impl Doctest {
6161
}
6262

6363
pub fn compile(&self, config: &config::Doctest) -> std::path::PathBuf {
64-
let compiler_invocation = config.compiler_invocation.join(" ");
64+
// This is fine, this should never panic
65+
let compiler_invocation = config.compiler_invocation.clone().unwrap();
66+
let compiler_invocation = compiler_invocation.join(" ");
6567

6668
let mut in_file = tempfile::Builder::new().suffix(".cpp").tempfile().unwrap();
6769

src/main.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,20 @@ fn main() {
159159
ProgressStyle::with_template("Running doctest {pos}/{len}").unwrap(),
160160
);
161161

162+
if let None = doctest_conf.run {
163+
report_error("Doctests enabled but no run option specified");
164+
std::process::exit(1);
165+
}
166+
167+
if let None = doctest_conf.compiler_invocation {
168+
report_error("Doctests enabled but no compiler invocation specified");
169+
std::process::exit(1);
170+
}
171+
162172
for doc in doctests {
163173
let out = doc.compile(doctest_conf);
164174

165-
if doctest_conf.run {
175+
if doctest_conf.run.unwrap() {
166176
doc.run(out);
167177
}
168178

0 commit comments

Comments
 (0)