@@ -667,6 +667,57 @@ impl Execs {
667
667
/// Verifies that stdout is equal to the given lines.
668
668
///
669
669
/// See [`compare::assert_e2e`] for assertion details.
670
+ ///
671
+ /// <div class="warning">
672
+ ///
673
+ /// Prefer passing in [`str!`] for `expected` to get snapshot updating.
674
+ ///
675
+ /// If `format!` is needed for content that changes from run to run that you don't care about,
676
+ /// consider whether you could have [`compare::assert_e2e`] redact the content.
677
+ /// If nothing else, a wildcard (`[..]`, `...`) may be useful.
678
+ ///
679
+ /// However, `""` may be preferred for intentionally empty output so people don't accidentally
680
+ /// bless a change.
681
+ ///
682
+ /// </div>
683
+ ///
684
+ /// # Examples
685
+ ///
686
+ /// ```no_run
687
+ /// use cargo_test_support::prelude::*;
688
+ /// use cargo_test_support::str;
689
+ /// use cargo_test_support::execs;
690
+ ///
691
+ /// execs().with_stdout_data(str![r#"
692
+ /// Hello world!
693
+ /// "#]);
694
+ /// ```
695
+ ///
696
+ /// Non-deterministic compiler output
697
+ /// ```no_run
698
+ /// use cargo_test_support::prelude::*;
699
+ /// use cargo_test_support::str;
700
+ /// use cargo_test_support::execs;
701
+ ///
702
+ /// execs().with_stdout_data(str![r#"
703
+ /// [COMPILING] foo
704
+ /// [COMPILING] bar
705
+ /// "#].unordered());
706
+ /// ```
707
+ ///
708
+ /// jsonlines
709
+ /// ```no_run
710
+ /// use cargo_test_support::prelude::*;
711
+ /// use cargo_test_support::str;
712
+ /// use cargo_test_support::execs;
713
+ ///
714
+ /// execs().with_stdout_data(str![r#"
715
+ /// [
716
+ /// {},
717
+ /// {}
718
+ /// ]
719
+ /// "#].is_json().against_jsonlines());
720
+ /// ```
670
721
pub fn with_stdout_data ( & mut self , expected : impl snapbox:: IntoData ) -> & mut Self {
671
722
self . expect_stdout_data = Some ( expected. into_data ( ) ) ;
672
723
self
@@ -675,6 +726,57 @@ impl Execs {
675
726
/// Verifies that stderr is equal to the given lines.
676
727
///
677
728
/// See [`compare::assert_e2e`] for assertion details.
729
+ ///
730
+ /// <div class="warning">
731
+ ///
732
+ /// Prefer passing in [`str!`] for `expected` to get snapshot updating.
733
+ ///
734
+ /// If `format!` is needed for content that changes from run to run that you don't care about,
735
+ /// consider whether you could have [`compare::assert_e2e`] redact the content.
736
+ /// If nothing else, a wildcard (`[..]`, `...`) may be useful.
737
+ ///
738
+ /// However, `""` may be preferred for intentionally empty output so people don't accidentally
739
+ /// bless a change.
740
+ ///
741
+ /// </div>
742
+ ///
743
+ /// # Examples
744
+ ///
745
+ /// ```no_run
746
+ /// use cargo_test_support::prelude::*;
747
+ /// use cargo_test_support::str;
748
+ /// use cargo_test_support::execs;
749
+ ///
750
+ /// execs().with_stderr_data(str![r#"
751
+ /// Hello world!
752
+ /// "#]);
753
+ /// ```
754
+ ///
755
+ /// Non-deterministic compiler output
756
+ /// ```no_run
757
+ /// use cargo_test_support::prelude::*;
758
+ /// use cargo_test_support::str;
759
+ /// use cargo_test_support::execs;
760
+ ///
761
+ /// execs().with_stderr_data(str![r#"
762
+ /// [COMPILING] foo
763
+ /// [COMPILING] bar
764
+ /// "#].unordered());
765
+ /// ```
766
+ ///
767
+ /// jsonlines
768
+ /// ```no_run
769
+ /// use cargo_test_support::prelude::*;
770
+ /// use cargo_test_support::str;
771
+ /// use cargo_test_support::execs;
772
+ ///
773
+ /// execs().with_stderr_data(str![r#"
774
+ /// [
775
+ /// {},
776
+ /// {}
777
+ /// ]
778
+ /// "#].is_json().against_jsonlines());
779
+ /// ```
678
780
pub fn with_stderr_data ( & mut self , expected : impl snapbox:: IntoData ) -> & mut Self {
679
781
self . expect_stderr_data = Some ( expected. into_data ( ) ) ;
680
782
self
@@ -706,6 +808,14 @@ impl Execs {
706
808
/// its output.
707
809
///
708
810
/// See [`compare`] for supported patterns.
811
+ ///
812
+ /// <div class="warning">
813
+ ///
814
+ /// Prefer [`Execs::with_stdout_data`] where possible.
815
+ /// - `expected` cannot be snapshotted
816
+ /// - `expected` can end up being ambiguous, causing the assertion to succeed when it should fail
817
+ ///
818
+ /// </div>
709
819
#[ deprecated( note = "replaced with `Execs::with_stdout_data(expected)`" ) ]
710
820
pub fn with_stdout_contains < S : ToString > ( & mut self , expected : S ) -> & mut Self {
711
821
self . expect_stdout_contains . push ( expected. to_string ( ) ) ;
@@ -716,6 +826,14 @@ impl Execs {
716
826
/// its output.
717
827
///
718
828
/// See [`compare`] for supported patterns.
829
+ ///
830
+ /// <div class="warning">
831
+ ///
832
+ /// Prefer [`Execs::with_stderr_data`] where possible.
833
+ /// - `expected` cannot be snapshotted
834
+ /// - `expected` can end up being ambiguous, causing the assertion to succeed when it should fail
835
+ ///
836
+ /// </div>
719
837
#[ deprecated( note = "replaced with `Execs::with_stderr_data(expected)`" ) ]
720
838
pub fn with_stderr_contains < S : ToString > ( & mut self , expected : S ) -> & mut Self {
721
839
self . expect_stderr_contains . push ( expected. to_string ( ) ) ;
@@ -727,6 +845,18 @@ impl Execs {
727
845
/// See [`compare`] for supported patterns.
728
846
///
729
847
/// See note on [`Self::with_stderr_does_not_contain`].
848
+ ///
849
+ /// <div class="warning">
850
+ ///
851
+ /// Prefer [`Execs::with_stdout_data`] where possible.
852
+ /// - `expected` cannot be snapshotted
853
+ /// - The absence of `expected` can either mean success or that the string being looked for
854
+ /// changed.
855
+ ///
856
+ /// To mitigate this, consider matching this up with
857
+ /// [`Execs::with_stdout_contains`].
858
+ ///
859
+ /// </div>
730
860
#[ deprecated]
731
861
pub fn with_stdout_does_not_contain < S : ToString > ( & mut self , expected : S ) -> & mut Self {
732
862
self . expect_stdout_not_contains . push ( expected. to_string ( ) ) ;
@@ -737,11 +867,18 @@ impl Execs {
737
867
///
738
868
/// See [`compare`] for supported patterns.
739
869
///
740
- /// Care should be taken when using this method because there is a
741
- /// limitless number of possible things that *won't* appear. A typo means
742
- /// your test will pass without verifying the correct behavior. If
743
- /// possible, write the test first so that it fails, and then implement
744
- /// your fix/feature to make it pass.
870
+ /// <div class="warning">
871
+ ///
872
+ /// Prefer [`Execs::with_stdout_data`] where possible.
873
+ /// - `expected` cannot be snapshotted
874
+ /// - The absence of `expected` can either mean success or that the string being looked for
875
+ /// changed.
876
+ ///
877
+ /// To mitigate this, consider either matching this up with
878
+ /// [`Execs::with_stdout_contains`] or replace it
879
+ /// with [`Execs::with_stderr_line_without`].
880
+ ///
881
+ /// </div>
745
882
#[ deprecated]
746
883
pub fn with_stderr_does_not_contain < S : ToString > ( & mut self , expected : S ) -> & mut Self {
747
884
self . expect_stderr_not_contains . push ( expected. to_string ( ) ) ;
@@ -751,7 +888,18 @@ impl Execs {
751
888
/// Verify that a particular line appears in stderr with and without the
752
889
/// given substrings. Exactly one line must match.
753
890
///
754
- /// The substrings are matched as `contains`. Example:
891
+ /// The substrings are matched as `contains`.
892
+ ///
893
+ /// <div class="warning">
894
+ ///
895
+ /// Prefer [`Execs::with_stdout_data`] where possible.
896
+ /// - `with` cannot be snapshotted
897
+ /// - The absence of `without`` can either mean success or that the string being looked for
898
+ /// changed.
899
+ ///
900
+ /// </div>
901
+ ///
902
+ /// # Example
755
903
///
756
904
/// ```no_run
757
905
/// use cargo_test_support::execs;
@@ -768,8 +916,6 @@ impl Execs {
768
916
/// This will check that a build line includes `-C opt-level=3` but does
769
917
/// not contain `-C debuginfo` or `-C incremental`.
770
918
///
771
- /// Be careful writing the `without` fragments, see note in
772
- /// `with_stderr_does_not_contain`.
773
919
#[ deprecated]
774
920
pub fn with_stderr_line_without < S : ToString > (
775
921
& mut self ,
0 commit comments