Skip to content

Commit

Permalink
Cargo.toml: introduce a virtual workspace
Browse files Browse the repository at this point in the history
This allows IDE Rust integration to work when the root of the repository
is opened. Prior to this change, a developer would have to open
cargo-insta to get code completion for that crate.

This also causes `make lint` to run clippy over cargo-insta.
  • Loading branch information
tamird committed Oct 2, 2023
1 parent 9623b3a commit ccaa6c5
Show file tree
Hide file tree
Showing 116 changed files with 93 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ jobs:
with:
toolchain: 1.51.0
- name: Check
run: cargo check --no-default-features
run: cargo check -p insta --no-default-features
69 changes: 3 additions & 66 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,67 +1,4 @@
[package]
name = "insta"
version = "1.33.0"
license = "Apache-2.0"
authors = ["Armin Ronacher <armin.ronacher@active-4.com>"]
description = "A snapshot testing library for Rust"
edition = "2018"
rust-version = "1.51.0"
homepage = "https://insta.rs/"
repository = "https://github.com/mitsuhiko/insta"
keywords = ["snapshot", "testing", "jest", "approval"]
readme = "README.md"
exclude = [
"assets/*"
]
[workspace]
members = ["cargo-insta", "insta"]

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["colors"]

# when the redactions feature is enabled values can be redacted in serialized
# snapshots.
redactions = ["pest", "pest_derive", "serde"]

# Enables support for running filters on snapshot
filters = ["regex"]

# Glob support
glob = ["walkdir", "globset"]

# Color support
colors = ["console"]

# Serialization formats
# TODO: This could be cleaner by using "dep:csv" without renaming the dep, but
# this technique allows for a lower MSRV
csv = ["dep_csv", "serde"]
json = ["serde"]
ron = ["dep_ron", "serde"]
toml = ["dep_toml", "serde"]
yaml = ["serde"]

# internal feature exclusive to cargo-insta
_cargo_insta_internal = []

[dependencies]
dep_csv = { package = "csv", version = "=1.1.6", optional = true }
console = { version = "0.15.4", optional = true, default-features = false }
pest = { version = "2.1.3", optional = true }
pest_derive = { version = "2.1.0", optional = true }
dep_ron = { package = "ron", version = "0.7.1", optional = true }
dep_toml = { package = "toml", version = "0.5.7", optional = true }
globset = { version = "0.4.6", optional = true }
walkdir = { version = "2.3.1", optional = true }
similar = { version = "2.1.0", features = ["inline"] }
regex = { version = "1.6.0", default-features = false, optional = true, features = ["std", "unicode"] }
yaml-rust = "0.4.5"
serde = { version = "1.0.117", optional = true }
linked-hash-map = "0.5.6"
lazy_static = "1.4.0"

[dev-dependencies]
serde = { version = "1.0.117", features = ["derive"] }
similar-asserts = "1.4.2"
resolver = "2"
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ cargotest:
@cargo test --all-features
@cargo test --no-default-features
@cargo test --features redactions -- --test-threads 1
@cd cargo-insta; cargo test

check-minver:
@echo "MINVER CHECK"
@cargo minimal-versions check
@cargo minimal-versions check --all-features
@cargo minimal-versions check --no-default-features
@cargo minimal-versions check --features redactions
@cargo minimal-versions check -p insta
@cargo minimal-versions check -p insta --all-features
@cargo minimal-versions check -p insta --no-default-features
@cargo minimal-versions check -p insta --features redactions

format:
@rustup component add rustfmt 2> /dev/null
Expand Down
7 changes: 6 additions & 1 deletion cargo-insta/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ edition = "2018"
readme = "README.md"

[dependencies]
insta = { version = "=1.33.0", path = "..", features = ["json", "yaml", "redactions", "_cargo_insta_internal"] }
insta = { version = "=1.33.0", path = "../insta", features = [
"json",
"yaml",
"redactions",
"_cargo_insta_internal",
] }
console = "0.15.4"
structopt = { version = "0.3.26", default-features = false }
serde = { version = "1.0.117", features = ["derive"] }
Expand Down
7 changes: 6 additions & 1 deletion cargo-insta/integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ edition = "2018"

[dependencies]
dircpy = "0.3.4"
insta = { path = "../..", features = ["json", "yaml", "redactions", "glob"] }
insta = { path = "../../insta", features = [
"json",
"yaml",
"redactions",
"glob",
] }
walkdir = "2.3.1"
serde = { version = "1.0.117", features = ["derive"] }
3 changes: 3 additions & 0 deletions cargo-insta/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct Opts {
bin_name = "cargo insta",
after_help = "For the online documentation of the latest version, see https://insta.rs/docs/cli/."
)]
#[allow(clippy::large_enum_variant)]
enum Command {
/// Interactively review snapshots
#[structopt(name = "review", alias = "verify")]
Expand Down Expand Up @@ -408,6 +409,7 @@ fn handle_target_args(target_args: &TargetArgs) -> Result<LocationInfo<'_>, Box<
}
}

#[allow(clippy::type_complexity)]
fn load_snapshot_containers<'a>(
loc: &'a LocationInfo,
) -> Result<
Expand Down Expand Up @@ -768,6 +770,7 @@ fn handle_unreferenced_snapshots(
Ok(())
}

#[allow(clippy::type_complexity)]
fn prepare_test_runner<'snapshot_ref>(
test_runner: TestRunner,
unreferenced: UnreferencedSnapshots,
Expand Down
2 changes: 1 addition & 1 deletion cargo-insta/src/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl FilePatcher {

// replace lines
let snapshot_line_contents =
vec![prefix, snapshot.to_inline(inline.indentation), suffix].join("");
[prefix, snapshot.to_inline(inline.indentation), suffix].join("");

self.lines.splice(
inline.start.0..=inline.end.0,
Expand Down
64 changes: 64 additions & 0 deletions insta/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[package]
name = "insta"
version = "1.33.0"
license = "Apache-2.0"
authors = ["Armin Ronacher <armin.ronacher@active-4.com>"]
description = "A snapshot testing library for Rust"
edition = "2018"
rust-version = "1.51.0"
homepage = "https://insta.rs/"
repository = "https://github.com/mitsuhiko/insta"
keywords = ["snapshot", "testing", "jest", "approval"]
readme = "README.md"

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["colors"]

# when the redactions feature is enabled values can be redacted in serialized
# snapshots.
redactions = ["pest", "pest_derive", "serde"]

# Enables support for running filters on snapshot
filters = ["regex"]

# Glob support
glob = ["walkdir", "globset"]

# Color support
colors = ["console"]

# Serialization formats
# TODO: This could be cleaner by using "dep:csv" without renaming the dep, but
# this technique allows for a lower MSRV
csv = ["dep_csv", "serde"]
json = ["serde"]
ron = ["dep_ron", "serde"]
toml = ["dep_toml", "serde"]
yaml = ["serde"]

# internal feature exclusive to cargo-insta
_cargo_insta_internal = []

[dependencies]
dep_csv = { package = "csv", version = "=1.1.6", optional = true }
console = { version = "0.15.4", optional = true, default-features = false }
pest = { version = "2.1.3", optional = true }
pest_derive = { version = "2.1.0", optional = true }
dep_ron = { package = "ron", version = "0.7.1", optional = true }
dep_toml = { package = "toml", version = "0.5.7", optional = true }
globset = { version = "0.4.6", optional = true }
walkdir = { version = "2.3.1", optional = true }
similar = { version = "2.1.0", features = ["inline"] }
regex = { version = "1.6.0", default-features = false, optional = true, features = ["std", "unicode"] }
yaml-rust = "0.4.5"
serde = { version = "1.0.117", optional = true }
linked-hash-map = "0.5.6"
lazy_static = "1.4.0"

[dev-dependencies]
serde = { version = "1.0.117", features = ["derive"] }
similar-asserts = "1.4.2"
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.
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.
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.
6 changes: 3 additions & 3 deletions scripts/bump-version.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/bin/bash
set -euo pipefail

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd $SCRIPT_DIR/..

NEW_VERSION="${1}"

echo "Bumping version: ${NEW_VERSION}"
perl -pi -e "s/^version = \".*?\"/version = \"$NEW_VERSION\"/" Cargo.toml
perl -pi -e "s/^version = \".*?\"/version = \"$NEW_VERSION\"/" insta/Cargo.toml
perl -pi -e "s/^version = \".*?\"/version = \"$NEW_VERSION\"/" cargo-insta/Cargo.toml
perl -pi -e "s/^(insta.*?)version = \".*?\"/\$1version = \"=$NEW_VERSION\"/" cargo-insta/Cargo.toml

cd cargo-insta; cargo check
cargo check
4 changes: 2 additions & 2 deletions scripts/publish-all.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
set -euo pipefail

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd $SCRIPT_DIR/..

cargo publish -p insta
cd cargo-insta && cargo publish
cargo publish -p insta-insta

0 comments on commit ccaa6c5

Please sign in to comment.