Replace hard coded version strings with compiletime env

This commit is contained in:
Matthias Beyer 2018-03-03 13:51:55 +01:00
parent 8c1a9ffe67
commit 579c00b62a
7 changed files with 65 additions and 64 deletions

View file

@ -315,7 +315,7 @@ mod tests {
make_mock_app! {
app "imag-link";
modulename mock;
version "0.7.0";
version env!("CARGO_PKG_VERSION");
with help "imag-link mocking app";
}
use self::mock::generate_test_runtime;

View file

@ -174,7 +174,7 @@ mod tests {
make_mock_app! {
app "imag-store";
modulename mock;
version "0.7.0";
version env!("CARGO_PKG_VERSION");
with help "imag-store mocking app";
}
use self::mock::generate_test_runtime;
@ -193,7 +193,7 @@ mod tests {
let e = e.unwrap();
let version = e.get_header().read("imag.version").map(Option::unwrap).unwrap();
assert_eq!(Value::String(String::from("0.7.0")), *version);
assert_eq!(Value::String(String::from(env!("CARGO_PKG_VERSION"))), *version);
}
}

View file

@ -48,7 +48,7 @@ mod tests {
make_mock_app! {
app "imag-store";
modulename mock;
version "0.7.0";
version env!("CARGO_PKG_VERSION");
with help "imag-store mocking app";
}
use self::mock::generate_test_runtime;

View file

@ -240,7 +240,7 @@ mod tests {
make_mock_app! {
app "imag-tag";
modulename mock;
version "0.7.0";
version env!("CARGO_PKG_VERSION");
with help "imag-tag mocking app";
}
use self::mock::generate_test_runtime;

View file

@ -112,11 +112,11 @@ mod test {
let mut lf = InMemoryFileAbstractionInstance::new(fs.backend().clone(), path.clone());
let loca = StoreId::new_baseless(path).unwrap();
let file = Entry::from_str(loca.clone(), r#"---
let file = Entry::from_str(loca.clone(), &format!(r#"---
[imag]
version = "0.7.0"
version = "{}"
---
Hello World"#).unwrap();
Hello World"#, env!("CARGO_PKG_VERSION"))).unwrap();
lf.write_file_content(&file).unwrap();
let bah = lf.get_file_content(loca).unwrap();
@ -132,12 +132,12 @@ Hello World"#).unwrap();
let mut lf = InMemoryFileAbstractionInstance::new(fs.backend().clone(), path.clone());
let loca = StoreId::new_baseless(path).unwrap();
let file = Entry::from_str(loca.clone(), r#"---
let file = Entry::from_str(loca.clone(), &format!(r#"---
[imag]
version = "0.7.0"
version = "{}"
---
Hello World
baz"#).unwrap();
baz"#, env!("CARGO_PKG_VERSION"))).unwrap();
lf.write_file_content(&file).unwrap();
let bah = lf.get_file_content(loca).unwrap();

View file

@ -164,7 +164,8 @@ mod test {
#[test]
fn test_empty_json_to_fs() {
let json = r#"{"version":"0.7.0","store":{}}"#;
let json = format!(r#"{{"version":"{version}","store":{{}}}}"#,
version = env!("CARGO_PKG_VERSION"));
let mut json = Cursor::new(String::from(json).into_bytes());
let mapper = JsonMapper::new();
let mut hm = HashMap::new();
@ -176,20 +177,20 @@ mod test {
#[test]
fn test_json_to_fs() {
let json = r#"
{ "version": "0.7.0",
"store": {
"example": {
"header": {
"imag": {
"version": "0.7.0"
}
},
let json = format!(r#"
{{ "version": "{version}",
"store": {{
"example": {{
"header": {{
"imag": {{
"version": "{version}"
}}
}},
"content": "test"
}
}
}
"#;
}}
}}
}}
"#, version = env!("CARGO_PKG_VERSION"));
let mut json = Cursor::new(String::from(json).into_bytes());
let mapper = JsonMapper::new();
let mut hm = HashMap::new();
@ -207,14 +208,14 @@ mod test {
let mut hm = {
let mut hm = HashMap::new();
let content = r#"---
let content = format!(r#"---
[imag]
version = "0.7.0"
version = "{}"
---
hi there!"#;
hi there!"#, env!("CARGO_PKG_VERSION"));
let id = PathBuf::from("example");
let entry = Entry::from_str(id.clone(), content).unwrap();
let entry = Entry::from_str(id.clone(), &content).unwrap();
hm.insert(id, entry);
hm
};
@ -222,23 +223,23 @@ hi there!"#;
let io_res = mapper.fs_to_write(&mut hm, &mut out);
assert!(io_res.is_ok());
let example = r#"
{
"version": "0.7.0",
"store": {
"example": {
"header": {
"imag": {
"version": "0.7.0"
}
},
let example = format!(r#"
{{
"version": "{version}",
"store": {{
"example": {{
"header": {{
"imag": {{
"version": "{version}"
}}
}},
"content": "hi there!"
}
}
}
"#;
}}
}}
}}
"#, version = env!("CARGO_PKG_VERSION"));
let example_json : ::serde_json::Value = ::serde_json::from_str(example).unwrap();
let example_json : ::serde_json::Value = ::serde_json::from_str(&example).unwrap();
let output_json = String::from_utf8(out.into_inner()).unwrap();
let output_json : ::serde_json::Value = ::serde_json::from_str(&output_json).unwrap();

View file

@ -1284,11 +1284,11 @@ mod store_tests {
use file_abstraction::stdio::mapper::json::JsonMapper;
// Lets have an empty store as input
let mut input = Cursor::new(r#"
{ "version": "0.7.0",
"store": { }
}
"#);
let mut input = Cursor::new(format!(r#"
{{ "version": "{}",
"store": {{}}
}}
"#, env!("CARGO_PKG_VERSION")));
let mapper = JsonMapper::new();
let backend = StdIoFileAbstraction::new(&mut input, output.clone(), mapper).unwrap();
@ -1322,7 +1322,7 @@ mod store_tests {
Value::Object(ref map) => {
assert!(map.get("version").is_some(), format!("No 'version' in JSON"));
match map.get("version").unwrap() {
&Value::String(ref s) => assert_eq!("0.7.0", s),
&Value::String(ref s) => assert_eq!(env!("CARGO_PKG_VERSION"), s),
_ => panic!("Wrong type in JSON at 'version'"),
}
@ -1622,20 +1622,20 @@ mod store_tests {
use file_abstraction::stdio::mapper::json::JsonMapper;
// Lets have an empty store as input
let mut input = Cursor::new(r#"
{ "version": "0.7.0",
"store": {
"example": {
"header": {
"imag": {
"version": "0.7.0"
}
},
let mut input = Cursor::new(format!(r#"
{{ "version": "{version}",
"store": {{
"example": {{
"header": {{
"imag": {{
"version": "{version}"
}}
}},
"content": "foobar"
}
}
}
"#);
}}
}}
}}
"#, version = env!("CARGO_PKG_VERSION")));
let output = Rc::new(RefCell::new(::std::io::sink()));
let mapper = JsonMapper::new();
@ -1672,7 +1672,7 @@ mod store_tests {
Value::Object(ref map) => {
assert!(map.get("version").is_some(), format!("No 'version' in JSON"));
match map.get("version").unwrap() {
&Value::String(ref s) => assert_eq!("0.7.0", s),
&Value::String(ref s) => assert_eq!(env!("CARGO_PKG_VERSION"), s),
_ => panic!("Wrong type in JSON at 'version'"),
}