Mutation testing toolkit for MoonBit projects
你的测试不仅会运行,还真的能发现代码被悄悄改坏了吗?
moon add Magic486/moon_mutest@0.1.6import {
"Magic486/moon_mutest"
}///|
test {
let manifest = @moon_mutest.manifest("a == b && true", file="demo.mbt")
inspect(manifest.summary.candidate_count, content="3")
}moon check --warn-list +73
moon test --warn-list +73moon run --target js cmd/main -- scan "a == b && true"Mutation candidates for <memory>
total: 3
boolean: 1
equality: 1
relational: 0
arithmetic: 0
logical: 1
numeric: 0
#0 <memory>:1:3 eq-to-ne == -> != | a == b && true
#1 <memory>:1:8 and-to-or && -> || | a == b && true
#2 <memory>:1:11 true-to-false true -> false | a == b && truemoon run --target js cmd/main -- run . --max-mutants 10 --first 10moon run --target js cmd/main -- run path/to/workspace --max-mutants 5 --first 5moon run --target js cmd/main -- scan "score >= limit && enabled"moon run --target js cmd/main -- scan --profile boundary "let n = 0"moon run --target js cmd/main -- scan --json --profile boundary "let n = 1"moon check --warn-list +73
moon test --warn-list +73moon run --target js cmd/main -- run . \
--profile boundary \
--format markdown \
--max-mutants 30 \
--first 10moon run --target js cmd/main -- run . --format json --max-mutants 10moon run --target js cmd/main -- run . --format html --max-mutants 50 > mutest-report.htmlmoon run --target js cmd/main -- run . --keep-temp --temp-dir _build/mutest-debugmoon run --target js cmd/main -- run . \
--max-mutants 50 \
--fail-under 80 \
--max-survived 0{
"profile": "basic",
"format": "text",
"max_mutants": 50,
"first": 10,
"fail_under": 80,
"max_survived": 0,
"max_skipped": 0
}moon run --target js cmd/main -- run . --config moon_mutest.json///|
test {
let manifest = @moon_mutest.manifest("a + b == c && false", file="demo.mbt")
inspect(manifest.summary.candidate_count, content="4")
inspect(manifest.candidates[0].rule.label, content="add-to-sub")
let mutants = @moon_mutest.generate_mutants("a + b == c", file="demo.mbt")
inspect(mutants[0].source, content="a - b == c")
}///|
test {
let text = @moon_mutest.format_manifest_json("a == b", file="demo.mbt")
assert_true(text.contains("\"candidate_count\": 1"))
assert_true(text.contains("\"eq-to-ne\""))
}///|
test {
let plan = @moon_mutest.plan_project([
@moon_mutest.source_file("src/a.mbt", "a == b"),
@moon_mutest.source_file("src/b.mbt", "x + y && false"),
])
inspect(plan.file_count, content="2")
inspect(plan.mutation_count, content="4")
inspect(plan.mutations[0].global_id, content="0")
}///|
test {
let source = "let ok = a == b"
let candidate = @moon_mutest.discover(source, file="a.mbt")[0]
let preview = @moon_mutest.preview_candidate_patch(source, candidate)
assert_true(preview is Some(_))
}moon run --target js cmd/main -- run examples/quality_gate_workspace --max-mutants 1 --first 1 --temp-dir _build/quality-gate-example-runkilled: 1
survived: 0
score: 100%moon run --target js cmd/main -- run examples/weak_test_workspace --max-mutants 1 --first 1 --temp-dir _build/weak-test-example-runkilled: 0
survived: 1
score: 0%///|
test {
let config = @moon_mutest.MutestConfig::default()
let plan = @moon_mutest.build_execution_plan(
[
@moon_mutest.source_file("src/a.mbt", "a == b && false"),
@moon_mutest.source_file("src/b.mbt", "x + y"),
],
config,
)
let selected = @moon_mutest.select_executions(
plan,
Shard(shard_index=1, shard_count=2),
)
inspect(selected.length(), content="2")
let batches = @moon_mutest.build_selected_batch_plan(
plan,
FirstMutants(2),
OneMutantPerBatch,
)
inspect(batches.batch_count, content="2")
let script = @moon_mutest.generate_selected_runner_script(
plan,
FirstMutants(1),
BashDialect,
)
assert_true(script.content.contains("moon-mutest baseline"))
}///|
test {
let files = [
@moon_mutest.source_file("src/lib.mbt", "a == b"),
@moon_mutest.source_file("src/lib_test.mbt", "test {}"),
@moon_mutest.source_file("_build/gen/out.mbt", "let x = 1"),
]
let selected = @moon_mutest.select_workspace_files(
files,
@moon_mutest.WorkspaceFileSpec::moonbit_default(),
)
inspect(selected.length(), content="1")
inspect(selected[0].path, content="src/lib.mbt")
}///|
test {
let plan = @moon_mutest.plan_project([
@moon_mutest.source_file("src/a.mbt", "a == b"),
])
let report = @moon_mutest.summarize_project_run(plan, [
@moon_mutest.project_result(plan.mutations[0], Killed),
])
let gate = @moon_mutest.evaluate_quality_gate(
report,
@moon_mutest.QualityGate::default(),
)
inspect(@moon_mutest.quality_gate_status_label(gate.status), content="passed")
}moon check --target all
moon test --target all
moon info
git diff --exit-code
moon run --target js cmd/main -- scan "a == b && true"
moon run --target js cmd/main -- run examples/quality_gate_workspace --max-mutants 1 --first 1 --fail-under 100 --max-survived 0 --max-skipped 0
moon run --target js cmd/main -- run examples/quality_gate_workspace --config examples/quality_gate_workspace/moon_mutest.json
moon run --target js cmd/main -- run examples/weak_test_workspace --max-mutants 1 --first 1moon check --warn-list +73
moon fmt --check
moon info
moon check --target js --warn-list +73
moon build
moon test --warn-list +73
moon test --target js --warn-list +73moon publish --dry-run
moon publishfn build_execution_plan_with_profile(files : ArrayView[SourceFile], config : MutestConfig, profile : RuleProfile) -> ExecutionPlanfn build_selected_batch_plan(plan : ExecutionPlan, selection : SelectionMode, strategy : BatchStrategy) -> BatchPlanfn classify_baseline(expected : ArrayView[RunnerCommand], results : ArrayView[CommandResult]) -> BaselineReportfn classify_project_sequence(mutation : ProjectMutation, commands : ArrayView[CommandResult]) -> ProjectMutantResultfn classify_sequence(candidate : MutationCandidate, commands : ArrayView[CommandResult]) -> MutantResultfn command_failure(phase : CommandPhase, code : Int, stdout? : String, stderr? : String) -> CommandResultfn discover_filtered(source : String, filter : MutationFilter, file? : String) -> Array[MutationCandidate]fn discover_with_profile(source : String, profile : RuleProfile, file? : String) -> Array[MutationCandidate]fn discover_with_rules(source : String, rules : ArrayView[MutationRule], file? : String) -> Array[MutationCandidate]fn evaluate_quality_gate_after_baseline(report : ProjectRunReport, gate : QualityGate, baseline : BaselineReport) -> QualityGateReportfn filter_candidates(candidates : ArrayView[MutationCandidate], filter : MutationFilter) -> Array[MutationCandidate]fn format_manifest_json_with_profile(source : String, profile : RuleProfile, file? : String) -> Stringfn format_unified_diff(file : String, line : Int, before : String, after : String) -> Stringfn generate_selected_runner_script(plan : ExecutionPlan, mode : SelectionMode, dialect : ShellDialect) -> RunnerScriptfn manifest_with_profile(source : String, profile : RuleProfile, file? : String) -> MutationManifestfn plan_project_filtered(files : ArrayView[SourceFile], filter : MutationFilter) -> ProjectMutationPlanfn plan_project_with_rules(files : ArrayView[SourceFile], filter : MutationFilter, rules : ArrayView[MutationRule]) -> ProjectMutationPlanfn project_result(mutation : ProjectMutation, outcome : MutantOutcome, detail? : String) -> ProjectMutantResultfn select_project_mutations(plan : ProjectMutationPlan, mode : SelectionMode) -> Array[ProjectMutation]fn select_workspace_files(files : ArrayView[SourceFile], spec : WorkspaceFileSpec) -> Array[SourceFile]fn skip_execution_results_for_baseline(plan : ExecutionPlan, report : BaselineReport) -> Array[ProjectMutantResult]fn summarize_candidates(file : String, candidates : ArrayView[MutationCandidate]) -> MutationSummaryfn summarize_project_run(plan : ProjectMutationPlan, results : ArrayView[ProjectMutantResult]) -> ProjectRunReportfn summarize_workspace_selection(files : ArrayView[SourceFile], spec : WorkspaceFileSpec) -> WorkspaceSelectionReport