Skip to content

Instantly share code, notes, and snippets.

@alisha17
Last active August 13, 2017 13:34
Show Gist options
  • Save alisha17/2065a558ea3e2b9c8c9740001847624e to your computer and use it in GitHub Desktop.
Save alisha17/2065a558ea3e2b9c8c9740001847624e to your computer and use it in GitHub Desktop.
fn generate_single_test(dest_path: &mut File, cache_dir: &Path, name: &String, version: &String) {
let dl_crate = format!("{}-{}.crate",name, version);
let mut new_path = cache_dir.join(dl_crate);
let new_path = new_path.to_str();
let expected = [
"#[test]\n",
"fn test_",name,"(){\n",
"let outdir = TempDir::new(\"testrunner\").unwrap();\n",
"let new_path = File::create(\"",new_path,"\");\n",
"let mut tar = Archive::new(GzDecoder::new(new_path));\n",
"let archive = &mut tar;\n",
"archive.unpack(outdir);\n",
"let mut path_to_test = outdir.path().join(\"",name,"-",version,"\");\n",
"let cmd = Command::new(\"cargo\").arg(\"test\").current_dir(path_to_test).output().unwrap();\n",
"match cmd.status.success() {\n",
" True => {},\n",
" False => panic!(\"Test didn't pass!\")\n",
"}\n",
"drop(outdir);",
"outdir.close();",
"}\n",
].concat();
dest_path.write(expected.as_bytes());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment