Skip to content

feat: implement odin_test rule with shared compilation helper#10

Merged
clappingmonkey merged 1 commit into
mainfrom
feat/odin-test
Jul 8, 2026
Merged

feat: implement odin_test rule with shared compilation helper#10
clappingmonkey merged 1 commit into
mainfrom
feat/odin-test

Conversation

@clappingmonkey

Copy link
Copy Markdown
Owner

Summary

Implements the odin_test Bazel rule for running Odin's built-in test framework (@(test)-annotated procedures) within Bazel's test infrastructure.

Design

  • Uses odin build -build-mode:test to compile a test binary at build time (cacheable, hermetic)
  • Bazel's test runner executes the binary at test time (exit 0 = pass, non-zero = fail)
  • Follows the same pattern as rules_go (go_test) and rules_rust (rust_test)
  • Injects ODIN_TEST_FANCY=false by default for CI-friendly output (no ANSI escape codes)
  • Test runner config exposed via defines attr (compile-time constants in Odin)

Refactoring

Extracts compile_odin_binary() shared helper in common.bzl to eliminate code duplication between odin_binary and odin_test. Moves OdinLibraryInfo provider to common.bzl to resolve a circular dependency.

Changes

  • odin/private/common.bzlOdinLibraryInfo + compile_odin_binary() shared helper
  • odin/private/binary.bzl — Refactored to use shared helper
  • odin/private/library.bzl — Imports OdinLibraryInfo from common.bzl
  • odin/private/test.bzlNew: odin_test rule implementation
  • odin/defs.bzl — Re-exports odin_test and OdinLibraryInfo
  • e2e/smoke/tests/smoke_test.odinNew: example test (3 @(test) procedures)
  • e2e/smoke/BUILD.bazel — Adds odin_test target with library deps
  • .github/workflows/check.yamlbazel buildbazel test in smoke step
  • README.md — Documents odin_test rule and test runner defines

Verification

  • bazel build //... (ruleset root): PASSES
  • bazel test //... (e2e/smoke): smoke_test PASSED in 0.7s
  • bazel run //:hello (e2e/smoke): binary still works correctly
  • pre-commit run --all-files: all checks pass
  • @change-validator: APPROVED WITH CONCERNS (docs addressed, no blockers)

Checklist

  • Conventional commit title
  • Tests pass locally
  • Pre-commit hooks pass
  • README updated
  • No breaking changes to existing public API

- Add odin_test rule: compiles @(test)-annotated Odin sources using
  'odin build -build-mode:test', producing a test binary that Bazel's
  test runner executes (compile at build-time, run at test-time)
- Refactor: extract compile_odin_binary() shared helper in common.bzl
  to eliminate duplication between odin_binary and odin_test
- Move OdinLibraryInfo provider to common.bzl to avoid circular deps
  (library.bzl <-> common.bzl cycle)
- Inject ODIN_TEST_FANCY=false by default (CI-friendly, no ANSI escape
  codes); user can override via defines attr
- Test runner config (threads, filtering, memory, etc.) exposed via
  the defines attr as compile-time constants
- Add e2e smoke test: tests/smoke_test.odin exercises arithmetic,
  string ops, and library imports with @(test) procedures
- CI: change 'bazel build' to 'bazel test' in smoke step so odin_test
  targets are actually executed in the matrix
@clappingmonkey clappingmonkey merged commit 21e72aa into main Jul 8, 2026
14 checks passed
@clappingmonkey clappingmonkey deleted the feat/odin-test branch July 8, 2026 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant