Skip to content

Commit

Permalink
[meta] move fixtures to top level
Browse files Browse the repository at this point in the history
We're starting to use them throughout the cargo-guppy
codebase.

Also add a small README.
  • Loading branch information
sunshowers committed May 1, 2020
1 parent 0a6c440 commit 7624989
Show file tree
Hide file tree
Showing 28 changed files with 39 additions and 27 deletions.
File renamed without changes.
12 changes: 12 additions & 0 deletions fixtures/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Fixtures for cargo-guppy

This directory contains interesting test corpuses used within the cargo-guppy codebase.

The fixtures are organized into several folders.

## `cargo metadata` output

* `small`: relatively simple examples that cover basic and some edge case functionality
* `large`: complex examples pulled from real-world Rust repositories, that test a variety of edge cases
* `invalid`: examples that are *representable* as cargo metadata (i.e. they are valid JSON and follow the general
schema) but are *invalid* in some way; `cargo metadata` should never be able to generate these
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion guppy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Print out all direct dependencies of a package:
use guppy::{PackageId, CargoMetadata};

// `guppy` accepts `cargo metadata` JSON output. Use a pre-existing fixture for these examples.
let metadata = CargoMetadata::parse_json(include_str!("../fixtures/small/metadata1.json")).unwrap();
let metadata = CargoMetadata::parse_json(include_str!("../../fixtures/small/metadata1.json")).unwrap();
let package_graph = metadata.build_graph().unwrap();

// `guppy` provides several ways to get hold of package IDs. Use a pre-defined one for this
Expand Down
2 changes: 1 addition & 1 deletion guppy/examples/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::iter;

fn main() -> Result<(), Error> {
// `guppy` accepts `cargo metadata` JSON output. Use a pre-existing fixture for these examples.
let metadata = CargoMetadata::parse_json(include_str!("../fixtures/small/metadata1.json"))?;
let metadata = CargoMetadata::parse_json(include_str!("../../fixtures/small/metadata1.json"))?;
let package_graph = metadata.build_graph()?;

// `guppy` provides several ways to get hold of package IDs. Use a pre-defined one for this
Expand Down
2 changes: 1 addition & 1 deletion guppy/examples/print_by_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::io::{stdout, Write};
fn main() -> Result<(), Error> {
// `guppy` accepts `cargo metadata` JSON output. Use a pre-existing fixture for these examples.
let metadata =
CargoMetadata::parse_json(include_str!("../fixtures/large/metadata_libra.json"))?;
CargoMetadata::parse_json(include_str!("../../fixtures/large/metadata_libra.json"))?;
let package_graph = metadata.build_graph()?;

// Pick an interesting package to compute dependencies of.
Expand Down
2 changes: 1 addition & 1 deletion guppy/examples/print_dot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl PackageDotVisitor for PackageNameVisitor {
fn main() -> Result<(), Error> {
// `guppy` accepts `cargo metadata` JSON output. Use a pre-existing fixture for these examples.
let metadata =
CargoMetadata::parse_json(include_str!("../fixtures/large/metadata_libra.json"))?;
CargoMetadata::parse_json(include_str!("../../fixtures/large/metadata_libra.json"))?;
let package_graph = metadata.build_graph()?;

// Non-workspace packages cannot depend on packages within the workspace, so the reverse
Expand Down
2 changes: 1 addition & 1 deletion guppy/examples/remove_dev_only.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::iter;
fn main() -> Result<(), Error> {
// `guppy` accepts `cargo metadata` JSON output. Use a pre-existing fixture for these examples.
let metadata =
CargoMetadata::parse_json(include_str!("../fixtures/large/metadata_libra.json"))?;
CargoMetadata::parse_json(include_str!("../../fixtures/large/metadata_libra.json"))?;
let package_graph = metadata.build_graph()?;

// Pick an important binary package and compute the number of dependencies.
Expand Down
2 changes: 1 addition & 1 deletion guppy/examples/topo_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use guppy::{CargoMetadata, Error};
fn main() -> Result<(), Error> {
// `guppy` accepts `cargo metadata` JSON output. Use a pre-existing fixture for these examples.
let metadata =
CargoMetadata::parse_json(include_str!("../fixtures/large/metadata_libra.json"))?;
CargoMetadata::parse_json(include_str!("../../fixtures/large/metadata_libra.json"))?;
let package_graph = metadata.build_graph()?;

// Non-workspace packages cannot depend on packages within the workspace, so the reverse
Expand Down
2 changes: 1 addition & 1 deletion guppy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
//! use guppy::{CargoMetadata, PackageId};
//!
//! // `guppy` accepts `cargo metadata` JSON output. Use a pre-existing fixture for these examples.
//! let metadata = CargoMetadata::parse_json(include_str!("../fixtures/small/metadata1.json")).unwrap();
//! let metadata = CargoMetadata::parse_json(include_str!("../../fixtures/small/metadata1.json")).unwrap();
//! let package_graph = metadata.build_graph().unwrap();
//!
//! // `guppy` provides several ways to get hold of package IDs. Use a pre-defined one for this
Expand Down
25 changes: 14 additions & 11 deletions guppy/src/unit_tests/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::path::PathBuf;
use target_spec::TargetFeatures;

// Metadata along with interesting crate names.
pub(crate) static METADATA1: &str = include_str!("../../fixtures/small/metadata1.json");
pub(crate) static METADATA1: &str = include_str!("../../../fixtures/small/metadata1.json");
pub(crate) static METADATA1_TESTCRATE: &str = "testcrate 0.1.0 (path+file:///fakepath/testcrate)";
pub(crate) static METADATA1_DATATEST: &str =
"datatest 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)";
Expand All @@ -28,14 +28,14 @@ pub(crate) static METADATA1_REGION: &str =
pub(crate) static METADATA1_DTOA: &str =
"dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)";

pub(crate) static METADATA2: &str = include_str!("../../fixtures/small/metadata2.json");
pub(crate) static METADATA2: &str = include_str!("../../../fixtures/small/metadata2.json");
pub(crate) static METADATA2_TESTCRATE: &str =
"testworkspace-crate 0.1.0 (path+file:///Users/fakeuser/local/testworkspace/testcrate)";
pub(crate) static METADATA2_WALKDIR: &str =
"walkdir 2.2.9 (path+file:///Users/fakeuser/local/testworkspace/walkdir)";
pub(crate) static METADATA2_QUOTE: &str = "quote 1.0.2 (path+file:///Users/fakeuser/local/quote)";

pub(crate) static METADATA_DUPS: &str = include_str!("../../fixtures/small/metadata_dups.json");
pub(crate) static METADATA_DUPS: &str = include_str!("../../../fixtures/small/metadata_dups.json");
pub(crate) static METADATA_DUPS_TESTCRATE: &str =
"testcrate-dups 0.1.0 (path+file:///Users/fakeuser/local/testcrates/testcrate-dups)";
pub(crate) static METADATA_DUPS_LAZY_STATIC_1: &str =
Expand All @@ -47,13 +47,15 @@ pub(crate) static METADATA_DUPS_BYTES_03: &str =
pub(crate) static METADATA_DUPS_BYTES_05: &str =
"bytes 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)";

pub(crate) static METADATA_CYCLE1: &str = include_str!("../../fixtures/small/metadata_cycle1.json");
pub(crate) static METADATA_CYCLE1: &str =
include_str!("../../../fixtures/small/metadata_cycle1.json");
pub(crate) static METADATA_CYCLE1_BASE: &str =
"testcycles-base 0.1.0 (path+file:///Users/fakeuser/local/testcrates/testcycles/testcycles-base)";
pub(crate) static METADATA_CYCLE1_HELPER: &str =
"testcycles-helper 0.1.0 (path+file:///Users/fakeuser/local/testcrates/testcycles/testcycles-helper)";

pub(crate) static METADATA_CYCLE2: &str = include_str!("../../fixtures/small/metadata_cycle2.json");
pub(crate) static METADATA_CYCLE2: &str =
include_str!("../../../fixtures/small/metadata_cycle2.json");
pub(crate) static METADATA_CYCLE2_UPPER_A: &str =
"upper-a 0.1.0 (path+file:///Users/fakeuser/local/testcrates/cycle2/upper-a)";
pub(crate) static METADATA_CYCLE2_UPPER_B: &str =
Expand All @@ -64,7 +66,7 @@ pub(crate) static METADATA_CYCLE2_LOWER_B: &str =
"lower-b 0.1.0 (path+file:///Users/fakeuser/local/testcrates/cycle2/lower-b)";

pub(crate) static METADATA_TARGETS1: &str =
include_str!("../../fixtures/small/metadata_targets1.json");
include_str!("../../../fixtures/small/metadata_targets1.json");
pub(crate) static METADATA_TARGETS1_TESTCRATE: &str =
"testcrate-targets 0.1.0 (path+file:///Users/fakeuser/local/testcrates/testcrate-targets)";
pub(crate) static METADATA_TARGETS1_LAZY_STATIC_1: &str =
Expand All @@ -79,12 +81,12 @@ pub(crate) static METADATA_TARGETS1_DEP_A: &str =
"dep-a 0.1.0 (path+file:///Users/fakeuser/local/testcrates/dep-a)";

pub(crate) static METADATA_BUILD_TARGETS1: &str =
include_str!("../../fixtures/small/metadata_build_targets1.json");
include_str!("../../../fixtures/small/metadata_build_targets1.json");
pub(crate) static METADATA_BUILD_TARGETS1_TESTCRATE: &str =
"testcrate 0.1.0 (path+file:///Users/fakeuser/local/testcrates/test-build-targets)";

pub(crate) static METADATA_PROC_MACRO1: &str =
include_str!("../../fixtures/small/metadata_proc_macro1.json");
include_str!("../../../fixtures/small/metadata_proc_macro1.json");
pub(crate) static METADATA_PROC_MACRO1_MACRO: &str =
"macro 0.1.0 (path+file:///Users/fakeuser/local/testcrates/proc-macro/macro)";
pub(crate) static METADATA_PROC_MACRO1_NORMAL_USER: &str =
Expand All @@ -94,7 +96,8 @@ pub(crate) static METADATA_PROC_MACRO1_BUILD_USER: &str =
pub(crate) static METADATA_PROC_MACRO1_DEV_USER: &str =
"dev-user 0.1.0 (path+file:///Users/fakeuser/local/testcrates/proc-macro/dev-user)";

pub(crate) static METADATA_LIBRA: &str = include_str!("../../fixtures/large/metadata_libra.json");
pub(crate) static METADATA_LIBRA: &str =
include_str!("../../../fixtures/large/metadata_libra.json");
pub(crate) static METADATA_LIBRA_ADMISSION_CONTROL_SERVICE: &str =
"admission-control-service 0.1.0 (path+file:///Users/fakeuser/local/libra/admission_control/admission-control-service)";
pub(crate) static METADATA_LIBRA_COMPILER: &str =
Expand Down Expand Up @@ -139,10 +142,10 @@ pub(crate) static METADATA_LIBRA_CFG_IF: &str =
"cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)";

pub(crate) static METADATA_LIBRA_F0091A4: &str =
include_str!("../../fixtures/large/metadata_libra_f0091a4.json");
include_str!("../../../fixtures/large/metadata_libra_f0091a4.json");

pub(crate) static METADATA_LIBRA_9FFD93B: &str =
include_str!("../../fixtures/large/metadata_libra_9ffd93b.json");
include_str!("../../../fixtures/large/metadata_libra_9ffd93b.json");

pub(crate) static FAKE_AUTHOR: &str = "Fake Author <[email protected]>";

Expand Down
10 changes: 5 additions & 5 deletions guppy/src/unit_tests/invalid_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,39 @@ use cargo_metadata::{Metadata, Target};
#[test]
fn optional_dev_dep() {
assert_invalid(
include_str!("../../fixtures/invalid/optional_dev_dep.json"),
include_str!("../../../fixtures/invalid/optional_dev_dep.json"),
"dependency 'lazy_static' marked optional",
);
}

#[test]
fn duplicate_workspace_names() {
assert_invalid(
include_str!("../../fixtures/invalid/duplicate_workspace_names.json"),
include_str!("../../../fixtures/invalid/duplicate_workspace_names.json"),
"duplicate package name in workspace: 'pkg' is name for",
);
}

#[test]
fn build_targets_empty_kinds() {
assert_invalid(
include_str!("../../fixtures/invalid/build_targets_empty_kinds.json"),
include_str!("../../../fixtures/invalid/build_targets_empty_kinds.json"),
"build target 'bench1' has no kinds",
);
}

#[test]
fn build_targets_non_bin() {
assert_invalid(
include_str!("../../fixtures/invalid/build_targets_non_bin.json"),
include_str!("../../../fixtures/invalid/build_targets_non_bin.json"),
"build target 'Binary(\"testcrate\")' has invalid crate types '{cdylib}'",
);
}

#[test]
fn build_targets_duplicate_lib() {
assert_invalid(
include_str!("../../fixtures/invalid/build_targets_duplicate_lib.json"),
include_str!("../../../fixtures/invalid/build_targets_duplicate_lib.json"),
"duplicate build targets for Library",
);
}
Expand Down
5 changes: 1 addition & 4 deletions tools/benchmarks/benches/package_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ pub fn benchmarks(c: &mut Criterion) {

fn make_package_graph() -> PackageGraph {
// Use this package graph as a large and representative one.
PackageGraph::from_json(include_str!(
"../../../guppy/fixtures/large/metadata_libra.json"
))
.unwrap()
PackageGraph::from_json(include_str!("../../../fixtures/large/metadata_libra.json")).unwrap()
}

/// Generate pairs of IDs for benchmarks.
Expand Down

0 comments on commit 7624989

Please sign in to comment.