Skip to content

Fix: use if/else pattern for skip() guards in unit tests#1

Closed
will-bates11 wants to merge 1 commit intomainfrom
claude/strange-driscoll
Closed

Fix: use if/else pattern for skip() guards in unit tests#1
will-bates11 wants to merge 1 commit intomainfrom
claude/strange-driscoll

Conversation

@will-bates11
Copy link
Copy Markdown
Owner

Summary

  • Nim's skip() template marks tests as SKIPPED but does not halt test execution. The test body continues running after skip() is called.
  • Tests guarded with if not isLibAvailable(): skip() followed by check assertions were being marked FAILED (not SKIPPED) when optional native libraries (Capstone, Keystone, Unicorn) were absent, because the checks ran regardless.
  • Fixed all affected tests by wrapping check bodies in else: so they only execute when the library is present.
  • Also fixed an ambiguous symbol error in test_runtime.nim where both runtime and process export attachProcess and related procs -- qualified all calls with runtime. prefix.

Files changed

  • tests/test_assembler.nim - 6 Keystone-dependent tests
  • tests/test_disassembler.nim - 6 Capstone-dependent tests, removed unused requireCapstone template
  • tests/test_emulator.nim - 8 Unicorn-dependent tests
  • tests/test_patcher.nim - 5 Keystone/Unicorn-dependent tests
  • tests/test_runtime.nim - compile error fix: qualify ambiguous proc names with runtime. module prefix

Test plan

  • Build passes: nim c -d:release --path:src -o:nimguard.exe src/nimguard.nim
  • All 9 test suites compile and run with no FAILED results
  • Keystone/Unicorn/Capstone-gated tests show as SKIPPED (not FAILED) when DLLs are absent
  • test_runtime.nim compiles cleanly without ambiguous call error

Nim's skip() template marks a test as SKIPPED but does not stop
execution -- the test body continues running. Tests that called
skip() and then used check() after it were being marked FAILED
rather than SKIPPED when optional native libraries (Capstone,
Keystone, Unicorn) were absent.

Fixed by wrapping the test body in an else branch so checks only
execute when the library is actually available:
  test_assembler.nim   - Keystone-dependent tests (6 tests)
  test_disassembler.nim - Capstone-dependent tests (6 tests), also
                          removed the now-redundant requireCapstone
                          helper template
  test_emulator.nim    - Unicorn-dependent tests (8 tests)
  test_patcher.nim     - Keystone/Unicorn-dependent tests (5 tests)
  test_runtime.nim     - Qualified ambiguous calls (attachProcess,
                          detachProcess, etc.) with runtime. prefix
                          to fix compile error when process module
                          is also imported
@will-bates11 will-bates11 deleted the claude/strange-driscoll branch April 5, 2026 02:25
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