Skip to content

Commit 5e7847b

Browse files
committed
fix: assert contract outputs individually
1 parent a4d0c1c commit 5e7847b

File tree

1 file changed

+150
-35
lines changed
  • crates/forge/tests/cli/test_cmd/invariant

1 file changed

+150
-35
lines changed

crates/forge/tests/cli/test_cmd/invariant/target.rs

Lines changed: 150 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -537,72 +537,118 @@ contract TargetArtifacts is Test {
537537
"#,
538538
);
539539

540-
assert_invariant(cmd.args(["test", "-j1"])).failure().stdout_eq(str![[r#"
540+
// Test ExcludeContracts
541+
assert_invariant(cmd.forge_fuse().args(["test", "--mc", "ExcludeContracts"]))
542+
.success()
543+
.stdout_eq(str![[r#"
541544
...
542-
Ran 1 test for test/ExcludeArtifacts.t.sol:ExcludeArtifacts
543-
[PASS] invariantShouldPass() ([RUNS])
544-
545-
[STATS]
546-
547-
Suite result: ok. 1 passed; 0 failed; 0 skipped; [ELAPSED]
548-
549-
Ran 1 test for test/ExcludeSenders.t.sol:ExcludeSenders
545+
Ran 1 test for test/ExcludeContracts.t.sol:ExcludeContracts
550546
[PASS] invariantTrueWorld() ([RUNS])
551547
552548
[STATS]
553549
554550
Suite result: ok. 1 passed; 0 failed; 0 skipped; [ELAPSED]
555551
556-
Ran 1 test for test/TargetArtifactSelectors.t.sol:TargetArtifactSelectors
557-
[PASS] invariantShouldPass() ([RUNS])
558-
559-
[STATS]
552+
Ran 1 test suite [ELAPSED]: 1 tests passed, 0 failed, 0 skipped (1 total tests)
560553
561-
Suite result: ok. 1 passed; 0 failed; 0 skipped; [ELAPSED]
554+
"#]]);
562555

556+
// Test ExcludeSelectors
557+
assert_invariant(cmd.forge_fuse().args(["test", "--mc", "ExcludeSelectors"]))
558+
.success()
559+
.stdout_eq(str![[r#"
560+
...
563561
Ran 1 test for test/ExcludeSelectors.t.sol:ExcludeSelectors
564562
[PASS] invariantFalseWorld() ([RUNS])
565563
566564
[STATS]
567565
568566
Suite result: ok. 1 passed; 0 failed; 0 skipped; [ELAPSED]
569567
570-
Ran 2 tests for test/TargetArtifacts.t.sol:TargetArtifacts
571-
[FAIL: false world]
572-
[SEQUENCE]
573-
invariantShouldFail() ([RUNS])
568+
Ran 1 test suite [ELAPSED]: 1 tests passed, 0 failed, 0 skipped (1 total tests)
574569
575-
[STATS]
570+
"#]]);
576571

577-
[PASS] invariantShouldPass() ([RUNS])
572+
// Test ExcludeSenders
573+
assert_invariant(cmd.forge_fuse().args(["test", "--mc", "ExcludeSenders"]))
574+
.success()
575+
.stdout_eq(str![[r#"
576+
...
577+
Ran 1 test for test/ExcludeSenders.t.sol:ExcludeSenders
578+
[PASS] invariantTrueWorld() ([RUNS])
578579
579580
[STATS]
580581
581-
Suite result: FAILED. 1 passed; 1 failed; 0 skipped; [ELAPSED]
582+
Suite result: ok. 1 passed; 0 failed; 0 skipped; [ELAPSED]
583+
584+
Ran 1 test suite [ELAPSED]: 1 tests passed, 0 failed, 0 skipped (1 total tests)
585+
586+
"#]]);
582587

588+
// Test TargetContracts
589+
assert_invariant(cmd.forge_fuse().args(["test", "--mc", "TargetContracts"]))
590+
.success()
591+
.stdout_eq(str![[r#"
592+
...
583593
Ran 1 test for test/TargetContracts.t.sol:TargetContracts
584594
[PASS] invariantTrueWorld() ([RUNS])
585595
586596
[STATS]
587597
588598
Suite result: ok. 1 passed; 0 failed; 0 skipped; [ELAPSED]
589599
590-
Ran 1 test for test/TargetArtifactSelectors2.t.sol:TargetArtifactSelectors2
591-
[FAIL: it's false]
600+
Ran 1 test suite [ELAPSED]: 1 tests passed, 0 failed, 0 skipped (1 total tests)
601+
602+
"#]]);
603+
604+
// Test TargetInterfaces (should fail)
605+
assert_invariant(cmd.forge_fuse().args(["test", "--mc", "TargetWorldInterfaces"]))
606+
.failure()
607+
.stdout_eq(str![[r#"
608+
...
609+
Ran 1 test for test/TargetInterfaces.t.sol:TargetWorldInterfaces
610+
[FAIL: false world]
592611
[SEQUENCE]
593-
invariantShouldFail() ([RUNS])
612+
invariantTrueWorld() ([RUNS])
594613
595614
[STATS]
596615
597616
Suite result: FAILED. 0 passed; 1 failed; 0 skipped; [ELAPSED]
598617
618+
Ran 1 test suite [ELAPSED]: 0 tests passed, 1 failed, 0 skipped (1 total tests)
619+
620+
Failing tests:
621+
Encountered 1 failing test in test/TargetInterfaces.t.sol:TargetWorldInterfaces
622+
[FAIL: false world]
623+
[SEQUENCE]
624+
invariantTrueWorld() ([RUNS])
625+
626+
Encountered a total of 1 failing tests, 0 tests succeeded
627+
628+
Tip: Run `forge test --rerun` to retry only the 1 failed test
629+
630+
"#]]);
631+
632+
// Test TargetSelectors
633+
assert_invariant(cmd.forge_fuse().args(["test", "--mc", "TargetSelectors"]))
634+
.success()
635+
.stdout_eq(str![[r#"
636+
...
599637
Ran 1 test for test/TargetSelectors.t.sol:TargetSelectors
600638
[PASS] invariantTrueWorld() ([RUNS])
601639
602640
[STATS]
603641
604642
Suite result: ok. 1 passed; 0 failed; 0 skipped; [ELAPSED]
605643
644+
Ran 1 test suite [ELAPSED]: 1 tests passed, 0 failed, 0 skipped (1 total tests)
645+
646+
"#]]);
647+
648+
// Test TargetSenders (should fail)
649+
assert_invariant(cmd.forge_fuse().args(["test", "--mc", "TargetSenders"])).failure().stdout_eq(
650+
str![[r#"
651+
...
606652
Ran 1 test for test/TargetSenders.t.sol:TargetSenders
607653
[FAIL: false world]
608654
[SEQUENCE]
@@ -612,41 +658,110 @@ Ran 1 test for test/TargetSenders.t.sol:TargetSenders
612658
613659
Suite result: FAILED. 0 passed; 1 failed; 0 skipped; [ELAPSED]
614660
615-
Ran 1 test for test/TargetInterfaces.t.sol:TargetWorldInterfaces
661+
Ran 1 test suite [ELAPSED]: 0 tests passed, 1 failed, 0 skipped (1 total tests)
662+
663+
Failing tests:
664+
Encountered 1 failing test in test/TargetSenders.t.sol:TargetSenders
616665
[FAIL: false world]
617666
[SEQUENCE]
618667
invariantTrueWorld() ([RUNS])
619668
669+
Encountered a total of 1 failing tests, 0 tests succeeded
670+
671+
Tip: Run `forge test --rerun` to retry only the 1 failed test
672+
673+
"#]],
674+
);
675+
676+
// Test ExcludeArtifacts
677+
assert_invariant(cmd.forge_fuse().args(["test", "--mc", "ExcludeArtifacts"]))
678+
.success()
679+
.stdout_eq(str![[r#"
680+
...
681+
Ran 1 test for test/ExcludeArtifacts.t.sol:ExcludeArtifacts
682+
[PASS] invariantShouldPass() ([RUNS])
683+
684+
[STATS]
685+
686+
Suite result: ok. 1 passed; 0 failed; 0 skipped; [ELAPSED]
687+
688+
Ran 1 test suite [ELAPSED]: 1 tests passed, 0 failed, 0 skipped (1 total tests)
689+
690+
"#]]);
691+
692+
// Test TargetArtifactSelectors2 (should fail)
693+
assert_invariant(cmd.forge_fuse().args(["test", "--mc", "TargetArtifactSelectors2"]))
694+
.failure()
695+
.stdout_eq(str![[r#"
696+
...
697+
Ran 1 test for test/TargetArtifactSelectors2.t.sol:TargetArtifactSelectors2
698+
[FAIL: it's false]
699+
[SEQUENCE]
700+
invariantShouldFail() ([RUNS])
701+
620702
[STATS]
621703
622704
Suite result: FAILED. 0 passed; 1 failed; 0 skipped; [ELAPSED]
623705
624-
Ran 11 test suites [ELAPSED]: 8 tests passed, 4 failed, 0 skipped (12 total tests)
706+
Ran 1 test suite [ELAPSED]: 0 tests passed, 1 failed, 0 skipped (1 total tests)
625707
626708
Failing tests:
627709
Encountered 1 failing test in test/TargetArtifactSelectors2.t.sol:TargetArtifactSelectors2
628710
[FAIL: it's false]
629711
[SEQUENCE]
630712
invariantShouldFail() ([RUNS])
631713
632-
Encountered 1 failing test in test/TargetArtifacts.t.sol:TargetArtifacts
714+
Encountered a total of 1 failing tests, 0 tests succeeded
715+
716+
Tip: Run `forge test --rerun` to retry only the 1 failed test
717+
718+
"#]]);
719+
720+
// Test TargetArtifactSelectors
721+
assert_invariant(cmd.forge_fuse().args(["test", "--mc", "^TargetArtifactSelectors$"]))
722+
.success()
723+
.stdout_eq(str![[r#"
724+
...
725+
Ran 1 test for test/TargetArtifactSelectors.t.sol:TargetArtifactSelectors
726+
[PASS] invariantShouldPass() ([RUNS])
727+
728+
[STATS]
729+
730+
Suite result: ok. 1 passed; 0 failed; 0 skipped; [ELAPSED]
731+
732+
Ran 1 test suite [ELAPSED]: 1 tests passed, 0 failed, 0 skipped (1 total tests)
733+
734+
"#]]);
735+
736+
// Test TargetArtifacts
737+
assert_invariant(cmd.forge_fuse().args(["test", "--mc", "^TargetArtifacts$"]))
738+
.failure()
739+
.stdout_eq(str![[r#"
740+
...
741+
Ran 2 tests for test/TargetArtifacts.t.sol:TargetArtifacts
633742
[FAIL: false world]
634743
[SEQUENCE]
635744
invariantShouldFail() ([RUNS])
636745
637-
Encountered 1 failing test in test/TargetInterfaces.t.sol:TargetWorldInterfaces
638-
[FAIL: false world]
639-
[SEQUENCE]
640-
invariantTrueWorld() ([RUNS])
746+
[STATS]
641747
642-
Encountered 1 failing test in test/TargetSenders.t.sol:TargetSenders
748+
[PASS] invariantShouldPass() ([RUNS])
749+
750+
[STATS]
751+
752+
Suite result: FAILED. 1 passed; 1 failed; 0 skipped; [ELAPSED]
753+
754+
Ran 1 test suite [ELAPSED]: 1 tests passed, 1 failed, 0 skipped (2 total tests)
755+
756+
Failing tests:
757+
Encountered 1 failing test in test/TargetArtifacts.t.sol:TargetArtifacts
643758
[FAIL: false world]
644759
[SEQUENCE]
645-
invariantTrueWorld() ([RUNS])
760+
invariantShouldFail() ([RUNS])
646761
647-
Encountered a total of 4 failing tests, 8 tests succeeded
762+
Encountered a total of 1 failing tests, 1 tests succeeded
648763
649-
Tip: Run `forge test --rerun` to retry only the 4 failed tests
764+
Tip: Run `forge test --rerun` to retry only the 1 failed test
650765
651766
"#]]);
652767
});

0 commit comments

Comments
 (0)