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 3d61f2e
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 11 deletions.
16 changes: 5 additions & 11 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
1 change: 1 addition & 0 deletions test-resources/example-bin-and-lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"packages":[{"name":"example-bin-and-lib","version":"0.1.0","id":"example-bin-and-lib 0.1.0 (path+file:///home/hiram/git/cargo-modules/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":"/home/hiram/git/cargo-modules/test-resources/example-bin-and-lib/src/lib.rs","edition":"2018"},{"kind":["bin"],"crate_types":["bin"],"name":"example-bin-and-lib","src_path":"/home/hiram/git/cargo-modules/test-resources/example-bin-and-lib/src/main.rs","edition":"2018"},{"kind":["example"],"crate_types":["bin"],"name":"example","src_path":"/home/hiram/git/cargo-modules/test-resources/example-bin-and-lib/examples/example.rs","edition":"2018"},{"kind":["test"],"crate_types":["bin"],"name":"test","src_path":"/home/hiram/git/cargo-modules/test-resources/example-bin-and-lib/tests/test.rs","edition":"2018"},{"kind":["custom-build"],"crate_types":["bin"],"name":"build-script-build","src_path":"/home/hiram/git/cargo-modules/test-resources/example-bin-and-lib/build.rs","edition":"2018"}],"features":{},"manifest_path":"/home/hiram/git/cargo-modules/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:///home/hiram/git/cargo-modules/test-resources/example-bin-and-lib)"],"resolve":null,"target_directory":"/home/hiram/git/cargo-modules/test-resources/example-bin-and-lib/target","version":1,"workspace_root":"/home/hiram/git/cargo-modules/test-resources/example-bin-and-lib"}
1 change: 1 addition & 0 deletions test-resources/example-bin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"packages":[{"name":"example-bin","version":"0.1.0","id":"example-bin 0.1.0 (path+file:///home/hiram/git/cargo-modules/test-resources/example-bin)","license":null,"license_file":null,"description":null,"source":null,"dependencies":[],"targets":[{"kind":["bin"],"crate_types":["bin"],"name":"example2","src_path":"/home/hiram/git/cargo-modules/test-resources/example-bin/src/bin/example2.rs","edition":"2018"},{"kind":["bin"],"crate_types":["bin"],"name":"example","src_path":"/home/hiram/git/cargo-modules/test-resources/example-bin/src/bin/example.rs","edition":"2018"},{"kind":["custom-build"],"crate_types":["bin"],"name":"build-script-build","src_path":"/home/hiram/git/cargo-modules/test-resources/example-bin/build.rs","edition":"2018"}],"features":{},"manifest_path":"/home/hiram/git/cargo-modules/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:///home/hiram/git/cargo-modules/test-resources/example-bin)"],"resolve":null,"target_directory":"/home/hiram/git/cargo-modules/test-resources/example-bin/target","version":1,"workspace_root":"/home/hiram/git/cargo-modules/test-resources/example-bin"}
1 change: 1 addition & 0 deletions test-resources/example-lib-edition-2015.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"packages":[{"name":"example-lib-edition-2015","version":"0.1.0","id":"example-lib-edition-2015 0.1.0 (path+file:///home/hiram/git/cargo-modules/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":"/home/hiram/git/cargo-modules/test-resources/example-lib-edition-2015/src/lib.rs","edition":"2015"},{"kind":["custom-build"],"crate_types":["bin"],"name":"build-script-build","src_path":"/home/hiram/git/cargo-modules/test-resources/example-lib-edition-2015/build.rs","edition":"2015"}],"features":{},"manifest_path":"/home/hiram/git/cargo-modules/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:///home/hiram/git/cargo-modules/test-resources/example-lib-edition-2015)"],"resolve":null,"target_directory":"/home/hiram/git/cargo-modules/test-resources/example-lib-edition-2015/target","version":1,"workspace_root":"/home/hiram/git/cargo-modules/test-resources/example-lib-edition-2015"}
1 change: 1 addition & 0 deletions test-resources/example-lib-edition-2018.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"packages":[{"name":"example-lib-edition-2018","version":"0.1.0","id":"example-lib-edition-2018 0.1.0 (path+file:///home/hiram/git/cargo-modules/test-resources/example-lib-edition-2018)","license":null,"license_file":null,"description":null,"source":null,"dependencies":[],"targets":[{"kind":["lib"],"crate_types":["lib"],"name":"example-lib-edition-2018","src_path":"/home/hiram/git/cargo-modules/test-resources/example-lib-edition-2018/src/lib.rs","edition":"2018"},{"kind":["custom-build"],"crate_types":["bin"],"name":"build-script-build","src_path":"/home/hiram/git/cargo-modules/test-resources/example-lib-edition-2018/build.rs","edition":"2018"}],"features":{},"manifest_path":"/home/hiram/git/cargo-modules/test-resources/example-lib-edition-2018/Cargo.toml","metadata":null,"authors":["Name <email@email.com>"],"categories":[],"keywords":[],"readme":null,"repository":null,"edition":"2018","links":null}],"workspace_members":["example-lib-edition-2018 0.1.0 (path+file:///home/hiram/git/cargo-modules/test-resources/example-lib-edition-2018)"],"resolve":null,"target_directory":"/home/hiram/git/cargo-modules/test-resources/example-lib-edition-2018/target","version":1,"workspace_root":"/home/hiram/git/cargo-modules/test-resources/example-lib-edition-2018"}
1 change: 1 addition & 0 deletions test-resources/example-lib-no-edition.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"packages":[{"name":"example-lib","version":"0.1.0","id":"example-lib 0.1.0 (path+file:///home/hiram/git/cargo-modules/test-resources/example-lib-no-edition)","license":null,"license_file":null,"description":null,"source":null,"dependencies":[],"targets":[{"kind":["lib"],"crate_types":["lib"],"name":"example-lib","src_path":"/home/hiram/git/cargo-modules/test-resources/example-lib-no-edition/src/lib.rs","edition":"2015"}],"features":{},"manifest_path":"/home/hiram/git/cargo-modules/test-resources/example-lib-no-edition/Cargo.toml","metadata":null,"authors":["Name <email@email.com>"],"categories":[],"keywords":[],"readme":null,"repository":null,"edition":"2015","links":null}],"workspace_members":["example-lib 0.1.0 (path+file:///home/hiram/git/cargo-modules/test-resources/example-lib-no-edition)"],"resolve":null,"target_directory":"/home/hiram/git/cargo-modules/test-resources/example-lib-no-edition/target","version":1,"workspace_root":"/home/hiram/git/cargo-modules/test-resources/example-lib-no-edition"}
1 change: 1 addition & 0 deletions test-resources/example-plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"packages":[{"name":"example-plugin","version":"0.1.0","id":"example-plugin 0.1.0 (path+file:///home/hiram/git/cargo-modules/test-resources/example-plugin)","license":null,"license_file":null,"description":null,"source":null,"dependencies":[],"targets":[{"kind":["dylib"],"crate_types":["dylib"],"name":"example-plugin","src_path":"/home/hiram/git/cargo-modules/test-resources/example-plugin/src/lib.rs","edition":"2018"},{"kind":["custom-build"],"crate_types":["bin"],"name":"build-script-build","src_path":"/home/hiram/git/cargo-modules/test-resources/example-plugin/build.rs","edition":"2018"}],"features":{},"manifest_path":"/home/hiram/git/cargo-modules/test-resources/example-plugin/Cargo.toml","metadata":null,"authors":["Name <email@email.com>"],"categories":[],"keywords":[],"readme":null,"repository":null,"edition":"2018","links":null}],"workspace_members":["example-plugin 0.1.0 (path+file:///home/hiram/git/cargo-modules/test-resources/example-plugin)"],"resolve":null,"target_directory":"/home/hiram/git/cargo-modules/test-resources/example-plugin/target","version":1,"workspace_root":"/home/hiram/git/cargo-modules/test-resources/example-plugin"}
1 change: 1 addition & 0 deletions test-resources/example-proc-macro.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"packages":[{"name":"example-proc-macro","version":"0.1.0","id":"example-proc-macro 0.1.0 (path+file:///home/hiram/git/cargo-modules/test-resources/example-proc-macro)","license":null,"license_file":null,"description":null,"source":null,"dependencies":[],"targets":[{"kind":["proc-macro"],"crate_types":["proc-macro"],"name":"example-proc-macro","src_path":"/home/hiram/git/cargo-modules/test-resources/example-proc-macro/src/lib.rs","edition":"2018"},{"kind":["custom-build"],"crate_types":["bin"],"name":"build-script-build","src_path":"/home/hiram/git/cargo-modules/test-resources/example-proc-macro/build.rs","edition":"2018"}],"features":{},"manifest_path":"/home/hiram/git/cargo-modules/test-resources/example-proc-macro/Cargo.toml","metadata":null,"authors":["Name <email@email.com>"],"categories":[],"keywords":[],"readme":null,"repository":null,"edition":"2018","links":null}],"workspace_members":["example-proc-macro 0.1.0 (path+file:///home/hiram/git/cargo-modules/test-resources/example-proc-macro)"],"resolve":null,"target_directory":"/home/hiram/git/cargo-modules/test-resources/example-proc-macro/target","version":1,"workspace_root":"/home/hiram/git/cargo-modules/test-resources/example-proc-macro"}
1 change: 1 addition & 0 deletions test-resources/example-virtual-workspace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"packages":[{"name":"example-workspace-package","version":"0.1.0","id":"example-workspace-package 0.1.0 (path+file:///home/hiram/git/cargo-modules/test-resources/example-virtual-workspace/example-workspace-package)","license":null,"license_file":null,"description":null,"source":null,"dependencies":[],"targets":[{"kind":["lib"],"crate_types":["lib"],"name":"example-workspace-package","src_path":"/home/hiram/git/cargo-modules/test-resources/example-virtual-workspace/example-workspace-package/src/lib.rs","edition":"2018"}],"features":{},"manifest_path":"/home/hiram/git/cargo-modules/test-resources/example-virtual-workspace/example-workspace-package/Cargo.toml","metadata":null,"authors":["Name <email@email.com>"],"categories":[],"keywords":[],"readme":null,"repository":null,"edition":"2018","links":null}],"workspace_members":["example-workspace-package 0.1.0 (path+file:///home/hiram/git/cargo-modules/test-resources/example-virtual-workspace/example-workspace-package)"],"resolve":null,"target_directory":"/home/hiram/git/cargo-modules/test-resources/example-virtual-workspace/target","version":1,"workspace_root":"/home/hiram/git/cargo-modules/test-resources/example-virtual-workspace"}
1 change: 1 addition & 0 deletions test-resources/example-workspace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"packages":[{"name":"example-workspace-package","version":"0.1.0","id":"example-workspace-package 0.1.0 (path+file:///home/hiram/git/cargo-modules/test-resources/example-workspace/example-workspace-package)","license":null,"license_file":null,"description":null,"source":null,"dependencies":[],"targets":[{"kind":["lib"],"crate_types":["lib"],"name":"example-workspace-package","src_path":"/home/hiram/git/cargo-modules/test-resources/example-workspace/example-workspace-package/src/lib.rs","edition":"2018"}],"features":{},"manifest_path":"/home/hiram/git/cargo-modules/test-resources/example-workspace/example-workspace-package/Cargo.toml","metadata":null,"authors":["Name <email@email.com>"],"categories":[],"keywords":[],"readme":null,"repository":null,"edition":"2018","links":null},{"name":"example-workspace","version":"0.1.0","id":"example-workspace 0.1.0 (path+file:///home/hiram/git/cargo-modules/test-resources/example-workspace)","license":null,"license_file":null,"description":null,"source":null,"dependencies":[],"targets":[{"kind":["lib"],"crate_types":["lib"],"name":"example-workspace","src_path":"/home/hiram/git/cargo-modules/test-resources/example-workspace/src/lib.rs","edition":"2018"}],"features":{},"manifest_path":"/home/hiram/git/cargo-modules/test-resources/example-workspace/Cargo.toml","metadata":null,"authors":["Name <email@email.com>"],"categories":[],"keywords":[],"readme":null,"repository":null,"edition":"2018","links":null}],"workspace_members":["example-workspace-package 0.1.0 (path+file:///home/hiram/git/cargo-modules/test-resources/example-workspace/example-workspace-package)","example-workspace 0.1.0 (path+file:///home/hiram/git/cargo-modules/test-resources/example-workspace)"],"resolve":null,"target_directory":"/home/hiram/git/cargo-modules/test-resources/example-workspace/target","version":1,"workspace_root":"/home/hiram/git/cargo-modules/test-resources/example-workspace"}
9 changes: 9 additions & 0 deletions test-resources/generate-test-manifets.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

find "$(pwd)/test-resources/" -maxdepth 1 -mindepth 1 -type d | while read -r dir
do
echo "$dir"
cd "$dir" || exit
cargo metadata --no-deps --format-version 1 > "$dir.json"
cd - || exit
done

0 comments on commit 3d61f2e

Please sign in to comment.