Skip to content

Commit bd83a6a

Browse files
author
Alexander Weber
committed
test
1 parent c7d8d44 commit bd83a6a

File tree

3 files changed

+67
-64
lines changed

3 files changed

+67
-64
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ keywords = ["cli", "template", "replace", "standardizing"]
1111
categories = ["command-line-utilities"]
1212
readme = "docs/README.md"
1313

14+
[[bin]]
15+
name = "complate"
16+
path = "./src/main.rs"
17+
1418
[features]
1519
default = ["backend+cli"]
1620
"backend+cli" = ["dialoguer"]

src/lib.rs

Lines changed: 0 additions & 64 deletions
This file was deleted.

src/main.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,66 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
4747
},
4848
}
4949
}
50+
51+
#[cfg(test)]
52+
mod tests {
53+
use std::{error::Error, process::Command};
54+
55+
fn exec(command: &str) -> Result<String, Box<dyn Error>> {
56+
let output = Command::new("sh").arg("-c").arg(command).output()?;
57+
if output.status.code().unwrap() != 0 {
58+
return Err(Box::new(crate::error::Error::ShellCommand(
59+
String::from_utf8(output.stderr).unwrap(),
60+
)));
61+
}
62+
Ok(String::from_utf8(output.stdout)?)
63+
}
64+
65+
const CONFIG_PATH: &'static str = "./test/.complate/config.yaml";
66+
67+
#[test]
68+
fn template_var_static() {
69+
assert!("alpha" == exec(&format!("cargo run -- render -c {} -t var:static", CONFIG_PATH)).unwrap())
70+
}
71+
72+
#[test]
73+
fn template_var_env() {
74+
assert!(
75+
"alpha"
76+
== exec(&format!(
77+
"alpha=\"alpha\" cargo run -- render -c {} -t var:env",
78+
CONFIG_PATH
79+
))
80+
.unwrap()
81+
)
82+
}
83+
84+
#[test]
85+
fn template_var_shell() {
86+
assert!(
87+
"alpha"
88+
== exec(&format!(
89+
"alpha=\"alpha\" cargo run -- render -c {} -t var:shell --trust",
90+
CONFIG_PATH
91+
))
92+
.unwrap()
93+
)
94+
}
95+
96+
#[test]
97+
fn template_overrides() {
98+
assert!(
99+
"alpha"
100+
== exec(&format!(
101+
"cargo run -- render -c {} -t override -v a.alpha=\"alpha\"",
102+
CONFIG_PATH
103+
))
104+
.unwrap()
105+
)
106+
}
107+
108+
#[test]
109+
fn template_helper() {
110+
assert!("bananarama" == exec(&format!("cargo run -- render -c {} -t helper --trust", CONFIG_PATH)).unwrap())
111+
}
112+
}

0 commit comments

Comments
 (0)