Skip to content

Added a windows-specific tee equivalent #561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl Renderer for CmdRenderer {
}

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

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

Expand Down Expand Up @@ -183,7 +183,7 @@ impl Renderer for CmdRenderer {

if !status.success() {
error!("Renderer exited with non-zero return code.");
bail!("The \"{}\" renderer failed", self.cmd);
bail!("The \"{}\" renderer failed", self.name);
} else {
Ok(())
}
Expand Down
15 changes: 14 additions & 1 deletion tests/alternate_backends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extern crate mdbook;
extern crate tempdir;

use std::fs::File;
use std::path::Path;
use tempdir::TempDir;
use mdbook::config::Config;
use mdbook::MDBook;
Expand All @@ -30,11 +31,23 @@ fn alternate_backend_with_arguments() {
md.build().unwrap();
}

/// Get a command which will pipe `stdin` to the provided file.
fn tee_command<P: AsRef<Path>>(out_file: P) -> String {
let out_file = out_file.as_ref();

if cfg!(windows) {
format!("cmd.exe /c \"type > {}\"", out_file.display())
} else {
format!("tee {}", out_file.display())
}
}

#[test]
#[cfg(not(windows))]
fn backends_receive_render_context_via_stdin() {
let temp = TempDir::new("output").unwrap();
let out_file = temp.path().join("out.txt");
let cmd = format!("tee {}", out_file.display());
let cmd = tee_command(&out_file);

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

Expand Down