std/compiler
Compiler and analyzer operations for test tooling.
Import with import std/compiler.
Exports
Section titled “Exports”struct Diagnostic
Section titled “struct Diagnostic”struct Diagnostic { line: Int col: Int message: String }
A compiler diagnostic with 1-based source coordinates.
Diagnostic.inspect
Section titled “Diagnostic.inspect”fn inspect(value: Diagnostic): String
impl Debug.inspect
struct Hover
Section titled “struct Hover”struct Hover { signature: String markdown: String }
Hover text returned by the same renderer used by the editor.
Hover.inspect
Section titled “Hover.inspect”fn inspect(value: Hover): String
impl Debug.inspect
struct Project
Section titled “struct Project”struct Project { entry_point: String files: Map<String, String> manifest: Maybe<Toml> }
An in-memory Nomi project for compiler tests.
entry_point names the file in files to check as the entry file.
File keys are import paths without .nomi, so "main" represents
main.nomi and "api/user" represents api/user.nomi.
manifest is optional nomi.toml content. When present, checks that
depend on package metadata, such as entry_points, use it.
Project.inspect
Section titled “Project.inspect”fn inspect(value: Project): String
impl Debug.inspect
struct RunFile
Section titled “struct RunFile”struct RunFile { entry_point: String env: Map<String, String> }
Options for running a .nomi file under the current test project root.
RunFile.inspect
Section titled “RunFile.inspect”fn inspect(value: RunFile): String
impl Debug.inspect
compiler.check
Section titled “compiler.check”fn check(source: String): List<Diagnostic>
Checks source as a standalone Nomi entry file and returns every
diagnostic as data.
Interactive Tests
diagnostics = compiler.check(
"""
fn main() {
dbg missing
}
"""
)
assert [diagnostic] = diagnostics
assert String.contains?(diagnostic.message, "undefined variable 'missing'")
compiler.run
Section titled “compiler.run”fn run(source: String): Result<String, String>
Runs source as a standalone Nomi entry file and captures stdout.
Err(message) is returned for parse, analysis, or runtime errors.
Use compiler.check when the diagnostic itself is the behavior under
test; use compiler.run when output is the behavior under test.
Interactive Tests
case compiler.run(
"""
fn main() {
_ = dbg 41 + 1
}
"""
) {
Ok(out) -> assert String.contains?(out, "41 + 1 = 42")
Err(e) -> assert String.contains?(e, "unreachable: the program above runs")
}
compiler.run_file
Section titled “compiler.run_file”fn run_file(run: RunFile): Result<String, String>
Runs a .nomi file under the current test project root and captures
stdout.
compiler.hover
Section titled “compiler.hover”fn hover(source: String): Result<Hover, String>
Returns hover content for the single ˇ marker in source.
The marker is removed before parsing. Use it only in compiler/editor tests, where it marks the cursor position without making the fixture depend on line and column numbers.
Interactive Tests
hover = try compiler.hover(
"""
fn main() {
ansˇwer = 42
_ = answer
}
"""
)
assert hover.signature == "answer: Int"
compiler.check_project
Section titled “compiler.check_project”fn check_project(project: Project): List<Diagnostic>
Checks an in-memory project and returns every diagnostic as data.
Interactive Tests
diagnostics = compiler.check_project(Project{
entry_point: "main",
manifest: Maybe.Some(
Toml"""
[module]
name = "demo"
entry_points = ["main"]
"""
),
files: {
"main" => """
import api.{Widget, make}
fn main() {
w = make("Ada")
Widget.secret(w)
}
""",
"api" => """
pub struct Widget {
name: String
}
fn secret(w: Widget): String {
"secret " + w.name
}
pub fn make(name: String): Widget {
Widget{name}
}
""",
},
})
assert [diagnostic] = diagnostics
assert String.contains?(diagnostic.message, "no member 'secret'")