Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial changes to drop default serde dependency #255

Merged
29 changes: 21 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ default = ["colors"]

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

# Enables support for running filters on snapshot
filters = ["regex"]
Expand All @@ -34,26 +34,39 @@ glob = ["walkdir", "globset"]
colors = ["console"]

# This feature is now just always enabled because we use yaml internally now.
serialization = []
serialization = ["serde"]

# This feature is no longer used as snapshot name detection was changed.
backtrace = []

# 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", "serialization"]
json = ["serde_json", "serialization"]
ron = ["dep_ron", "serialization"]
toml = ["dep_toml", "serialization"]
yaml = ["serde_yaml", "serialization"]

[dependencies]
csv = { version = "1.1.4", optional = true }
serde = { version = "1.0.117", features = ["derive"] }
serde_yaml = "0.8.26"
dep_csv = { package = "csv", version = "1.1.4", optional = true }
console = { version = "0.15.1", optional = true, default-features = false }
serde_json = "1.0.59"
pest = { version = "2.1.3", optional = true }
pest_derive = { version = "2.1.0", optional = true }
ron = { version = "0.7.1", optional = true }
toml = { version = "0.5.7", 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"] }
once_cell = "1.9.0"
regex = { version = "1.6.0", default-features = false, optional = true, features = ["std", "unicode"] }
yaml-rust = "0.4.5"
dep_json = { package = "json", version = "0.12.4" }
serde = { version = "1.0.117", optional = true }
serde_json = { version = "1.0.59", optional = true }
serde_yaml = { version = "0.8.26", optional = true }
linked-hash-map = "0.5.6"

[dev-dependencies]
serde = { version = "1.0.117", features = ["derive"] }
similar-asserts = "1.4.2"
13 changes: 11 additions & 2 deletions cargo-insta/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cargo-insta/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ edition = "2018"
readme = "README.md"

[dependencies]
insta = { version = "=1.17.1", path = "..", features = ["redactions"] }
insta = { version = "=1.17.1", path = "..", features = ["json", "yaml", "redactions"] }
console = "0.15.1"
structopt = "0.3.20"
serde = { version = "1.0.117", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion cargo-insta/integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ edition = "2018"

[dependencies]
dircpy = "0.3.4"
insta = { version = "1.1.0", path = "../..", features = ["redactions", "glob"] }
insta = { version = "1.1.0", path = "../..", features = ["json", "yaml", "redactions", "glob"] }
walkdir = "2.3.1"
serde = { version = "1.0.117", features = ["derive"] }
30 changes: 30 additions & 0 deletions src/content/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use std::{error, fmt, result};

use super::Content;

pub type Result<T> = result::Result<T, Error>;

#[derive(Debug)]
pub enum Error {
InvalidStructField(Content),
FailedParsingYaml,
UnexpectedDataType,
MissingField,
UnsupportedDataType,
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidStructField(content) => write!(f, "Invalid struct field: {:?}", content),
Self::FailedParsingYaml => f.write_str("Failed parsing the provided YAML text"),
Self::UnexpectedDataType => {
f.write_str("The present data type wasn't what was expected")
}
Self::MissingField => f.write_str("A required field was missing"),
Self::UnsupportedDataType => f.write_str("Failed converting an unsupported data type"),
}
}
}

impl error::Error for Error {}
Loading