1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 11:07:44 +00:00

test: fix namespace and broken test

I separated test's main() into a separate file to override Cargo's
requirement for matching crate names. I had to update the build command
to use a special extern reference for test.

Fixes issues caused by #728.
This commit is contained in:
Joseph Crail 2015-11-27 15:25:58 -05:00
parent b469b2e316
commit 012414c49f
4 changed files with 15 additions and 18 deletions

View file

@ -29,7 +29,8 @@ pub fn main() {
let mut map: UtilityMap = HashMap::new();\n".as_bytes()).unwrap(); let mut map: UtilityMap = HashMap::new();\n".as_bytes()).unwrap();
for krate in crates { for krate in crates {
match krate.as_ref() { match krate.as_ref() {
"false" | "true" | "test" => {}, "false" | "true" => {},
"test" => cf.write_all(format!("extern crate uu{krate};\n", krate=krate).as_bytes()).unwrap(),
_ => cf.write_all(format!("extern crate {krate} as uu{krate};\n", krate=krate).as_bytes()).unwrap(), _ => cf.write_all(format!("extern crate {krate} as uu{krate};\n", krate=krate).as_bytes()).unwrap(),
} }
@ -43,16 +44,12 @@ pub fn main() {
map.insert(\"sha384sum\", uuhashsum::uumain); map.insert(\"sha384sum\", uuhashsum::uumain);
map.insert(\"sha512sum\", uuhashsum::uumain);\n".as_bytes()).unwrap(); map.insert(\"sha512sum\", uuhashsum::uumain);\n".as_bytes()).unwrap();
}, },
"true" => { "false" =>
mf.write_all(format!("fn uu{}", krate).as_bytes()).unwrap(); mf.write_all("fn uufalse(_: Vec<String>) -> i32 { 1 }
mf.write_all("(_: Vec<String>) -> i32 { 0 }\n".as_bytes()).unwrap(); map.insert(\"false\", uufalse as fn(Vec<String>) -> i32);\n".as_bytes()).unwrap(),
mf.write_all(format!("map.insert(\"{krate}\", uu{krate} as fn(Vec<String>) -> i32);\n", krate=krate).as_bytes()).unwrap(); "true" =>
} mf.write_all("fn uutrue(_: Vec<String>) -> i32 { 0 }
"false" | "test" => { map.insert(\"true\", uutrue as fn(Vec<String>) -> i32);\n".as_bytes()).unwrap(),
mf.write_all(format!("fn uu{}", krate).as_bytes()).unwrap();
mf.write_all("(_: Vec<String>) -> i32 { 1 }\n".as_bytes()).unwrap();
mf.write_all(format!("map.insert(\"{krate}\", uu{krate} as fn(Vec<String>) -> i32);\n", krate=krate).as_bytes()).unwrap();
},
_ => _ =>
mf.write_all(format!("map.insert(\"{krate}\", uu{krate}::uumain as fn(Vec<String>) -> i32);\n", krate= krate).as_bytes()).unwrap(), mf.write_all(format!("map.insert(\"{krate}\", uu{krate}::uumain as fn(Vec<String>) -> i32);\n", krate= krate).as_bytes()).unwrap(),
} }

View file

@ -13,5 +13,5 @@ libc = "*"
uucore = { path="../uucore" } uucore = { path="../uucore" }
[[bin]] [[bin]]
name="uutest" name="test"
path="test.rs" path="main.rs"

5
src/test/main.rs Normal file
View file

@ -0,0 +1,5 @@
extern crate uutest;
fn main() {
std::process::exit(uutest::uumain(std::env::args().collect()));
}

View file

@ -406,8 +406,3 @@ fn path(path: &[u8], cond: PathCondition) -> bool {
PathCondition::Executable => false, // TODO PathCondition::Executable => false, // TODO
} }
} }
#[allow(dead_code)]
fn main() {
std::process::exit(uumain(std::env::args().collect()));
}