Files
dcr/docs/commands/dcr-test.md
Dexoron 7969209eae Added:
- `build.kind = "efi"` — UEFI PE32+ executable support. Links with `-shared -nostdlib -Wl,-dll -Wl,--subsystem,10`, output via `efi_path()` with `.efi` extension, rejected by `dcr run`.
- `build.kind = "elf"` — bare-metal ELF executable support. Uses `elf_path()` output path, rejected by `dcr run`, no extra linker flags.

Fixed:

- `dcr run` with `--target` or `build.target` now correctly finds the binary in the arch-specific target directory.
- `dcr run` checks profile-specific `build.{profile}.kind` before rejecting library builds (previously only checked `build.kind`).
- `dcr clean` now reads `build.target` from `dcr.toml` when no `--target` flag is given.
- Linux: target directory is now consistent — `target/<arch>-unknown-linux-gnu/<profile>/` (no stale `target/<profile>/`).
- `dcr.lock` is now populated with all resolved dependencies (registry, path, git) instead of being always empty.
- Git dependencies are now properly recognized and recorded in `dcr.lock`.
- `is_registry_dep` correctly identifies version-based registry dependency tables (`{ version = "..." }`) and rejects tables with unknown keys.
- `dcr test` accepts `--debug`/`--release` flags (defaults to `debug` profile instead of always `release`).
- Build fingerprint cache (`build_cache_path`) now includes `target_dir` — different targets no longer share a single cache entry.
- `object_path` no longer hardcodes the `src/` prefix — works correctly with custom `build.roots` (e.g. `roots = ["lib"]`).
- `dcr update` now generates `.exe` candidates for all Windows targets, not just `x86_64-pc-windows-msvc`.
- Compiler existence is verified before starting the build (clear error if compiler is not found in PATH).
- Consolidated duplicate `OUTPUT_MUTEX` definitions — MSVC backend now uses the shared mutex from `common.rs`.
- Registry cache root directory is created if missing (prevents cryptic errors when `~/.dcr/` does not exist).
2026-05-26 16:38:23 +08:00

1.3 KiB

dcr test

Runs the project's test suite.

Usage

dcr test
dcr test --debug
dcr test --release
dcr test --target linux
dcr test --init

What test does

  1. Builds the project with the specified profile/target.
  2. Compiles test files in tests/ (e.g., tests/test.c) into a test binary.
  3. Runs the test binary and parses output for PASS/SKIP/FAIL results.
  4. Reports summary with colored output.

Test Structure

DCR uses a simple test framework:

  • Header: tests/dcr_test.h (generated by dcr test --init)
  • Test file: tests/test.c (template generated by dcr test --init)
  • Macros: TEST(name), TEST_CASE(name), EXPECT(condition), SKIP(reason)
  • Output: [PASS] test_name, [FAIL] test_name, or [SKIP] test_name

Config values used

  • package.name
  • build.compiler, build.language, build.standard
  • build.cflags, build.ldflags
  • build.debug / build.release
  • build.targets (if specified)

Notes

  • Test binary is linked with the main project (for lib projects) or standalone.
  • --init creates tests/dcr_test.h and tests/test.c if missing.
  • Tests run in debug mode by default. Use --release for release mode.
  • Custom test logic can be added by editing tests/test.c.
  • Fails if no tests/test.c exists (run dcr test --init first).