ワンクリックで
testing
How to run tests, add error tests, update golden files, and report nice errors in Dang. Use when running or writing tests.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
How to run tests, add error tests, update golden files, and report nice errors in Dang. Use when running or writing tests.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Dang language reference for writing, editing, and reviewing `.dang` code — syntax, types/nullability, prototype objects, copy-on-write mutation, control flow, errors, GraphQL interop, stdlib, and CLI. Use when authoring or reviewing `.dang` files or Dang modules, or any time precise Dang language behavior matters.
How to add or modify builtin functions and methods in `pkg/dang/stdlib.go`. Use when extending Dang's standard library.
Non-obvious invariants in Dang's compiler — multi-pass hoisting, the Fork/Clone/dynamic-scope-cell model, and `Module.Eq` subtyping. Use when editing `pkg/dang/` infer/eval/scope code, adding a new type-like declaration, or debugging mutation/scoping issues.
How to maintain editor syntax definitions for Dang. Use when adding or removing keywords, tokens, or language constructs.
| name | testing |
| description | How to run tests, add error tests, update golden files, and report nice errors in Dang. Use when running or writing tests. |
All language and error tests live in tests/ and run via the TestDang suite:
# Run all tests
go test ./tests/ -v
# Run a specific test by name
go test ./tests/ -run "TestDang/TestLanguage/test_foo" -v
go test ./tests/ -run "TestDang/TestErrorMessages/some_error" -v
go test ./tests/ -run "TestDang/TestFormatLanguage/test_foo" -v
The DangSuite (in tests/integration_test.go) has three sub-suites:
tests/test_*.dang file and expects it to succeed.tests/test_*.dang file, re-parses the formatted output, runs it, and checks it still produces the same result.tests/errors/*.dang file, expects an error, and compares the output against tests/testdata/<name>.golden.Editor syntax highlighting tests live in editors/ and run via the TestEditors suite:
go test ./editors/ -v
go test ./editors/ -run "TestEditors/TestNeovimHighlights" -update
editors/highlights/corpus/*.txt through Neovim with the tree-sitter parser and compares highlight spans.tree-sitter CLI.These tests Skip unless the editors/nvim and editors/zed submodules are initialized (git submodule update --init).
Error golden files live in tests/testdata/ and contain the exact error output including ANSI escape codes for colored/highlighted source annotations.
To update golden files after changing error messages:
go test ./tests/ -run "TestDang/TestErrorMessages" -update
tests/errors/my_error.dang with code that should produce an error.-update to generate the golden file:
go test ./tests/ -run "TestDang/TestErrorMessages/my_error" -update
tests/testdata/my_error.golden to confirm the error message is correct.Dang has two error types for attaching source locations:
Use NewInferError in Infer() methods to attach source location to type errors. These get converted to SourceError with full source highlighting when displayed.
return nil, NewInferError(fmt.Errorf("descriptive message"), node)
WrapInferError avoids double-wrapping if the error is already an InferError:
return nil, WrapInferError(err, node)
SourceError holds the error, source location, and source text, and renders with highlighted code snippets:
return nil, NewSourceError(fmt.Errorf("message"), location, sourceCode)
During eval, use the EvalContext helper:
return nil, evalCtx.CreateSourceError(err, node)
InferError → ConvertInferError() → SourceError (reads the source file and produces highlighted output). This happens automatically in RunFile.
Wrapper helpers that automatically attach source location to errors that don't already have one:
func (n *MyNode) Infer(ctx context.Context, env hm.Env, fresh hm.Fresher) (hm.Type, error) {
return WithInferErrorHandling(n, func() (hm.Type, error) {
// ... your logic here
})
}
The parser is defined in pkg/dang/dang.peg (pigeon PEG parser). After editing:
go generate ./pkg/dang/
This regenerates pkg/dang/dang.peg.go.
The formatter lives in pkg/dang/format.go. When adding a new AST node type, update:
formatNode() — add a case to format the node