nim-ffi/tests/unit/test_main_prefix_validation.nim
2026-07-10 16:49:07 -03:00

24 lines
1.1 KiB
Nim

import std/[os, strutils]
import unittest2
# The validation only fires when --nimMainPrefix is on the command line, so we
# capture a real `nim check` of the fixture at this test's compile time.
# `mainprefix_fixture.nim` deliberately lacks the `test_` prefix so the nimble
# runner never compiles it standalone.
const
nimExe = getCurrentCompilerExe()
fixture = currentSourcePath.parentDir / "mainprefix_fixture.nim"
checkCmd = nimExe & " check --hints:off --colors:off "
wrongPrefixOutput = staticExec(checkCmd & "--nimMainPrefix:libWRONG " & fixture)
rightPrefixOutput = staticExec(checkCmd & "--nimMainPrefix:libmpfixture " & fixture)
suite "compile-time --nimMainPrefix validation":
test "a mismatched prefix errors and names the expected flag":
check "Error:" in wrongPrefixOutput
# naming the expected flag is what distinguishes our error from any other
# compile failure, so assert on it rather than the bare "Error:".
check "needs --nimMainPrefix:libmpfixture" in wrongPrefixOutput
test "the matching prefix compiles without error":
check "Error:" notin rightPrefixOutput