Skip to content

feat: Rust testing framework with mix test integration ($350 bounty #102)#643

Open
JirA44 wants to merge 1 commit into
Spectral-Finance:mainfrom
JirA44:feat/rust-testing-framework
Open

feat: Rust testing framework with mix test integration ($350 bounty #102)#643
JirA44 wants to merge 1 commit into
Spectral-Finance:mainfrom
JirA44:feat/rust-testing-framework

Conversation

@JirA44
Copy link
Copy Markdown

@JirA44 JirA44 commented May 28, 2026

Summary

  • Adds Lux.Rust.Testing — a structured Elixir interface for running cargo test, parsing output, measuring coverage, and managing temporary Rust fixtures
  • Adds Mix.Tasks.Rust.Test (mix rust.test) that discovers every Cargo.toml in the repo, runs tests in each project, and exits non-zero on failures — integrating cleanly with CI pipelines
  • Adds a comprehensive unit-test suite (test/unit/lux/rust/testing_test.exs) that covers output parsing with sample strings (no real Cargo needed), fixture lifecycle, and result struct shape

What's in each file

lib/lux/rust/testing.ex

Function Description
run_tests/2 cargo test{:ok, result_map}
run_tests!/2 Same, raises on failure
run_test/3 Run a single named test
with_coverage/2 cargo llvm-cov, falls back to cargo test
parse_test_output/1 Pure parser — no subprocess
generate_report/2 HTML or text coverage report via cargo llvm-cov
setup_test_fixture/2 Create temp Cargo project with given source
cleanup_fixture/1 Remove temp project

Result map shape:

%{passed: integer, failed: integer, ignored: integer,
  output: string, duration_ms: integer, coverage_pct: float | nil}

lib/mix/tasks/rust.test.ex

  • Recursively finds Cargo.toml files (skipping target/ and workspace-only manifests)
  • Accepts --dir, --release, --features flags
  • Prints pass/fail per project with ANSI colour, summary line at the end
  • Non-zero exit when any suite has failures

test/unit/lux/rust/testing_test.exs

  • parse_test_output/1 — 7 tests covering all-pass, failures, ignored, fractional duration, empty input, unparseable input
  • setup_test_fixture/2 — 5 tests (directory created, Cargo.toml present, source written, name embedded, uniqueness)
  • cleanup_fixture/1 — 2 tests (removes dir, idempotent on missing dir)
  • run_tests/2 — skipped when cargo is absent, exercises result map shape when available

Test plan

  • mix test test/unit/lux/rust/testing_test.exs passes on machines without Cargo installed (parser tests are pure Elixir)
  • mix rust.test exits 0 on a repo with no Rust projects (prints yellow notice)
  • mix rust.test correctly finds and runs any Cargo projects that exist
  • mix rust.test --release forwards the flag to cargo test
  • On a machine with Cargo: setup_test_fixture + run_tests round-trip produces passed >= 1, failed == 0

/opire try #102

Implements Lux.Rust.Testing for running cargo tests from Elixir,
test output parsing, coverage support, and a mix rust.test task
that integrates with the existing mix test pipeline.

Resolves Spectral-Finance#102
@zhaog100
Copy link
Copy Markdown

/opire try

Claiming this bounty. Will deliver a complete implementation.

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.

2 participants