Skip to content

Commit

Permalink
Also use pre generated manifests to prevent test issues
Browse files Browse the repository at this point in the history
Cargo versions might not generated the same order of targets or
similar issues leading to hard to fix test failures
  • Loading branch information
hmvp committed Jun 9, 2019
1 parent 3fa9962 commit 694b244
Show file tree
Hide file tree
Showing 11 changed files with 586 additions and 28 deletions.
44 changes: 16 additions & 28 deletions src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,12 @@ impl Target {
#[cfg(test)]
mod tests {
use super::*;
use std::fs;
use std::path;
use std::process;

fn read_manifest(directory: &path::Path) -> Manifest {
let output = process::Command::new("cargo")
.current_dir(directory)
.arg("metadata")
.args(&["--no-deps", "--format-version", "1"])
.output()
.expect("Cargo failed")
.stdout;
let manifest_str = String::from_utf8(output).expect("Failed reading cargo output");

fn read_manifest(filename: &path::Path) -> Manifest {
let manifest_str: String = fs::read_to_string(filename.with_extension("json"))
.expect("manifest file cannot be read");
Manifest::from_str(&manifest_str).expect("manifest cannot be read")
}

Expand Down Expand Up @@ -207,7 +201,7 @@ mod tests {
kind: vec!(String::from("lib")),
crate_types: vec!(String::from("lib")),
name: String::from("example-lib-edition-2018"),
src_path: resource_path.join("src/lib.rs").canonicalize().unwrap(),
src_path: resource_path.join("src/lib.rs"),
edition: Edition::E2018
},
manifest.targets()[0]
Expand All @@ -226,20 +220,14 @@ mod tests {
kind: vec!(String::from("bin")),
crate_types: vec!(String::from("bin")),
name: String::from("example2"),
src_path: resource_path
.join("src/bin/example2.rs")
.canonicalize()
.unwrap(),
src_path: resource_path.join("src/bin/example2.rs"),
edition: Edition::E2018
},
&Target {
kind: vec!(String::from("bin")),
crate_types: vec!(String::from("bin")),
name: String::from("example"),
src_path: resource_path
.join("src/bin/example.rs")
.canonicalize()
.unwrap(),
src_path: resource_path.join("src/bin/example.rs"),
edition: Edition::E2018
}
],
Expand All @@ -259,14 +247,14 @@ mod tests {
kind: vec!(String::from("lib")),
crate_types: vec!(String::from("lib")),
name: String::from("example-lib-edition-2018"),
src_path: resource_path.join("src/lib.rs").canonicalize().unwrap(),
src_path: resource_path.join("src/lib.rs"),
edition: Edition::E2018
},
&Target {
kind: vec!(String::from("custom-build")),
crate_types: vec!(String::from("bin")),
name: String::from("build-script-build"),
src_path: resource_path.join("build.rs").canonicalize().unwrap(),
src_path: resource_path.join("build.rs"),
edition: Edition::E2018
}
],
Expand All @@ -277,7 +265,7 @@ mod tests {
kind: vec!(String::from("lib")),
crate_types: vec!(String::from("lib")),
name: String::from("example-lib-edition-2018"),
src_path: resource_path.join("src/lib.rs").canonicalize().unwrap(),
src_path: resource_path.join("src/lib.rs"),
edition: Edition::E2018
},],
manifest.targets()
Expand All @@ -287,7 +275,7 @@ mod tests {
kind: vec!(String::from("custom-build")),
crate_types: vec!(String::from("bin")),
name: String::from("build-script-build"),
src_path: resource_path.join("build.rs").canonicalize().unwrap(),
src_path: resource_path.join("build.rs"),
edition: Edition::E2018
}],
manifest.custom_builds()
Expand All @@ -303,7 +291,7 @@ mod tests {
kind: vec!(String::from("dylib")),
crate_types: vec!(String::from("dylib")),
name: String::from("example-plugin"),
src_path: resource_path.join("src/lib.rs").canonicalize().unwrap(),
src_path: resource_path.join("src/lib.rs"),
edition: Edition::E2018
},
manifest.targets()[0]
Expand All @@ -321,7 +309,7 @@ mod tests {
kind: vec!(String::from("proc-macro")),
crate_types: vec!(String::from("proc-macro")),
name: String::from("example-proc-macro"),
src_path: resource_path.join("src/lib.rs").canonicalize().unwrap(),
src_path: resource_path.join("src/lib.rs"),
edition: Edition::E2018
},
manifest.targets()[0]
Expand All @@ -341,14 +329,14 @@ mod tests {
kind: vec!(String::from("lib")),
crate_types: vec!(String::from("lib")),
name: String::from("example-bin-and-lib"),
src_path: resource_path.join("src/lib.rs").canonicalize().unwrap(),
src_path: resource_path.join("src/lib.rs"),
edition: Edition::E2018
},
&Target {
kind: vec!(String::from("bin")),
crate_types: vec!(String::from("bin")),
name: String::from("example-bin-and-lib"),
src_path: resource_path.join("src/main.rs").canonicalize().unwrap(),
src_path: resource_path.join("src/main.rs"),
edition: Edition::E2018
}
],
Expand Down
90 changes: 90 additions & 0 deletions test-resources/example-bin-and-lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"packages": [
{
"name": "example-bin-and-lib",
"version": "0.1.0",
"id": "example-bin-and-lib 0.1.0 (path+file://test-resources/example-bin-and-lib)",
"license": null,
"license_file": null,
"description": null,
"source": null,
"dependencies": [],
"targets": [
{
"kind": [
"lib"
],
"crate_types": [
"lib"
],
"name": "example-bin-and-lib",
"src_path": "test-resources/example-bin-and-lib/src/lib.rs",
"edition": "2018"
},
{
"kind": [
"bin"
],
"crate_types": [
"bin"
],
"name": "example-bin-and-lib",
"src_path": "test-resources/example-bin-and-lib/src/main.rs",
"edition": "2018"
},
{
"kind": [
"example"
],
"crate_types": [
"bin"
],
"name": "example",
"src_path": "test-resources/example-bin-and-lib/examples/example.rs",
"edition": "2018"
},
{
"kind": [
"test"
],
"crate_types": [
"bin"
],
"name": "test",
"src_path": "test-resources/example-bin-and-lib/tests/test.rs",
"edition": "2018"
},
{
"kind": [
"custom-build"
],
"crate_types": [
"bin"
],
"name": "build-script-build",
"src_path": "test-resources/example-bin-and-lib/build.rs",
"edition": "2018"
}
],
"features": {},
"manifest_path": "test-resources/example-bin-and-lib/Cargo.toml",
"metadata": null,
"authors": [
"Name <email@email.com>"
],
"categories": [],
"keywords": [],
"readme": null,
"repository": null,
"edition": "2018",
"links": null
}
],
"workspace_members": [
"example-bin-and-lib 0.1.0 (path+file://test-resources/example-bin-and-lib)"
],
"resolve": null,
"target_directory": "test-resources/example-bin-and-lib/target",
"version": 1,
"workspace_root": "test-resources/example-bin-and-lib"
}
68 changes: 68 additions & 0 deletions test-resources/example-bin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"packages": [
{
"name": "example-bin",
"version": "0.1.0",
"id": "example-bin 0.1.0 (path+file://test-resources/example-bin)",
"license": null,
"license_file": null,
"description": null,
"source": null,
"dependencies": [],
"targets": [
{
"kind": [
"bin"
],
"crate_types": [
"bin"
],
"name": "example2",
"src_path": "test-resources/example-bin/src/bin/example2.rs",
"edition": "2018"
},
{
"kind": [
"bin"
],
"crate_types": [
"bin"
],
"name": "example",
"src_path": "test-resources/example-bin/src/bin/example.rs",
"edition": "2018"
},
{
"kind": [
"custom-build"
],
"crate_types": [
"bin"
],
"name": "build-script-build",
"src_path": "test-resources/example-bin/build.rs",
"edition": "2018"
}
],
"features": {},
"manifest_path": "test-resources/example-bin/Cargo.toml",
"metadata": null,
"authors": [
"Name <email@email.com>"
],
"categories": [],
"keywords": [],
"readme": null,
"repository": null,
"edition": "2018",
"links": null
}
],
"workspace_members": [
"example-bin 0.1.0 (path+file://test-resources/example-bin)"
],
"resolve": null,
"target_directory": "test-resources/example-bin/target",
"version": 1,
"workspace_root": "test-resources/example-bin"
}
57 changes: 57 additions & 0 deletions test-resources/example-lib-edition-2015.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"packages": [
{
"name": "example-lib-edition-2015",
"version": "0.1.0",
"id": "example-lib-edition-2015 0.1.0 (path+file://test-resources/example-lib-edition-2015)",
"license": null,
"license_file": null,
"description": null,
"source": null,
"dependencies": [],
"targets": [
{
"kind": [
"lib"
],
"crate_types": [
"lib"
],
"name": "example-lib-edition-2015",
"src_path": "test-resources/example-lib-edition-2015/src/lib.rs",
"edition": "2015"
},
{
"kind": [
"custom-build"
],
"crate_types": [
"bin"
],
"name": "build-script-build",
"src_path": "test-resources/example-lib-edition-2015/build.rs",
"edition": "2015"
}
],
"features": {},
"manifest_path": "test-resources/example-lib-edition-2015/Cargo.toml",
"metadata": null,
"authors": [
"Name <email@email.com>"
],
"categories": [],
"keywords": [],
"readme": null,
"repository": null,
"edition": "2015",
"links": null
}
],
"workspace_members": [
"example-lib-edition-2015 0.1.0 (path+file://test-resources/example-lib-edition-2015)"
],
"resolve": null,
"target_directory": "test-resources/example-lib-edition-2015/target",
"version": 1,
"workspace_root": "test-resources/example-lib-edition-2015"
}
Loading

0 comments on commit 694b244

Please sign in to comment.