Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ add_subdirectory(nildebugger)
add_subdirectory(nilassembler)
add_subdirectory(nillinker)
add_subdirectory(nilbuild)
add_subdirectory(niltest)
add_subdirectory(aperture)

if(NIL_BUILD_EXPERIMENTAL_TOOLS)
Expand Down Expand Up @@ -433,7 +434,7 @@ if(BUILD_TESTING)
find_package(Python3 3.8 REQUIRED COMPONENTS Interpreter)
if(Python3_Interpreter_FOUND)
set(NY_IDENTITY_TEST_ARGUMENTS)
foreach(tool IN ITEMS nilcompiler nilinterpreter nilassembler nillinker nillsp nildebugger nilschema nilagent nilbuild)
foreach(tool IN ITEMS nilcompiler nilinterpreter nilassembler nillinker nillsp nildebugger nilschema nilagent nilbuild niltest)
if(TARGET ${tool})
list(APPEND NY_IDENTITY_TEST_ARGUMENTS --tool "${tool}=$<TARGET_FILE:${tool}>")
endif()
Expand All @@ -452,6 +453,7 @@ if(BUILD_TESTING)
COMMAND "${Python3_EXECUTABLE}"
"${CMAKE_CURRENT_SOURCE_DIR}/tests/tools/project_build_contract.py"
--builder $<TARGET_FILE:nilbuild>
--tester $<TARGET_FILE:niltest>
--compiler $<TARGET_FILE:nilcompiler>
--interpreter $<TARGET_FILE:nilinterpreter>
--stdlib "${CMAKE_CURRENT_SOURCE_DIR}/nilstd/src"
Expand Down Expand Up @@ -608,6 +610,20 @@ if(BUILD_TESTING)
--interpreter $<TARGET_FILE:nilinterpreter>
--llvm "${NIL_ENABLE_LLVM}")
set_tests_properties(nil.anything-contract PROPERTIES LABELS "matrix;ny;routes;typecheck" TIMEOUT 240)
add_test(NAME niltest.compiler-contract
COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/tools/niltest_compiler_contract.py"
--compiler $<TARGET_FILE:nilcompiler> --interpreter $<TARGET_FILE:nilinterpreter>
--llvm "${NIL_ENABLE_LLVM}")
set_tests_properties(niltest.compiler-contract PROPERTIES LABELS "matrix;ny;testing;routes" TIMEOUT 240)
add_test(NAME niltest.source-contract
COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/tools/niltest_source_contract.py"
--compiler $<TARGET_FILE:nilcompiler> --interpreter $<TARGET_FILE:nilinterpreter>
--llvm "${NIL_ENABLE_LLVM}")
set_tests_properties(niltest.source-contract PROPERTIES LABELS "matrix;ny;testing;routes" TIMEOUT 240)
add_test(NAME niltest.process-contract
COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/tools/niltest_process_contract.py"
--tester $<TARGET_FILE:niltest>)
set_tests_properties(niltest.process-contract PROPERTIES LABELS "testing;process" TIMEOUT 120 SKIP_RETURN_CODE 77)
# Matrix execution conformance: each page lowers to NIL and runs on the
# interpreter with exact expected output. Acceptance is covered by the
# lexer test; this checks that the lowering means what the surface says.
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,19 @@ For projects with multiple source modules, add a
[`nil.project.nildata`](docs/tools/projects.md) manifest. Project check, build and
run commands use the same import paths and analyzer policy as live checks.

### Tests beside the code

[`niltest`](docs/tools/testing.md) discovers named tests and annotated test
functions in Ny and Matrix, then runs each case in an isolated process through
the interpreter, native code, or both. Inline test blocks share their enclosing
function's locals and run when a test calls that function. Ordinary builds omit
test-only code. `nilbuild test` uses the project configuration, and the VS Code
Test Explorer offers interpreter and native run profiles.

```sh
sdk/niltest run --target all example.matrix
```

## Examples

[`validation/ny-3d`](validation/ny-3d) is an independent consumer of the SDK:
Expand Down
91 changes: 91 additions & 0 deletions docs/design/NIL-0024-colocated-testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# NIL-0024: Tests alongside source

Status: implemented initial unit and integration test profile.

## Purpose

Tests belong to the same source graph as the behavior they exercise. Both
frontends lower test declarations and assertions to the shared AST. The compiler
checks their types, ownership and source identity; tools consume its discovery
manifest instead of recognizing tests with text searches.

## Source model

Ny named `test` and `example` blocks, Matrix `<name> begin test` blocks, and
zero-argument, nongeneric void functions annotated `@test` are runnable cases.
`@suite("name")` supplies a group; Matrix can spell these annotations `note test`
and `note suite "name"`. Existing Ny tests attached after a function remain
supported. Integration annotations describe cases without changing execution.

A named test block inside a function is an inline test region. It sees the
function's preceding locals and introduces a child lexical scope. It executes
when a discovered case calls that function in a test build. It does not invent
arguments or become an independent case. Ownership analysis includes the region;
returning from it or jumping to an enclosing loop is rejected. Loops declared
inside the region retain ordinary control flow.

Production compilation removes test declarations, annotated test functions and
inline regions before semantic checking and lowering. Test-only declarations
cannot provide symbols to production code. Syntax still has to parse. Editor
analysis retains the test code so errors remain visible while editing.

Matrix `expect expression` lowers to the same assertion node as Ny `assert`.
Direct comparisons retain both operands for diagnostics. Supported assertions
check Boolean conditions or scalar/text equality and numeric ordering. Arguments
are evaluated once, in source order, including an optional Ny message. A failed
check reports its source, assertion and actual/expected values. Ordinary
assertions outside test-only regions are runtime checks. Property generators
and unsupported assertion methods produce explicit diagnostics.

## Discovery and execution

`nilcompiler --test-list` checks the complete input/import graph and emits
`nil.tests.v1` JSON. It never executes user code or initializers. Each case has an
opaque deterministic ID, name, suite, kind, function and source location. IDs
identify a particular checked source layout, not a permanent external API.

`nilcompiler --test` adds a synthetic entrypoint selected by one exact case ID.
It calls the case directly, avoiding an unimplemented native function-pointer
ABI. The original application entrypoint remains callable under a private
name. Global initialization runs once after a valid case is selected. The
harness exits with private completion status 77; an early user `exit(0)` does
not count as completion. This status is an execution convention, not a security
boundary against a deliberately forged test.

`niltest` compiles once for each requested VM/native route, then runs each
selected case in its own process. A fault, signal or timeout is a case result;
ordinary failures do not stop later cases. Process groups provide cancellation
and descendant cleanup. Captured stdout/stderr are data inside a result record,
never a status protocol. JSON and NILData reports identify the route explicitly.
Current process execution requires a POSIX host.

`nilbuild test` delegates with the project's entrypoint and import/SDK paths.
VS Code discovers from saved sources in a trusted workspace and supplies
interpreter/native Test Explorer run profiles. It validates the structured
reports and rejects stale/unknown identities instead of guessing a match.

## Library and limits

The Matrix-authored `nil.std.testing` provides scalar checks and generic
`require-some`/`require-ok` value extraction. An unsuccessful extraction faults
with the supplied explanation; it does not fabricate a value. The module's own
tests live beside its implementation.

The initial profile does not include property generation, coverage, fixtures
with shared mutable process state, automatic test-input synthesis, or a Test
Explorer debugging profile. Source maps for preprocessor transformations remain
tracked separately. Imported source tests participate in discovery; callers can
filter suites or exact IDs. Binary libraries do not expose runnable test source.

## Evidence

- `tests/tools/niltest_compiler_contract.py`: read-only discovery, harness
selection, initialization and artifact preservation on VM/native routes.
- `tests/tools/niltest_source_contract.py`: both source languages, production
exclusion, lexical scope, assertions, ownership and standard-library helpers.
- `tests/tools/niltest_process_contract.py`: isolated results, cancellation,
timeouts, descendant cleanup, selection and malformed discovery.
- Editor model and real extension-host tests: report validation, source identity
and compiler-backed discovery.

See the [testing guide](../tools/testing.md) for runnable examples and limits.
1 change: 1 addition & 0 deletions docs/design/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ not assigned architecture identifiers.
| NIL-0021 | [Switch statements and expressions with automatic fallthrough](NIL-0021-fallthrough-switch.md) | Accepted; initial literal and payload-free enum selector profile |
| NIL-0022 | [Incremental project builds and NILData configuration](NIL-0022-incremental-project-builds.md) | Implemented initial local project graph and target scheduling profile |
| NIL-0023 | [Dynamic values and Boolean vocabulary](NIL-0023-dynamic-values-and-booleans.md) | Implemented |
| NIL-0024 | [Tests alongside source](NIL-0024-colocated-testing.md) | Implemented initial unit/integration profile |
| NIL-0093 | [Executable context is artifact self-description](NIL-0093-executable-context.md) | Implemented within the documented inspection profile |

## Retained Ny feature references
Expand Down
9 changes: 9 additions & 0 deletions docs/developer-tooling.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ or running. VS Code consumes that configuration for live analysis and project
tasks, displays matching imported-file diagnostics, and offers guarded style
fixes. See [projects](tools/projects.md) and the [analysis API](analysis-api.md).

`niltest` now uses compiler-backed discovery and isolated per-case execution for
Ny and Matrix. `nilbuild test` shares the project entrypoint and import settings,
and VS Code's Testing view provides interpreter/native run profiles for saved
sources in trusted workspaces. Colocated and inline lexical test blocks are
excluded from production compilation. Assertions and `nil.std.testing` helpers
supply the initial checked test API. See the [testing guide](tools/testing.md)
for syntax, reports, process limits, and the current scope; property generators,
coverage, and test-debug profiles remain future work.

Project manifests now default to NILData. Local project references establish
dependency ordering, and bounded parallel jobs build independent projects and
VM/native targets. SHA-256 input and artifact identities avoid redundant
Expand Down
18 changes: 14 additions & 4 deletions docs/standard-library/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Standard-library status

Ny and Matrix share `nilstd`, one standard library compiled to NIL. Its 76 active
sources (69 Ny and seven Matrix) form 16 logical SDK modules, including `prelude`.
Ny and Matrix share `nilstd`, one standard library compiled to NIL. Its active
Ny and Matrix sources form 17 logical SDK modules, including `prelude`.
Support remains evidence-scoped. Focused fixtures exercise `nilstd` and `nillib`
through textual/binary NIL, bundles, LLVM JIT and AOT, and standalone
assembler/linker pipelines. Local SDK qualification records the exact source
Expand Down Expand Up @@ -31,7 +31,7 @@ averaging, nonfinite compatibility behavior and numerical accuracy limits.

```text
nilstd/
src/ Ny and Matrix sources organized as 16 logical modules
src/ Ny and Matrix sources organized as 17 logical modules
native/ 14 preserved C and C++ interoperability shims
tests/ 8 preserved design-era library tests
experimental/ 65 quarantined Ny sources excluded from the SDK
Expand All @@ -43,7 +43,7 @@ remain aliases of the same module identities.

The active logical modules are `prelude` and `nil.std.core`, `collections`,
`datetime`, `db`, `diagnostics`, `io`, `math`, `net`, `nildata`, `reflection`, `runtime`,
`security`, `system`, `text`, and `threading`. Quarantine is broader than parser
`security`, `system`, `testing`, `text`, and `threading`. Quarantine is broader than parser
failure: an experimental source may compile yet still lack complete language
semantics, an executable provider, or behavioral evidence.

Expand All @@ -68,6 +68,16 @@ packages/ny.ui.mimic/
Other opt-in experiments, including `ny.godot`, also live under
`packages`. `nilaix` is a separate UI/AI integration sandbox.

## Testing

`nil.std.testing` provides Boolean and scalar checks plus `require-some` and
`require-ok` for checked value extraction inside ordinary assignments. The
module is written in Matrix and includes tests next to its implementation.
These helpers remain runtime checks when called by production code; placing
them in test blocks makes them test-only. See the
[co-located testing guide](../tools/testing.md) for language syntax, discovery,
execution routes, and editor integration.

## NILData

`nil.std.nildata` provides checked, versioned data loading and serialization,
Expand Down
21 changes: 17 additions & 4 deletions docs/tools/projects.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Projects and the default analyzer

`nilbuild` checks, builds and runs Ny/Matrix projects using the installed
`nilbuild` checks, builds, runs and tests Ny/Matrix projects using the installed
compiler. A `nil.project.nildata` manifest supplies the entrypoint, import
roots, SDK selection and analyzer policy to the CLI and VS Code extension.
Each project produces one executable; project references express the ordering
Expand Down Expand Up @@ -53,6 +53,7 @@ nilbuild build
nilbuild run
nilbuild run --target native
nilbuild build --target all --jobs 4
nilbuild test --target all
```

`build` and `run` check the saved import graph on every invocation. Compiler
Expand Down Expand Up @@ -86,16 +87,18 @@ A project reference establishes build ordering. It does not add an import
root, expose the referenced program's symbols, or link its executable into the
caller. Configure `includePaths` for shared source modules as before. A project
shared by several dependents is built once; each manifest must list distinct
reference paths. Reference cycles are errors. Package resolution, remote downloads, arbitrary hooks, test discovery
and publishing remain outside this profile.
reference paths. Reference cycles are errors. Package resolution, remote downloads, arbitrary hooks
and publishing remain outside this profile. Compiler-backed tests use the same
entrypoint and import settings; see [testing](testing.md).

## Incremental and parallel builds

`--jobs N` limits simultaneous compiler processes to 1–64; the default uses up
to four hardware threads. Independent projects in a dependency wave can be
checked and compiled concurrently. References complete before their dependents
are built. `--target all` builds both VM and native outputs and allows the two
compilations to run concurrently; it is available only with `build`. `run`
compilations to run concurrently. `test --target all` also supports both routes,
using its separate test runner. `run`
selects one target, and still builds that project's references first.

Parallelism is across projects and output targets. A single executable's
Expand Down Expand Up @@ -182,8 +185,14 @@ nilbuild describe [--project FILE] [--format nildata|json|yaml]
nilbuild check [--project FILE] [--format nildata|json|yaml]
nilbuild build [--project FILE] [--target vm|native|all] [--jobs N] [--rebuild]
nilbuild run [--project FILE] [--target vm|native] [--jobs N] [--rebuild] [-- PROGRAM_ARGUMENTS...]
nilbuild test [--project FILE] [--target vm|native|all] [--jobs N] [--filter TEXT] [--test-id ID] [--timeout SECONDS] [--format human|json|nildata]
```

`test` delegates to `niltest` and uses fresh temporary test artifacts. It does not
run the application build pipeline or build project-reference executables.
`--tester PATH` selects a runner override. Test selection, process isolation,
reports, and editor integration are described in the [testing guide](testing.md).

Tool overrides are `--compiler PATH` and `--interpreter PATH`; otherwise the
driver looks beside itself and then on `PATH`. `--sdk PATH` resolves relative
to the invocation directory and overrides the manifest's SDK location.
Expand Down Expand Up @@ -265,6 +274,10 @@ source snapshot before displaying results. Parse recovery remains limited;
the language server retains tolerant completion for unsupported contexts and
supplies hover and outline information.

The Testing view also discovers compiler-backed tests and runs selected cases
through interpreter or native profiles. See [testing in VS Code](testing.md#visual-studio-code)
for the saved-source workflow and current limits.

Find All References and rename are available for compiler-certified lexical
locals; rename checks the proposed source and its bindings before returning
edits.
Expand Down
Loading
Loading