Open haxscramper opened 2 years ago
Reasoning for why this is important:
There are many ideas of what we could change or where to go next, but those are often poorly thoughtout. The sheer volume of what we don't know about the existing system, good or bad, is so large we're working in the dark. This is a blindspot induced by the current state of the code base.
What we do know, with great certainty, is that we need tests that not only test things but also:
Going through the exercise of improving tests will address the blindspot and is going to teach all of us where to go next and which ideas are more likely to get us there.
Another example of tests that we do not want to see - https://github.com/nim-lang/Nim/blob/788cf426123e00a7879dbd9fc765cefb08bd3ddc/tests/overload/tprefer_tygenericinst.nim#L25-L46
# bug #2219
template testPred(a: untyped) =
block:
type A = object of RootObj
type B = object of A
type SomeA = A|A # A hack to make "A" a typeclass.
when a >= 3:
proc p[X: A](x: X) =
echo "This has the highest precedence."
when a == 2:
proc p[X: SomeA](x: X) =
echo "This has the second-highest precedence."
when a >= 1:
proc p[X](x: X) =
echo "This has the lowest precedence."
p(B())
testPred(3)
testPred(2)
testPred(1)
It uses templates, generics, when
, typeclasses, compile-time evaluation, echo
. The when
code is also irregular, it does >=, ==, >=
so it took a while to understand how it is going to be properly expanded. Ideally, this should be rewritten into
type
A = object of RootObj
B = object of A
SomeA = A | A
block:
proc p[X: A](x: X): string = "highest"
proc p[X](x: X): string = "lowest"
doAssert p(B()) == "highest"
block:
proc p[X: SomeA](x: X): string = "second-lowest"
proc p[X](x: X): string = "lowest"
doAssert p(B()) == "second-lowest"
block:
proc p[X](x: X): string = "lowest"
doAssert p(B()) == "lowest"
No templates, no echo
, when
etc. It is a question whether this piece of code tests exactly the same thing that was tested originally, but it is hard to answer because the previous test is all over the place.
There is a change they were attempting to ensure that compile time comparisons work, but that should work because we should test the VM more directly, imo.
File is placed in the tests/overloads/...
not tests/language_parts_integration/...
. Either way it is an example of what we need to remove, or split into meaningful parts, or call this an integration test and not "overloading".
Testing VM separately is a good idea
Instead of just "exactly" I should've said "exactly the same set of properties of the overload resolution"
File is placed in the
tests/overloads/...
nottests/language_parts_integration/...
. Either way it is an example of what we need to remove, or split into meaningful parts, or call this an integration test and not "overloading".
Yeah, it's messy. I totally missed the directory structure, I'm just used to most tests not using that meaningfully, can't wait for that habit to break.
Testing VM separately is a good idea
I know someone who is interested in pursuing this, will see if I can get them excited, started, and unblocked.
Instead of just "exactly" I should've said "exactly the same set of properties of the overload resolution"
From context and rereading I see what you meant, good point.
misc/trunner.nim
must be split into several smaller test files they could be ran separately. Right now failure in a single assert fails whole test, and it is hard to spot what went wrongtshould_fail
must be removed and replaced with collection of smaller tests that test testament binary directly (it's output, exit codes and so on)
Moved to documentation https://nim-works.github.io/nimskull/contributing.html#writing-or-improving-tests
Original issue description