evilution 0.20.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.beads/.gitignore +4 -0
  3. data/.beads/.migration-hint-ts +1 -1
  4. data/.beads/interactions.jsonl +12 -0
  5. data/.beads/issues.jsonl +22 -19
  6. data/CHANGELOG.md +35 -0
  7. data/README.md +17 -11
  8. data/comparison_results/baseline_2026-04-09.md +35 -0
  9. data/comparison_results/operator_classification.md +79 -0
  10. data/comparison_results/operator_prioritization.md +68 -0
  11. data/docs/mutation_density_benchmark.md +91 -0
  12. data/lib/evilution/ast/parser.rb +2 -1
  13. data/lib/evilution/baseline.rb +14 -11
  14. data/lib/evilution/cli.rb +13 -3
  15. data/lib/evilution/config.rb +27 -5
  16. data/lib/evilution/disable_comment.rb +2 -1
  17. data/lib/evilution/integration/base.rb +98 -1
  18. data/lib/evilution/integration/minitest.rb +145 -0
  19. data/lib/evilution/integration/minitest_crash_detector.rb +55 -0
  20. data/lib/evilution/integration/rspec.rb +33 -92
  21. data/lib/evilution/isolation/fork.rb +3 -6
  22. data/lib/evilution/mcp/mutate_tool.rb +6 -6
  23. data/lib/evilution/mutator/base.rb +5 -1
  24. data/lib/evilution/mutator/operator/bitwise_complement.rb +1 -1
  25. data/lib/evilution/mutator/operator/block_pass_removal.rb +30 -0
  26. data/lib/evilution/mutator/operator/ensure_removal.rb +1 -1
  27. data/lib/evilution/mutator/operator/index_to_at.rb +30 -0
  28. data/lib/evilution/mutator/operator/index_to_dig.rb +3 -3
  29. data/lib/evilution/mutator/operator/index_to_fetch.rb +2 -2
  30. data/lib/evilution/mutator/operator/keyword_argument.rb +1 -1
  31. data/lib/evilution/mutator/operator/regex_simplification.rb +169 -0
  32. data/lib/evilution/mutator/operator/rescue_body_replacement.rb +1 -1
  33. data/lib/evilution/mutator/operator/rescue_removal.rb +1 -1
  34. data/lib/evilution/mutator/operator/string_literal.rb +18 -0
  35. data/lib/evilution/mutator/registry.rb +12 -2
  36. data/lib/evilution/reporter/html.rb +2 -2
  37. data/lib/evilution/reporter/json.rb +2 -2
  38. data/lib/evilution/reporter/suggestion.rb +659 -2
  39. data/lib/evilution/runner.rb +59 -13
  40. data/lib/evilution/spec_resolver.rb +24 -16
  41. data/lib/evilution/temp_dir_tracker.rb +39 -0
  42. data/lib/evilution/version.rb +1 -1
  43. data/lib/evilution.rb +4 -0
  44. data/scripts/benchmark_density +261 -0
  45. data/scripts/benchmark_density.yml +19 -0
  46. data/scripts/compare_mutations +404 -0
  47. data/scripts/compare_mutations.yml +24 -0
  48. data/scripts/mutant_json_adapter +224 -0
  49. metadata +17 -2
@@ -658,10 +658,662 @@ class Evilution::Reporter::Suggestion
658
658
  }
659
659
  }.freeze
660
660
 
661
+ MINITEST_CONCRETE_TEMPLATES = {
662
+ "comparison_replacement" => lambda { |mutation|
663
+ method_name = parse_method_name(mutation.subject.name)
664
+ safe_name = sanitize_method_name(method_name)
665
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
666
+ <<~MINITEST.strip
667
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
668
+ # #{mutation.file_path}:#{mutation.line}
669
+ def test_returns_correct_result_at_comparison_boundary_in_#{safe_name}
670
+ # Test with values where the original operator and mutated operator
671
+ # produce different results (e.g., equal values for > vs >=)
672
+ result = subject.#{method_name}(boundary_value)
673
+ assert_equal expected, result
674
+ end
675
+ MINITEST
676
+ },
677
+ "arithmetic_replacement" => lambda { |mutation|
678
+ method_name = parse_method_name(mutation.subject.name)
679
+ safe_name = sanitize_method_name(method_name)
680
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
681
+ <<~MINITEST.strip
682
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
683
+ # #{mutation.file_path}:#{mutation.line}
684
+ def test_computes_correct_arithmetic_result_in_#{safe_name}
685
+ # Assert the exact numeric result, not just truthiness or sign
686
+ result = subject.#{method_name}(input_value)
687
+ assert_equal expected, result
688
+ end
689
+ MINITEST
690
+ },
691
+ "boolean_operator_replacement" => lambda { |mutation|
692
+ method_name = parse_method_name(mutation.subject.name)
693
+ safe_name = sanitize_method_name(method_name)
694
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
695
+ <<~MINITEST.strip
696
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
697
+ # #{mutation.file_path}:#{mutation.line}
698
+ def test_returns_correct_result_when_one_condition_differs_in_#{safe_name}
699
+ # Use inputs where only one operand is truthy to distinguish && from ||
700
+ result = subject.#{method_name}(input_value)
701
+ assert_equal expected, result
702
+ end
703
+ MINITEST
704
+ },
705
+ "boolean_literal_replacement" => lambda { |mutation|
706
+ method_name = parse_method_name(mutation.subject.name)
707
+ safe_name = sanitize_method_name(method_name)
708
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
709
+ <<~MINITEST.strip
710
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
711
+ # #{mutation.file_path}:#{mutation.line}
712
+ def test_returns_expected_boolean_value_from_#{safe_name}
713
+ # Assert the exact true/false/nil value, not just truthiness
714
+ result = subject.#{method_name}(input_value)
715
+ assert_equal expected, result
716
+ end
717
+ MINITEST
718
+ },
719
+ "negation_insertion" => lambda { |mutation|
720
+ method_name = parse_method_name(mutation.subject.name)
721
+ safe_name = sanitize_method_name(method_name)
722
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
723
+ <<~MINITEST.strip
724
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
725
+ # #{mutation.file_path}:#{mutation.line}
726
+ def test_returns_correct_boolean_from_predicate_in_#{safe_name}
727
+ # Assert the exact true/false result, not just truthiness
728
+ result = subject.#{method_name}(input_value)
729
+ assert_includes [true, false], result
730
+ end
731
+ MINITEST
732
+ },
733
+ "integer_literal" => lambda { |mutation|
734
+ method_name = parse_method_name(mutation.subject.name)
735
+ safe_name = sanitize_method_name(method_name)
736
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
737
+ <<~MINITEST.strip
738
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
739
+ # #{mutation.file_path}:#{mutation.line}
740
+ def test_returns_exact_integer_value_from_#{safe_name}
741
+ # Assert the exact numeric value, not just > 0 or truthy
742
+ result = subject.#{method_name}(input_value)
743
+ assert_equal expected, result
744
+ end
745
+ MINITEST
746
+ },
747
+ "float_literal" => lambda { |mutation|
748
+ method_name = parse_method_name(mutation.subject.name)
749
+ safe_name = sanitize_method_name(method_name)
750
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
751
+ <<~MINITEST.strip
752
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
753
+ # #{mutation.file_path}:#{mutation.line}
754
+ def test_returns_exact_float_value_from_#{safe_name}
755
+ # Assert the exact floating-point result
756
+ result = subject.#{method_name}(input_value)
757
+ assert_in_delta expected, result
758
+ end
759
+ MINITEST
760
+ },
761
+ "string_literal" => lambda { |mutation|
762
+ method_name = parse_method_name(mutation.subject.name)
763
+ safe_name = sanitize_method_name(method_name)
764
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
765
+ <<~MINITEST.strip
766
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
767
+ # #{mutation.file_path}:#{mutation.line}
768
+ def test_returns_exact_string_content_from_#{safe_name}
769
+ # Assert the exact string value, not just presence or non-empty
770
+ result = subject.#{method_name}(input_value)
771
+ assert_equal expected, result
772
+ end
773
+ MINITEST
774
+ },
775
+ "symbol_literal" => lambda { |mutation|
776
+ method_name = parse_method_name(mutation.subject.name)
777
+ safe_name = sanitize_method_name(method_name)
778
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
779
+ <<~MINITEST.strip
780
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
781
+ # #{mutation.file_path}:#{mutation.line}
782
+ def test_returns_exact_symbol_from_#{safe_name}
783
+ # Assert the exact symbol value, not just that it is a Symbol
784
+ result = subject.#{method_name}(input_value)
785
+ assert_equal expected, result
786
+ end
787
+ MINITEST
788
+ },
789
+ "array_literal" => lambda { |mutation|
790
+ method_name = parse_method_name(mutation.subject.name)
791
+ safe_name = sanitize_method_name(method_name)
792
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
793
+ <<~MINITEST.strip
794
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
795
+ # #{mutation.file_path}:#{mutation.line}
796
+ def test_returns_expected_array_contents_from_#{safe_name}
797
+ # Assert the exact array elements, not just non-empty or truthy
798
+ result = subject.#{method_name}(input_value)
799
+ assert_equal expected, result
800
+ end
801
+ MINITEST
802
+ },
803
+ "hash_literal" => lambda { |mutation|
804
+ method_name = parse_method_name(mutation.subject.name)
805
+ safe_name = sanitize_method_name(method_name)
806
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
807
+ <<~MINITEST.strip
808
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
809
+ # #{mutation.file_path}:#{mutation.line}
810
+ def test_returns_expected_hash_contents_from_#{safe_name}
811
+ # Assert the exact keys and values, not just non-empty or truthy
812
+ result = subject.#{method_name}(input_value)
813
+ assert_equal expected, result
814
+ end
815
+ MINITEST
816
+ },
817
+ "collection_replacement" => lambda { |mutation|
818
+ method_name = parse_method_name(mutation.subject.name)
819
+ safe_name = sanitize_method_name(method_name)
820
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
821
+ <<~MINITEST.strip
822
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
823
+ # #{mutation.file_path}:#{mutation.line}
824
+ def test_uses_return_value_of_collection_operation_in_#{safe_name}
825
+ # Assert the return value of the collection method, not just side effects
826
+ result = subject.#{method_name}(input_value)
827
+ assert_equal expected, result
828
+ end
829
+ MINITEST
830
+ },
831
+ "conditional_negation" => lambda { |mutation|
832
+ method_name = parse_method_name(mutation.subject.name)
833
+ safe_name = sanitize_method_name(method_name)
834
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
835
+ <<~MINITEST.strip
836
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
837
+ # #{mutation.file_path}:#{mutation.line}
838
+ def test_exercises_both_branches_of_conditional_in_#{safe_name}
839
+ # Test with inputs that make the condition true AND false
840
+ result = subject.#{method_name}(input_value)
841
+ assert_equal expected, result
842
+ end
843
+ MINITEST
844
+ },
845
+ "conditional_branch" => lambda { |mutation|
846
+ method_name = parse_method_name(mutation.subject.name)
847
+ safe_name = sanitize_method_name(method_name)
848
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
849
+ <<~MINITEST.strip
850
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
851
+ # #{mutation.file_path}:#{mutation.line}
852
+ def test_exercises_removed_branch_of_conditional_in_#{safe_name}
853
+ # Test with inputs that trigger the branch removed by this mutation
854
+ result = subject.#{method_name}(input_value)
855
+ assert_equal expected, result
856
+ end
857
+ MINITEST
858
+ },
859
+ "statement_deletion" => lambda { |mutation|
860
+ method_name = parse_method_name(mutation.subject.name)
861
+ safe_name = sanitize_method_name(method_name)
862
+ original_line, _mutated_line = extract_diff_lines(mutation.diff)
863
+ <<~MINITEST.strip
864
+ # Mutation: deleted `#{original_line}` in #{mutation.subject.name}
865
+ # #{mutation.file_path}:#{mutation.line}
866
+ def test_depends_on_side_effect_of_deleted_statement_in_#{safe_name}
867
+ # Assert a side effect or return value that changes when this statement is removed
868
+ subject.#{method_name}(input_value)
869
+ assert_equal expected, observable_side_effect
870
+ end
871
+ MINITEST
872
+ },
873
+ "method_body_replacement" => lambda { |mutation|
874
+ method_name = parse_method_name(mutation.subject.name)
875
+ safe_name = sanitize_method_name(method_name)
876
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
877
+ <<~MINITEST.strip
878
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
879
+ # #{mutation.file_path}:#{mutation.line}
880
+ def test_verifies_return_value_or_side_effects_of_#{safe_name}
881
+ # Assert the method produces a meaningful result, not just nil
882
+ result = subject.#{method_name}(input_value)
883
+ assert_equal expected, result
884
+ end
885
+ MINITEST
886
+ },
887
+ "return_value_removal" => lambda { |mutation|
888
+ method_name = parse_method_name(mutation.subject.name)
889
+ safe_name = sanitize_method_name(method_name)
890
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
891
+ <<~MINITEST.strip
892
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
893
+ # #{mutation.file_path}:#{mutation.line}
894
+ def test_uses_return_value_of_#{safe_name}
895
+ # Assert the caller depends on the return value, not just side effects
896
+ result = subject.#{method_name}(input_value)
897
+ assert_equal expected, result
898
+ end
899
+ MINITEST
900
+ },
901
+ "method_call_removal" => lambda { |mutation|
902
+ method_name = parse_method_name(mutation.subject.name)
903
+ safe_name = sanitize_method_name(method_name)
904
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
905
+ <<~MINITEST.strip
906
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
907
+ # #{mutation.file_path}:#{mutation.line}
908
+ def test_depends_on_return_value_or_side_effect_of_call_in_#{safe_name}
909
+ # Assert the method call's effect is observable
910
+ result = subject.#{method_name}(input_value)
911
+ assert_equal expected, result
912
+ end
913
+ MINITEST
914
+ },
915
+ "compound_assignment" => lambda { |mutation|
916
+ method_name = parse_method_name(mutation.subject.name)
917
+ safe_name = sanitize_method_name(method_name)
918
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
919
+ <<~MINITEST.strip
920
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
921
+ # #{mutation.file_path}:#{mutation.line}
922
+ def test_verifies_compound_assignment_side_effect_in_#{safe_name}
923
+ # Assert the accumulated value after the compound assignment
924
+ # The mutation changes the operator, so the final value will differ
925
+ subject.#{method_name}(input_value)
926
+ assert_equal expected, observable_side_effect
927
+ end
928
+ MINITEST
929
+ },
930
+ "nil_replacement" => lambda { |mutation|
931
+ method_name = parse_method_name(mutation.subject.name)
932
+ safe_name = sanitize_method_name(method_name)
933
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
934
+ <<~MINITEST.strip
935
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
936
+ # #{mutation.file_path}:#{mutation.line}
937
+ def test_asserts_nil_return_value_from_#{safe_name}
938
+ # Assert the method returns nil, not a substituted value
939
+ result = subject.#{method_name}(input_value)
940
+ assert_nil result
941
+ end
942
+ MINITEST
943
+ },
944
+ "superclass_removal" => lambda { |mutation|
945
+ method_name = parse_method_name(mutation.subject.name)
946
+ safe_name = sanitize_method_name(method_name)
947
+ original_line, _mutated_line = extract_diff_lines(mutation.diff)
948
+ <<~MINITEST.strip
949
+ # Mutation: removed superclass from `#{original_line}` in #{mutation.subject.name}
950
+ # #{mutation.file_path}:#{mutation.line}
951
+ def test_depends_on_inherited_behavior_in_#{safe_name}
952
+ # Assert behavior that comes from the superclass
953
+ result = subject.#{method_name}(input_value)
954
+ assert_equal expected, result
955
+ end
956
+ MINITEST
957
+ },
958
+ "local_variable_assignment" => lambda { |mutation|
959
+ method_name = parse_method_name(mutation.subject.name)
960
+ safe_name = sanitize_method_name(method_name)
961
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
962
+ <<~MINITEST.strip
963
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
964
+ # #{mutation.file_path}:#{mutation.line}
965
+ def test_verifies_local_variable_assignment_is_used_in_#{safe_name}
966
+ # Assert that the assigned variable is read later, not just the value expression
967
+ result = subject.#{method_name}(input_value)
968
+ assert_equal expected, result
969
+ end
970
+ MINITEST
971
+ },
972
+ "instance_variable_write" => lambda { |mutation|
973
+ method_name = parse_method_name(mutation.subject.name)
974
+ safe_name = sanitize_method_name(method_name)
975
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
976
+ <<~MINITEST.strip
977
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
978
+ # #{mutation.file_path}:#{mutation.line}
979
+ def test_verifies_instance_variable_is_set_correctly_in_#{safe_name}
980
+ # Assert that the instance variable holds the expected value after the method runs
981
+ subject.#{method_name}(input_value)
982
+ assert_equal expected, subject.instance_variable_get(:@variable)
983
+ end
984
+ MINITEST
985
+ },
986
+ "class_variable_write" => lambda { |mutation|
987
+ method_name = parse_method_name(mutation.subject.name)
988
+ safe_name = sanitize_method_name(method_name)
989
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
990
+ <<~MINITEST.strip
991
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
992
+ # #{mutation.file_path}:#{mutation.line}
993
+ def test_verifies_class_variable_shared_state_in_#{safe_name}
994
+ # Assert that the class variable holds the expected value and affects shared state
995
+ subject.#{method_name}(input_value)
996
+ assert_equal expected, klass.class_variable_get(:@@variable)
997
+ end
998
+ MINITEST
999
+ },
1000
+ "global_variable_write" => lambda { |mutation|
1001
+ method_name = parse_method_name(mutation.subject.name)
1002
+ safe_name = sanitize_method_name(method_name)
1003
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
1004
+ <<~MINITEST.strip
1005
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
1006
+ # #{mutation.file_path}:#{mutation.line}
1007
+ def test_verifies_global_variable_is_set_correctly_in_#{safe_name}
1008
+ # Assert that the global variable holds the expected value after the method runs
1009
+ subject.#{method_name}(input_value)
1010
+ assert_equal expected, $variable
1011
+ end
1012
+ MINITEST
1013
+ },
1014
+ "mixin_removal" => lambda { |mutation|
1015
+ method_name = parse_method_name(mutation.subject.name)
1016
+ safe_name = sanitize_method_name(method_name)
1017
+ original_line, _mutated_line = extract_diff_lines(mutation.diff)
1018
+ <<~MINITEST.strip
1019
+ # Mutation: removed `#{original_line}` in #{mutation.subject.name}
1020
+ # #{mutation.file_path}:#{mutation.line}
1021
+ def test_depends_on_behavior_from_included_module_in_#{safe_name}
1022
+ # Assert behavior provided by the mixin
1023
+ result = subject.#{method_name}(input_value)
1024
+ assert_equal expected, result
1025
+ end
1026
+ MINITEST
1027
+ },
1028
+ "rescue_removal" => lambda { |mutation|
1029
+ method_name = parse_method_name(mutation.subject.name)
1030
+ safe_name = sanitize_method_name(method_name)
1031
+ original_line, _mutated_line = extract_diff_lines(mutation.diff)
1032
+ <<~MINITEST.strip
1033
+ # Mutation: removed `#{original_line}` in #{mutation.subject.name}
1034
+ # #{mutation.file_path}:#{mutation.line}
1035
+ def test_verifies_rescue_handler_is_needed_in_#{safe_name}
1036
+ # Trigger the rescued exception and assert the handler's effect
1037
+ result = subject.#{method_name}(input_that_raises)
1038
+ assert_equal expected, result
1039
+ end
1040
+ MINITEST
1041
+ },
1042
+ "rescue_body_replacement" => lambda { |mutation|
1043
+ method_name = parse_method_name(mutation.subject.name)
1044
+ safe_name = sanitize_method_name(method_name)
1045
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
1046
+ <<~MINITEST.strip
1047
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
1048
+ # #{mutation.file_path}:#{mutation.line}
1049
+ def test_verifies_rescue_handler_produces_correct_result_in_#{safe_name}
1050
+ # Trigger the exception and assert the rescue body's return value or side effect
1051
+ result = subject.#{method_name}(input_that_raises)
1052
+ assert_equal expected, result
1053
+ end
1054
+ MINITEST
1055
+ },
1056
+ "inline_rescue" => lambda { |mutation|
1057
+ method_name = parse_method_name(mutation.subject.name)
1058
+ safe_name = sanitize_method_name(method_name)
1059
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
1060
+ <<~MINITEST.strip
1061
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
1062
+ # #{mutation.file_path}:#{mutation.line}
1063
+ def test_verifies_inline_rescue_fallback_value_in_#{safe_name}
1064
+ # Trigger the exception and assert the fallback value is correct
1065
+ result = subject.#{method_name}(input_that_raises)
1066
+ assert_equal expected, result
1067
+ end
1068
+ MINITEST
1069
+ },
1070
+ "ensure_removal" => lambda { |mutation|
1071
+ method_name = parse_method_name(mutation.subject.name)
1072
+ safe_name = sanitize_method_name(method_name)
1073
+ original_line, _mutated_line = extract_diff_lines(mutation.diff)
1074
+ <<~MINITEST.strip
1075
+ # Mutation: removed ensure block `#{original_line}` in #{mutation.subject.name}
1076
+ # #{mutation.file_path}:#{mutation.line}
1077
+ def test_verifies_ensure_cleanup_runs_in_#{safe_name}
1078
+ # Assert that the cleanup side effect is observable after the method runs
1079
+ subject.#{method_name}(input_value)
1080
+ assert_equal expected, observable_cleanup_effect
1081
+ end
1082
+ MINITEST
1083
+ },
1084
+ "break_statement" => lambda { |mutation|
1085
+ method_name = parse_method_name(mutation.subject.name)
1086
+ safe_name = sanitize_method_name(method_name)
1087
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
1088
+ <<~MINITEST.strip
1089
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
1090
+ # #{mutation.file_path}:#{mutation.line}
1091
+ def test_verifies_break_exits_loop_correctly_in_#{safe_name}
1092
+ # Assert the loop exits early and returns the expected value
1093
+ result = subject.#{method_name}(input_value)
1094
+ assert_equal expected, result
1095
+ end
1096
+ MINITEST
1097
+ },
1098
+ "next_statement" => lambda { |mutation|
1099
+ method_name = parse_method_name(mutation.subject.name)
1100
+ safe_name = sanitize_method_name(method_name)
1101
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
1102
+ <<~MINITEST.strip
1103
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
1104
+ # #{mutation.file_path}:#{mutation.line}
1105
+ def test_verifies_next_skips_iteration_correctly_in_#{safe_name}
1106
+ # Assert the iteration is skipped and the expected value is yielded
1107
+ result = subject.#{method_name}(input_value)
1108
+ assert_equal expected, result
1109
+ end
1110
+ MINITEST
1111
+ },
1112
+ "redo_statement" => lambda { |mutation|
1113
+ method_name = parse_method_name(mutation.subject.name)
1114
+ safe_name = sanitize_method_name(method_name)
1115
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
1116
+ <<~MINITEST.strip
1117
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
1118
+ # #{mutation.file_path}:#{mutation.line}
1119
+ def test_verifies_redo_retry_logic_is_necessary_in_#{safe_name}
1120
+ # Assert the iteration restart changes the outcome
1121
+ result = subject.#{method_name}(input_value)
1122
+ assert_equal expected, result
1123
+ end
1124
+ MINITEST
1125
+ },
1126
+ "bitwise_replacement" => lambda { |mutation|
1127
+ method_name = parse_method_name(mutation.subject.name)
1128
+ safe_name = sanitize_method_name(method_name)
1129
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
1130
+ <<~MINITEST.strip
1131
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
1132
+ # #{mutation.file_path}:#{mutation.line}
1133
+ def test_verifies_exact_bitwise_result_in_#{safe_name}
1134
+ # Assert the exact bit-level result to distinguish &, |, and ^ operators
1135
+ result = subject.#{method_name}(input_value)
1136
+ assert_equal expected, result
1137
+ end
1138
+ MINITEST
1139
+ },
1140
+ "bitwise_complement" => lambda { |mutation|
1141
+ method_name = parse_method_name(mutation.subject.name)
1142
+ safe_name = sanitize_method_name(method_name)
1143
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
1144
+ <<~MINITEST.strip
1145
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
1146
+ # #{mutation.file_path}:#{mutation.line}
1147
+ def test_verifies_bitwise_complement_result_in_#{safe_name}
1148
+ # Assert the exact complement (~) value, not just sign or magnitude
1149
+ result = subject.#{method_name}(input_value)
1150
+ assert_equal expected, result
1151
+ end
1152
+ MINITEST
1153
+ },
1154
+ "bang_method" => lambda { |mutation|
1155
+ method_name = parse_method_name(mutation.subject.name)
1156
+ safe_name = sanitize_method_name(method_name)
1157
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
1158
+ <<~MINITEST.strip
1159
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
1160
+ # #{mutation.file_path}:#{mutation.line}
1161
+ def test_verifies_in_place_vs_copy_semantics_matter_in_#{safe_name}
1162
+ # Assert that the original object is or is not modified
1163
+ result = subject.#{method_name}(input_value)
1164
+ assert_equal expected, result
1165
+ end
1166
+ MINITEST
1167
+ },
1168
+ "zsuper_removal" => lambda { |mutation|
1169
+ method_name = parse_method_name(mutation.subject.name)
1170
+ safe_name = sanitize_method_name(method_name)
1171
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
1172
+ <<~MINITEST.strip
1173
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
1174
+ # #{mutation.file_path}:#{mutation.line}
1175
+ def test_verifies_inherited_behavior_from_super_in_#{safe_name}
1176
+ # Assert that the result depends on the superclass implementation
1177
+ result = subject.#{method_name}(input_value)
1178
+ assert_equal expected, result
1179
+ end
1180
+ MINITEST
1181
+ },
1182
+ "explicit_super_mutation" => lambda { |mutation|
1183
+ method_name = parse_method_name(mutation.subject.name)
1184
+ safe_name = sanitize_method_name(method_name)
1185
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
1186
+ <<~MINITEST.strip
1187
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
1188
+ # #{mutation.file_path}:#{mutation.line}
1189
+ def test_verifies_correct_arguments_passed_to_super_in_#{safe_name}
1190
+ # Assert the inherited method receives the expected arguments
1191
+ result = subject.#{method_name}(input_value)
1192
+ assert_equal expected, result
1193
+ end
1194
+ MINITEST
1195
+ },
1196
+ "index_to_fetch" => lambda { |mutation|
1197
+ method_name = parse_method_name(mutation.subject.name)
1198
+ safe_name = sanitize_method_name(method_name)
1199
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
1200
+ <<~MINITEST.strip
1201
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
1202
+ # #{mutation.file_path}:#{mutation.line}
1203
+ def test_distinguishes_bracket_from_fetch_for_missing_keys_in_#{safe_name}
1204
+ # Access a missing key: [] returns nil, .fetch raises KeyError
1205
+ assert_raises(KeyError) { subject.#{method_name}(collection_with_missing_key) }
1206
+ end
1207
+ MINITEST
1208
+ },
1209
+ "index_to_dig" => lambda { |mutation|
1210
+ method_name = parse_method_name(mutation.subject.name)
1211
+ safe_name = sanitize_method_name(method_name)
1212
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
1213
+ <<~MINITEST.strip
1214
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
1215
+ # #{mutation.file_path}:#{mutation.line}
1216
+ def test_verifies_chained_bracket_access_returns_correct_nested_value_in_#{safe_name}
1217
+ # Assert the nested lookup produces the expected value
1218
+ result = subject.#{method_name}(nested_collection)
1219
+ assert_equal expected, result
1220
+ end
1221
+ MINITEST
1222
+ },
1223
+ "index_assignment_removal" => lambda { |mutation|
1224
+ method_name = parse_method_name(mutation.subject.name)
1225
+ safe_name = sanitize_method_name(method_name)
1226
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
1227
+ <<~MINITEST.strip
1228
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
1229
+ # #{mutation.file_path}:#{mutation.line}
1230
+ def test_verifies_bracket_assignment_modifies_collection_in_#{safe_name}
1231
+ # Assert the collection contains the assigned value after the method runs
1232
+ result = subject.#{method_name}(collection)
1233
+ assert_includes result, expected_value
1234
+ end
1235
+ MINITEST
1236
+ },
1237
+ "pattern_matching_guard" => lambda { |mutation|
1238
+ method_name = parse_method_name(mutation.subject.name)
1239
+ safe_name = sanitize_method_name(method_name)
1240
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
1241
+ <<~MINITEST.strip
1242
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
1243
+ # #{mutation.file_path}:#{mutation.line}
1244
+ def test_verifies_pattern_guard_filters_correctly_in_#{safe_name}
1245
+ # Test with input that matches the pattern but fails the guard condition
1246
+ # The guard should prevent matching, routing to a different branch
1247
+ result = subject.#{method_name}(input_matching_pattern_but_failing_guard)
1248
+ assert_equal expected, result
1249
+ end
1250
+ MINITEST
1251
+ },
1252
+ "pattern_matching_alternative" => lambda { |mutation|
1253
+ method_name = parse_method_name(mutation.subject.name)
1254
+ safe_name = sanitize_method_name(method_name)
1255
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
1256
+ <<~MINITEST.strip
1257
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
1258
+ # #{mutation.file_path}:#{mutation.line}
1259
+ def test_verifies_each_pattern_alternative_is_reachable_in_#{safe_name}
1260
+ # Test with input that matches only one specific alternative
1261
+ # Each alternative should have a dedicated test case
1262
+ result = subject.#{method_name}(input_for_specific_alternative)
1263
+ assert_equal expected, result
1264
+ end
1265
+ MINITEST
1266
+ },
1267
+ "collection_return" => lambda { |mutation|
1268
+ method_name = parse_method_name(mutation.subject.name)
1269
+ safe_name = sanitize_method_name(method_name)
1270
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
1271
+ <<~MINITEST.strip
1272
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
1273
+ # #{mutation.file_path}:#{mutation.line}
1274
+ def test_returns_non_empty_collection_from_#{safe_name}
1275
+ # Assert the collection has the expected elements, not just non-empty
1276
+ result = subject.#{method_name}(input_value)
1277
+ assert_equal expected, result
1278
+ end
1279
+ MINITEST
1280
+ },
1281
+ "scalar_return" => lambda { |mutation|
1282
+ method_name = parse_method_name(mutation.subject.name)
1283
+ safe_name = sanitize_method_name(method_name)
1284
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
1285
+ <<~MINITEST.strip
1286
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
1287
+ # #{mutation.file_path}:#{mutation.line}
1288
+ def test_returns_non_zero_non_empty_value_from_#{safe_name}
1289
+ # Assert the exact scalar value, not just presence or type
1290
+ result = subject.#{method_name}(input_value)
1291
+ assert_equal expected, result
1292
+ end
1293
+ MINITEST
1294
+ },
1295
+ "pattern_matching_array" => lambda { |mutation|
1296
+ method_name = parse_method_name(mutation.subject.name)
1297
+ safe_name = sanitize_method_name(method_name)
1298
+ original_line, mutated_line = extract_diff_lines(mutation.diff)
1299
+ <<~MINITEST.strip
1300
+ # Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
1301
+ # #{mutation.file_path}:#{mutation.line}
1302
+ def test_verifies_each_array_pattern_element_matters_in_#{safe_name}
1303
+ # Test with input where changing one element type causes a different match
1304
+ # Each position in the array pattern should be validated
1305
+ result = subject.#{method_name}(input_with_wrong_element_type)
1306
+ assert_equal expected, result
1307
+ end
1308
+ MINITEST
1309
+ }
1310
+ }.freeze
1311
+
661
1312
  DEFAULT_SUGGESTION = "Add a more specific test that detects this mutation"
662
1313
 
663
- def initialize(suggest_tests: false)
1314
+ def initialize(suggest_tests: false, integration: :rspec)
664
1315
  @suggest_tests = suggest_tests
1316
+ @integration = integration
665
1317
  end
666
1318
 
667
1319
  # Generate suggestions for survived mutations.
@@ -683,7 +1335,8 @@ class Evilution::Reporter::Suggestion
683
1335
  # @return [String]
684
1336
  def suggestion_for(mutation)
685
1337
  if @suggest_tests
686
- concrete = CONCRETE_TEMPLATES[mutation.operator_name]
1338
+ templates = @integration == :minitest ? MINITEST_CONCRETE_TEMPLATES : CONCRETE_TEMPLATES
1339
+ concrete = templates[mutation.operator_name]
687
1340
  return concrete.call(mutation) if concrete
688
1341
  end
689
1342
 
@@ -695,6 +1348,10 @@ class Evilution::Reporter::Suggestion
695
1348
  subject_name.split(/[#.]/).last
696
1349
  end
697
1350
 
1351
+ def sanitize_method_name(name)
1352
+ name.gsub(/[^a-zA-Z0-9_]/, "_").gsub(/_+/, "_").gsub(/\A_|_\z/, "")
1353
+ end
1354
+
698
1355
  def extract_diff_lines(diff)
699
1356
  lines = diff.split("\n")
700
1357
  original = lines.find { |l| l.start_with?("- ") }