ludic/examples/library/coverage.ludic
Orkuncakilkaya e175619543 refactor(cli)!: split the contributor tool out of the ludic CLI
`ludic help` ended with a section titled "contributing to the toolchain itself",
listing bootstrap, reseed, docs-gen and release tasks. None of that is available
to someone who installed the language — those tasks need the repository — so the
shipped tool was advertising work its user cannot do, in a namespace they have to
read past to find `new` and `run`.

The tasks move to a second program, dev.ludic -> bin/ludic-dev, built from a
checkout and excluded from every release artifact. `ludic` keeps the project and
package commands and nothing else; `ludic dev …` now explains where the tasks
went instead of failing as an unknown command.

What this shook out: the two programs share prelude/build/project/pkg, so the
helpers each had accreted in whichever file first needed them — cc(),
ensure_ludicc, the string functions, title_case, cmd_version — moved to where
both can see them. The argument-shift indirection added for the `dev` namespace
is gone with the namespace, so commands read argv directly again.

`ludic-dev test` asserts the split rather than trusting it: the staged install
must build a project, and `ludic dev build` there must fail while naming
ludic-dev. install.sh keeps building older tags, whose bootstrap goes through
main.ludic.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-05 23:15:12 +03:00

51 lines
1.3 KiB
Text

# coverage.ludic — a spec built to be measured by `bin/ludic-dev test --coverage` (issue
# #45). Compiled with `--coverage`, every statement bumps a per-source-line hit
# counter; at exit the counts are dumped and `bin/ludic-dev test --coverage` turns them
# into a per-file line-coverage report.
#
# The tests below exercise `sign` fully but only the taken branches of `grade`,
# so the report flags `grade`'s unreached line — the whole point of coverage:
# it shows you the branch your tests forgot.
#
# As an ordinary spec it still passes and prints:
# == 3 passed, 0 failed ==
program CoverageSpec {
# fully covered: the tests below hit all three returns.
function sign(n: int) -> int {
if n > 0 {
return 1
}
if n < 0 {
return -1
}
return 0
}
# partially covered: no test passes a score below 60, so the `return 0` (fail)
# line is never reached and shows up as uncovered in the report.
function grade(score: int) -> int {
if score >= 90 {
return 4
}
if score >= 60 {
return 2
}
return 0
}
test "sign covers every branch" {
expect_eq(sign(7), 1)
expect_eq(sign(-3), -1)
expect_eq(sign(0), 0)
}
test "grade: high scores" {
expect_eq(grade(95), 4)
expect_eq(grade(75), 2)
}
test "grade: boundary" {
expect_eq(grade(90), 4)
expect_eq(grade(60), 2)
}
}