-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nimsuggest test template def and fixture refactor
- Loading branch information
Showing
5 changed files
with
29 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
# Template for testing defs | ||
|
||
template doAssertish*(cond: untyped, msg: string = "") = | ||
## template to allow def lookup testing | ||
if not cond: quit() |
This file contains 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 |
---|---|---|
@@ -1,12 +1,15 @@ | ||
# Creates an awkward set of dependencies between this, import, and include. | ||
# This pattern appears in the compiler, compiler/(sem|ast|semexprs).nim. | ||
|
||
import massertish | ||
import minclude_types | ||
|
||
proc say*(g: Greet): string = | ||
doAssertish(true, "always works") | ||
g.greeting & ", " & g.subject & "!" | ||
|
||
include minclude_include | ||
|
||
proc say*(): string = | ||
doAssertish(1 + 1 == 2, "math works") | ||
say(create()) |
8 changes: 8 additions & 0 deletions
8
nimsuggest/tests/mdot4_strutils.nim → nimsuggest/tests/mstrutils.nim
This file contains 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 |
---|---|---|
@@ -1,11 +1,19 @@ | ||
import massertish | ||
|
||
func rereplace*(s, sub: string; by: string = ""): string {.used.} = | ||
## competes for priority in suggestion, here first, but never used in test | ||
|
||
doAssertish(true, "always works") | ||
result = by | ||
|
||
func replace*(s, sub: string; by: string = ""): string = | ||
## this is a test version of strutils.replace, it simply returns `by` | ||
|
||
doAssertish("".len == 0, "empty string is empty") | ||
result = by | ||
|
||
func rerereplace*(s, sub: string; by: string = ""): string {.used.} = | ||
## isn't used and appears last, lowest priority | ||
|
||
doAssertish(false, "never works") | ||
result = by |
This file contains 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 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 |
---|---|---|
@@ -1,17 +1,11 @@ | ||
import mstrutils | ||
|
||
discard """ | ||
$nimsuggest --tester lib/pure/strutils.nim | ||
>def lib/pure/strutils.nim:2022:8 | ||
def;;skTemplate;;assertions.doAssert;;template (cond: untyped, msg: string);;*lib/system/assertions.nim;;58;;9;;"Similar to ``assert`` but is always turned on*";;100 | ||
$nimsuggest --tester $file | ||
>def $path/mstrutils.nim:6:4 | ||
def;;skTemplate;;massertish.doAssertish;;template (cond: untyped, msg: string);;*/massertish.nim;;3;;9;;"template to allow def lookup testing";;100 | ||
>def $path/mstrutils.nim:12:3 | ||
def;;skTemplate;;massertish.doAssertish;;template (cond: untyped, msg: string);;*/massertish.nim;;3;;9;;"template to allow def lookup testing";;100 | ||
>def $path/mstrutils.nim:18:12 | ||
def;;skTemplate;;massertish.doAssertish;;template (cond: untyped, msg: string);;*/massertish.nim;;3;;9;;"template to allow def lookup testing";;100 | ||
""" | ||
|
||
# Line 2022 in strutils.nim is doAssert and this is unlikely to change | ||
# soon since there are a whole lot of doAsserts there. | ||
|
||
#[ | ||
Notes: | ||
* metamorphic testing or propery based testing might suit nimsuggest better | ||
* easier option is to isolate the dependency with test modules | ||
Open Questions: | ||
* Why not use unit tests or code fixtures for these tests? | ||
]# |