Testing applications
Kinmokusei v0.4 does not provide a keika test command. Use keika check for source validity, executable recipes for end-to-end behavior, and ordinary Go tests when you need to exercise an emitted package API.
Choose the boundary under test
| Goal | Test boundary |
|---|---|
| Reject invalid source before generation | keika check and its diagnostic/exit status |
| Verify a command's observable behavior | keika run plus an exact output assertion |
| Test public functions and types as a package | keika emit-go -package ..., then go test |
| Test HTTP routing without a listener | net/http/httptest through kinmokusei/http |
| Verify compiler compatibility with Go | Independent handwritten Go oracle; compiler contributors only |
Generated Go can be tested, but generated output must not become the oracle for its own semantics. Assert the API behavior your application promises.
A tested package
The Kinmokusei source exposes two Go-callable functions. Add and Half begin with uppercase letters, so their generated top-level Go declarations are exported:
import go errors from "errors";
function Add(left: int, right: int): int {
return left + right;
}
function Half(value: int): Result<int> {
if (value % 2 !== 0) {
return fail(errors.New("value must be even"));
}
return ok(value / 2);
}Emit it as package calculator:
keika check public_api.km
keika emit-go -package calculator -o calculator.go public_api.kmAn ordinary Go test can call the generated API directly:
package calculator
import "testing"
func TestPublicAPI(t *testing.T) {
if got := Add(20, 22); got != 42 {
t.Fatalf("Add(20, 22) = %d, want 42", got)
}
if got, err := Half(8); err != nil || got != 4 {
t.Fatalf("Half(8) = (%d, %v), want (4, nil)", got, err)
}
if got, err := Half(3); err == nil || got != 0 {
t.Fatalf("Half(3) = (%d, %v), want zero value and error", got, err)
}
}Place the files in one Go package and run:
go test ./...The documentation CI performs this exact generation and test. It proves that Add is callable and that Result<int> is exposed as (int, error), including the zero value on failure.
Public API discipline
- A top-level source name beginning with an uppercase Unicode letter becomes exported from the generated Go package; lowercase top-level names remain package-local.
- Source imports are a separate boundary and select written names explicitly, regardless of capitalization. Any source export opts its file into explicit visibility; without one, legacy selective importability remains.
- Keep parameter, result, named-type, pointer, interface, generic, channel, and error shapes within the documented interoperability matrix.
- Treat generated helper names as private unless the generated-Go guide documents them as public API.
- Regenerate before testing when
.kmsource, the dependency lock, target, or compiler version changes. - Do not hand-edit
calculator.go; fix the source or add a handwritten neighboring Go file with an explicit package boundary.
For HTTP handlers, use the port-free router recipe. For artifact guarantees and publication boundaries, read Generated Go and the Quality promise.