Skip to content

Commit 01a47f3

Browse files
committed
fix(test): Remove unused, deprecated with_json
1 parent c18765a commit 01a47f3

File tree

2 files changed

+1
-143
lines changed

2 files changed

+1
-143
lines changed

crates/cargo-test-support/src/compare.rs

Lines changed: 1 addition & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
use crate::cross_compile::try_alternate;
4545
use crate::paths;
4646
use crate::{diff, rustc_host};
47-
use anyhow::{bail, Context, Result};
47+
use anyhow::{bail, Result};
4848
use serde_json::Value;
4949
use std::fmt;
5050
use std::path::Path;
@@ -654,84 +654,6 @@ pub(crate) fn match_with_without(
654654
}
655655
}
656656

657-
/// Checks that the given string of JSON objects match the given set of
658-
/// expected JSON objects.
659-
///
660-
/// See [`crate::Execs::with_json`] for more details.
661-
pub(crate) fn match_json(expected: &str, actual: &str, cwd: Option<&Path>) -> Result<()> {
662-
let (exp_objs, act_objs) = collect_json_objects(expected, actual)?;
663-
if exp_objs.len() != act_objs.len() {
664-
bail!(
665-
"expected {} json lines, got {}, stdout:\n{}",
666-
exp_objs.len(),
667-
act_objs.len(),
668-
actual
669-
);
670-
}
671-
for (exp_obj, act_obj) in exp_objs.iter().zip(act_objs) {
672-
find_json_mismatch(exp_obj, &act_obj, cwd)?;
673-
}
674-
Ok(())
675-
}
676-
677-
/// Checks that the given string of JSON objects match the given set of
678-
/// expected JSON objects, ignoring their order.
679-
///
680-
/// See [`crate::Execs::with_json_contains_unordered`] for more details and
681-
/// cautions when using.
682-
pub(crate) fn match_json_contains_unordered(
683-
expected: &str,
684-
actual: &str,
685-
cwd: Option<&Path>,
686-
) -> Result<()> {
687-
let (exp_objs, mut act_objs) = collect_json_objects(expected, actual)?;
688-
for exp_obj in exp_objs {
689-
match act_objs
690-
.iter()
691-
.position(|act_obj| find_json_mismatch(&exp_obj, act_obj, cwd).is_ok())
692-
{
693-
Some(index) => act_objs.remove(index),
694-
None => {
695-
bail!(
696-
"Did not find expected JSON:\n\
697-
{}\n\
698-
Remaining available output:\n\
699-
{}\n",
700-
serde_json::to_string_pretty(&exp_obj).unwrap(),
701-
itertools::join(
702-
act_objs.iter().map(|o| serde_json::to_string(o).unwrap()),
703-
"\n"
704-
)
705-
);
706-
}
707-
};
708-
}
709-
Ok(())
710-
}
711-
712-
fn collect_json_objects(
713-
expected: &str,
714-
actual: &str,
715-
) -> Result<(Vec<serde_json::Value>, Vec<serde_json::Value>)> {
716-
let expected_objs: Vec<_> = expected
717-
.split("\n\n")
718-
.map(|expect| {
719-
expect
720-
.parse()
721-
.with_context(|| format!("failed to parse expected JSON object:\n{}", expect))
722-
})
723-
.collect::<Result<_>>()?;
724-
let actual_objs: Vec<_> = actual
725-
.lines()
726-
.filter(|line| line.starts_with('{'))
727-
.map(|line| {
728-
line.parse()
729-
.with_context(|| format!("failed to parse JSON object:\n{}", line))
730-
})
731-
.collect::<Result<_>>()?;
732-
Ok((expected_objs, actual_objs))
733-
}
734-
735657
/// Compares JSON object for approximate equality.
736658
/// You can use `[..]` wildcard in strings (useful for OS-dependent things such
737659
/// as paths). You can use a `"{...}"` string literal as a wildcard for

crates/cargo-test-support/src/lib.rs

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,6 @@ pub struct Execs {
655655
expect_stdout_unordered: Vec<String>,
656656
expect_stderr_unordered: Vec<String>,
657657
expect_stderr_with_without: Vec<(Vec<String>, Vec<String>)>,
658-
expect_json: Option<String>,
659-
expect_json_contains_unordered: Option<String>,
660658
stream_output: bool,
661659
assert: snapbox::Assert,
662660
}
@@ -824,56 +822,6 @@ impl Execs {
824822
self.expect_stderr_with_without.push((with, without));
825823
self
826824
}
827-
828-
/// Verifies the JSON output matches the given JSON.
829-
///
830-
/// This is typically used when testing cargo commands that emit JSON.
831-
/// Each separate JSON object should be separated by a blank line.
832-
/// Example:
833-
///
834-
/// ```rust,ignore
835-
/// assert_that(
836-
/// p.cargo("metadata"),
837-
/// execs().with_json(r#"
838-
/// {"example": "abc"}
839-
///
840-
/// {"example": "def"}
841-
/// "#)
842-
/// );
843-
/// ```
844-
///
845-
/// - Objects should match in the order given.
846-
/// - The order of arrays is ignored.
847-
/// - Strings support patterns described in [`compare`].
848-
/// - Use `"{...}"` to match any object.
849-
#[deprecated(
850-
note = "replaced with `Execs::with_stdout_data(expected.is_json().against_jsonlines())`"
851-
)]
852-
pub fn with_json(&mut self, expected: &str) -> &mut Self {
853-
self.expect_json = Some(expected.to_string());
854-
self
855-
}
856-
857-
/// Verifies JSON output contains the given objects (in any order) somewhere
858-
/// in its output.
859-
///
860-
/// CAUTION: Be very careful when using this. Make sure every object is
861-
/// unique (not a subset of one another). Also avoid using objects that
862-
/// could possibly match multiple output lines unless you're very sure of
863-
/// what you are doing.
864-
///
865-
/// See `with_json` for more detail.
866-
#[deprecated]
867-
pub fn with_json_contains_unordered(&mut self, expected: &str) -> &mut Self {
868-
match &mut self.expect_json_contains_unordered {
869-
None => self.expect_json_contains_unordered = Some(expected.to_string()),
870-
Some(e) => {
871-
e.push_str("\n\n");
872-
e.push_str(expected);
873-
}
874-
}
875-
self
876-
}
877825
}
878826

879827
/// # Configure the process
@@ -1050,8 +998,6 @@ impl Execs {
1050998
&& self.expect_stdout_unordered.is_empty()
1051999
&& self.expect_stderr_unordered.is_empty()
10521000
&& self.expect_stderr_with_without.is_empty()
1053-
&& self.expect_json.is_none()
1054-
&& self.expect_json_contains_unordered.is_none()
10551001
{
10561002
panic!(
10571003
"`with_status()` is used, but no output is checked.\n\
@@ -1175,14 +1121,6 @@ impl Execs {
11751121
for (with, without) in self.expect_stderr_with_without.iter() {
11761122
compare::match_with_without(stderr, with, without, cwd)?;
11771123
}
1178-
1179-
if let Some(ref expect_json) = self.expect_json {
1180-
compare::match_json(expect_json, stdout, cwd)?;
1181-
}
1182-
1183-
if let Some(ref expected) = self.expect_json_contains_unordered {
1184-
compare::match_json_contains_unordered(expected, stdout, cwd)?;
1185-
}
11861124
Ok(())
11871125
}
11881126
}
@@ -1212,8 +1150,6 @@ pub fn execs() -> Execs {
12121150
expect_stdout_unordered: Vec::new(),
12131151
expect_stderr_unordered: Vec::new(),
12141152
expect_stderr_with_without: Vec::new(),
1215-
expect_json: None,
1216-
expect_json_contains_unordered: None,
12171153
stream_output: false,
12181154
assert: compare::assert_e2e(),
12191155
}

0 commit comments

Comments
 (0)