|
7 | 7 | # This file may not be copied, modified, or distributed except according to |
8 | 8 | # those terms. |
9 | 9 |
|
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)) |
11 | 19 |
|
12 | 20 | type |
13 | 21 | OuterCmd = enum |
@@ -103,3 +111,38 @@ suite "test nested cmd default args": |
103 | 111 | conf.innerCmd == InnerCmd.innerCmd2 |
104 | 112 | conf.outerArg1 == "outerArg1 default" |
105 | 113 | 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