From 933eb1ac40f65b0b801ba40dc9622aabbd8d75c3 Mon Sep 17 00:00:00 2001 From: Graham Esau Date: Tue, 6 Aug 2019 08:55:25 +0100 Subject: [PATCH] Use pretty_assertions in tests --- schemars/Cargo.toml | 3 +++ schemars/tests/test.rs | 56 ++++++++++++++++++++---------------------- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/schemars/Cargo.toml b/schemars/Cargo.toml index f694cb6..35ef431 100644 --- a/schemars/Cargo.toml +++ b/schemars/Cargo.toml @@ -10,3 +10,6 @@ edition = "2018" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" schemars_derive = { version = "0.1.0", path = "../schemars_derive" } + +[dev-dependencies] +pretty_assertions = "0.6.1" diff --git a/schemars/tests/test.rs b/schemars/tests/test.rs index 9bb82de..b6074af 100644 --- a/schemars/tests/test.rs +++ b/schemars/tests/test.rs @@ -1,38 +1,34 @@ +use pretty_assertions::assert_eq; use schemars::schema::*; use schemars::{gen, schema_for}; use serde_json::{from_str, to_string_pretty}; use std::fs; -#[cfg(test)] -mod tests { - use super::*; +#[test] +fn schema_matches_default_settings() -> Result<(), Box> { + let expected_json = fs::read_to_string("tests/schema.json")?; + let expected: Schema = from_str(&expected_json)?; - #[test] - fn schema_matches_default_settings() -> Result<(), Box> { - let expected_json = fs::read_to_string("tests/schema.json")?; - let expected: Schema = from_str(&expected_json)?; + let actual = schema_for!(Schema); + fs::write("tests/schema.actual.json", to_string_pretty(&actual)?)?; - let actual = schema_for!(Schema); - fs::write("tests/schema.actual.json", to_string_pretty(&actual)?)?; - - assert_eq!(actual, expected, "\n\nGenerated schema did not match saved schema - generated schema has been written to \"tests/schema.actual.json\"."); - Ok(()) - } - - #[test] - fn schema_matches_openapi3() -> Result<(), Box> { - let expected_json = fs::read_to_string("tests/schema-openapi3.json")?; - let expected: Schema = from_str(&expected_json)?; - - let actual = gen::SchemaSettings::openapi3() - .into_generator() - .into_root_schema_for::(); - fs::write( - "tests/schema-openapi3.actual.json", - to_string_pretty(&actual)?, - )?; - - assert_eq!(actual, expected, "\n\nGenerated schema did not match saved schema - generated schema has been written to \"tests/schema-openapi3.actual.json\"."); - Ok(()) - } + assert_eq!(actual, expected, "Generated schema did not match saved schema - generated schema has been written to \"tests/schema.actual.json\"."); + Ok(()) +} + +#[test] +fn schema_matches_openapi3() -> Result<(), Box> { + let expected_json = fs::read_to_string("tests/schema-openapi3.json")?; + let expected: Schema = from_str(&expected_json)?; + + let actual = gen::SchemaSettings::openapi3() + .into_generator() + .into_root_schema_for::(); + fs::write( + "tests/schema-openapi3.actual.json", + to_string_pretty(&actual)?, + )?; + + assert_eq!(actual, expected, "Generated schema did not match saved schema - generated schema has been written to \"tests/schema-openapi3.actual.json\"."); + Ok(()) }