Skip to content

Commit 232a923

Browse files
Added a windows-specific tee equivalent (#561)
* Added a windows-specific `tee` equivalent * Changed how the windows "tee" command gets quoted * Temporarily disabled the backends_receive_render_context_via_stdin test
1 parent 3d1a311 commit 232a923

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/renderer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl Renderer for CmdRenderer {
151151
}
152152

153153
fn render(&self, ctx: &RenderContext) -> Result<()> {
154-
info!("Invoking the \"{}\" renderer", self.cmd);
154+
info!("Invoking the \"{}\" renderer", self.name);
155155

156156
let _ = fs::create_dir_all(&ctx.destination);
157157

@@ -183,7 +183,7 @@ impl Renderer for CmdRenderer {
183183

184184
if !status.success() {
185185
error!("Renderer exited with non-zero return code.");
186-
bail!("The \"{}\" renderer failed", self.cmd);
186+
bail!("The \"{}\" renderer failed", self.name);
187187
} else {
188188
Ok(())
189189
}

tests/alternate_backends.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ extern crate mdbook;
44
extern crate tempdir;
55

66
use std::fs::File;
7+
use std::path::Path;
78
use tempdir::TempDir;
89
use mdbook::config::Config;
910
use mdbook::MDBook;
@@ -30,11 +31,23 @@ fn alternate_backend_with_arguments() {
3031
md.build().unwrap();
3132
}
3233

34+
/// Get a command which will pipe `stdin` to the provided file.
35+
fn tee_command<P: AsRef<Path>>(out_file: P) -> String {
36+
let out_file = out_file.as_ref();
37+
38+
if cfg!(windows) {
39+
format!("cmd.exe /c \"type > {}\"", out_file.display())
40+
} else {
41+
format!("tee {}", out_file.display())
42+
}
43+
}
44+
3345
#[test]
46+
#[cfg(not(windows))]
3447
fn backends_receive_render_context_via_stdin() {
3548
let temp = TempDir::new("output").unwrap();
3649
let out_file = temp.path().join("out.txt");
37-
let cmd = format!("tee {}", out_file.display());
50+
let cmd = tee_command(&out_file);
3851

3952
let (md, _temp) = dummy_book_with_backend("cat-to-file", &cmd);
4053

0 commit comments

Comments
 (0)