Skip to content

Commit 1f89123

Browse files
authored
Nested cmd config file test (#124)
1 parent d7e139e commit 1f89123

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

tests/config_files/nested_cmd.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
outer-arg = "toml outer-arg"
2+
outerCmd1 = { outer-arg1 = "toml outer-arg1", innerCmd1 = { inner-arg1 = "toml inner-arg1" }, innerCmd2 = { inner-arg2 = "toml inner-arg2" } }

tests/test_nested_cmd.nim

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@
77
# This file may not be copied, modified, or distributed except according to
88
# those terms.
99

10-
import unittest2, ../confutils
10+
import std/os, unittest2, toml_serialization, ../confutils
11+
12+
const configFilePath = "tests" / "config_files"
13+
14+
template loadFile(T, file): untyped =
15+
proc (
16+
config: T, sources: ref SecondarySources
17+
) {.raises: [ConfigurationError].} =
18+
sources.addConfigFile(Toml, InputFile(configFilePath / file))
1119

1220
type
1321
OuterCmd = enum
@@ -103,3 +111,38 @@ suite "test nested cmd default args":
103111
conf.innerCmd == InnerCmd.innerCmd2
104112
conf.outerArg1 == "outerArg1 default"
105113
conf.innerArg2 == "innerArg2 default"
114+
115+
suite "test nested cmd toml":
116+
test "no command default":
117+
let conf = TestConf.load(secondarySources = loadFile(TestConf, "nested_cmd.toml"))
118+
check:
119+
conf.cmd == OuterCmd.noCommand
120+
conf.outerArg == "toml outer-arg"
121+
122+
test "subcommand outerCmd1 innerCmd1":
123+
let conf = TestConf.load(
124+
secondarySources = loadFile(TestConf, "nested_cmd.toml"),
125+
cmdLine = @[
126+
"outerCmd1",
127+
"innerCmd1"
128+
]
129+
)
130+
check:
131+
conf.cmd == OuterCmd.outerCmd1
132+
conf.innerCmd == InnerCmd.innerCmd1
133+
conf.outerArg1 == "toml outer-arg1"
134+
conf.innerArg1 == "toml inner-arg1"
135+
136+
test "subcommand outerCmd1 innerCmd2":
137+
let conf = TestConf.load(
138+
secondarySources = loadFile(TestConf, "nested_cmd.toml"),
139+
cmdLine = @[
140+
"outerCmd1",
141+
"innerCmd2"
142+
]
143+
)
144+
check:
145+
conf.cmd == OuterCmd.outerCmd1
146+
conf.innerCmd == InnerCmd.innerCmd2
147+
conf.outerArg1 == "toml outer-arg1"
148+
conf.innerArg2 == "toml inner-arg2"

0 commit comments

Comments
 (0)