-
Notifications
You must be signed in to change notification settings - Fork 16
Fix #62; Add obsolete pragma
#136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
505e61e
Fix #62; Add `obsolete` pragma
nitely 76de130
oops
nitely ff7ca81
better test
nitely e047658
oops
nitely 0cdc6b7
wip
nitely aafa4d3
fix old nim
nitely 51f323a
tests
nitely 13fe57f
test msg
nitely File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,3 +9,4 @@ tests/test_nested_cmd | |
| tests/test_help | ||
| tests/test_argument | ||
| tests/test_parsecmdarg | ||
| tests/test_obsolete | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| import | ||
| unittest2, | ||
| ../confutils | ||
|
|
||
| type | ||
| TestConf = object | ||
| opt1 {. | ||
| obsolete | ||
| defaultValue: "opt1 default" | ||
| name: "opt1"}: string | ||
|
|
||
| #let conf = TestConf.load() | ||
| #echo conf.opt1 | ||
|
|
||
| suite "test obsolete option": | ||
| test "obsolete option default": | ||
| let conf = TestConf.load() | ||
| check conf.opt1 == "opt1 default" | ||
|
|
||
| test "obsolete option set": | ||
| let conf = TestConf.load(cmdLine = @[ | ||
| "--opt1=foo" | ||
| ]) | ||
| check conf.opt1 == "foo" | ||
|
|
||
| type | ||
| OverloadConf = object | ||
| opt1 {. | ||
| obsolete | ||
| defaultValue: "opt1 default" | ||
| name: "opt1"}: string | ||
| opt2 {. | ||
| obsolete | ||
| defaultValue: "opt2 default" | ||
| name: "opt2"}: string | ||
| opt3 {. | ||
| obsolete: "opt3 obsolete msg" | ||
| defaultValue: "opt3 default" | ||
| name: "opt3"}: string | ||
| opt4 {. | ||
| defaultValue: "opt4 default" | ||
| name: "opt4"}: string | ||
|
|
||
| var registry {.threadvar.}: seq[string] | ||
|
|
||
| proc obsoleteCmdOpt(T: type OverloadConf, opt, msg: string) = | ||
| registry.add opt | ||
| if msg.len > 0: | ||
| registry.add msg | ||
|
|
||
| suite "test obsolete option overload": | ||
| test "the overload is called if opt is set": | ||
| registry.setLen 0 | ||
| let conf = OverloadConf.load(cmdLine = @[ | ||
| "--opt1=foo" | ||
| ]) | ||
| check conf.opt1 == "foo" | ||
| check registry == @["opt1"] | ||
|
|
||
| test "the overload is not called if opt not set": | ||
| registry.setLen 0 | ||
| let conf = OverloadConf.load() | ||
| check conf.opt1 == "opt1 default" | ||
| check registry.len == 0 | ||
|
|
||
| test "the overload is called for all obsolete opts set": | ||
| registry.setLen 0 | ||
| let conf = OverloadConf.load(cmdLine = @[ | ||
| "--opt1=foo", | ||
| "--opt2=bar" | ||
| ]) | ||
| check conf.opt1 == "foo" | ||
| check conf.opt2 == "bar" | ||
| check registry == @["opt1", "opt2"] | ||
|
|
||
| test "the overload is called with obsolete msg": | ||
| registry.setLen 0 | ||
| let conf = OverloadConf.load(cmdLine = @[ | ||
| "--opt3=foo" | ||
| ]) | ||
| check conf.opt3 == "foo" | ||
| check registry == @["opt3", "opt3 obsolete msg"] | ||
|
|
||
| test "the logger setup is called": | ||
| proc loggerSetup(c: OverloadConf) = | ||
| doAssert c.opt1 == "opt1 default" | ||
| registry.add "logger" | ||
|
|
||
| registry.setLen 0 | ||
| let conf = OverloadConf.load(loggerSetup = loggerSetup) | ||
| check conf.opt1 == "opt1 default" | ||
| check registry == @["logger"] | ||
|
|
||
| test "the logger setup is called before the overload": | ||
| proc loggerSetup(c: OverloadConf) = | ||
| doAssert c.opt1 == "foo" | ||
| registry.add "logger" | ||
|
|
||
| registry.setLen 0 | ||
| let conf = OverloadConf.load( | ||
| cmdLine = @[ | ||
| "--opt1=foo" | ||
| ], | ||
| loggerSetup = loggerSetup | ||
| ) | ||
| check conf.opt1 == "foo" | ||
| check registry == @["logger", "opt1"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import | ||
| unittest2, | ||
| ../confutils, | ||
| ./test_obsolete_overload_def | ||
|
|
||
| type | ||
| TestConf = object | ||
| opt1 {. | ||
| obsolete | ||
| defaultValue: "opt1 default" | ||
| name: "opt1"}: string | ||
|
|
||
| suite "test obsolete overload for type": | ||
| test "obsolete option default": | ||
| registry.setLen 0 | ||
| let conf = TestConf.load() | ||
| check conf.opt1 == "opt1 default" | ||
| check registry.len == 0 | ||
|
|
||
| test "obsolete option set": | ||
| registry.setLen 0 | ||
| let conf = TestConf.load(cmdLine = @[ | ||
| "--opt1=foo" | ||
| ]) | ||
| check conf.opt1 == "foo" | ||
| check registry == @["opt1"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
|
|
||
| # this is in its own module to test there | ||
| # is no ambiguous (import) call error for obsoleteCmdOpt | ||
|
|
||
| var registry* {.threadvar.}: seq[string] | ||
|
|
||
| proc obsoleteCmdOpt*(T: type[object], opt, msg: string) = | ||
| registry.add opt |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.