ludic/examples/library/coverage.ludic
Orkuncakilkaya aca263642d feat(cli): install in one command, and call the CLI ludic
Getting started meant cloning the repository, bootstrapping a compiler and
learning a task runner called `x`. That is a contributor's workflow handed to
everyone who wants to try the language.

Installing is now one command:

    curl -fsSL https://workshopsoft.pages.workshopsoft.io/ludic/install.sh | sh

install.sh puts a complete toolchain — compiler, CLI, engine runtime, bundled
ludic.* packages, formatter, language server — in ~/.ludic and adds it to PATH.
Prebuilt artifacts are checksum-verified; where a platform has none, or the
release predates this layout, it bootstraps from the compiler's own IR seed with
clang. The docs site publishes the script beside the pages that quote it, so the
page and the script can never come from different releases.

`x` becomes `ludic`, and the surface splits by audience. A user of the language
sees `new`, `run`, `build`, `test`, `add`, `fmt`, `lsp`, `doctor`, `upgrade`;
`ludic new` scaffolds a project that builds and plays as it stands. Everything
the toolchain repo needs moved under `ludic dev` — build, test, reseed,
bootstrap-cfree, docs-gen, release — unchanged apart from the namespace. Those
tasks read arguments one position further along, so dispatch_dev sets a shift
and commands use arg_n()/arg_total() rather than each knowing its own depth.

Release artifacts become complete install roots (bin/ beside runtime/, packages/
and VERSION) rather than bare binaries, which is what the installer unpacks.
`ludic dev test` asserts the whole shape: it stages an install, puts it on PATH
with no LUDIC_HOME, and runs new -> build -> test through it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-05 22:01:52 +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)
}
}