pathsd/tests/pathsd/test_main.nim

53 lines
1.3 KiB
Nim

import std/[logging, paths]
import unittest
import ../../src/pathsd
suite "Test main() proc":
setup:
const fixturesPath = Path(currentSourcePath) / Path("..") / Path("..") / Path("fixtures")
const pathsdFixturePath = fixturesPath / Path("paths.d")
const envParts = @["/usr/local/bin", "/usr/bin"]
const expectedOutput = @[
"/Users/bilbo/opt/bin", "/opt/homebrew/bin", "/opt/homebrew/sbin",
"/usr/local/bin", "/usr/bin",
]
pathsd.logger.levelThreshold = lvlNone
test "Test happy path":
# When
var mainResult = pathsd.main(@[pathsdFixturePath.string], envParts, false)
# Then
check mainResult.output == expectedOutput
check mainResult.errorCode == QuitSuccess
test "Test skipping search paths that don't exist":
# When
var mainResult = pathsd.main(
@[
pathsdFixturePath.string,
(fixturesPath / Path("idontexist")).string,
],
envParts,
false,
)
# Then
check mainResult.output == expectedOutput
test "Test dedupe":
# Given
const localEnvParts = @[
"/usr/local/bin", "/usr/bin", "/Users/bilbo/opt/bin",
]
# When
var mainResult = pathsd.main(
@[pathsdFixturePath.string], localEnvParts, true,
)
# Then
check mainResult.output == expectedOutput