Open timotheecour opened 3 years ago
<>
, not ""
:func builtin_rotl8(value: cuchar, shift: cint): cuchar {.importc: "__rolb", header: "x86intrin.h".}
=>
func builtin_rotl8(value: cuchar, shift: cint): cuchar {.importc: "__rolb", header: "<x86intrin.h>".}
func rotl[T: SomeUnsignedInt](value: T, rot: int32): T {.inline.} =
## Left-rotate bits in a `SomeUnsignedInt` value.
=>
## Left-rotate bits in `value`.
all tests run under a single main template:
discard """
targets: "c js"
"""
template main =
block: # foo
doAssert foo(1) == 1
doAssert foo(1, 2) == 3
block: # bar
doAssert bar()
doAssert not compiles(bar("abc"))
block: # bug #1234
...
static: main()
main()
block: # foo
instead of block foo:
; in particular when testing for a symbol foo
block foo:
should only be used if the code refers to foo
as a block label (eg via break foo
);
nim might in future issue warnings for labels without code referring to it
inline definitions of variables used only once, eg:
let
a = some(42)
b = none(int)
c = some(-11)
assert a.flatMap(doublePositives) == some(84)
assert b.flatMap(doublePositives) == none(int)
assert c.flatMap(doublePositives) == none(int)
=>
assert some(42).flatMap(doublePositives) == some(84)
assert none(int).flatMap(doublePositives) == none(int)
assert some(-11).flatMap(doublePositives) == none(int)
it results in more readable tests where all the context is in 1 line
function tested goes on LHS for clarity:
assert {true, false} == fullSet(bool)
=>
assert fullSet(bool) == {true, false}
# bad:
assert bounds.a <= bounds.b, " bounds b should be larger or equal to bounds.b"
=>
# good:
assert bounds.a <= bounds.b
the 1st form shows:
/t11954.nim(13, 10) `bounds.a <= bounds.b` bounds b should be larger or equal to bounds.b [AssertionDefect]
the 2nd shows:
t11954.nim(13, 10) `bounds.a <= bounds.b` [AssertionDefect]
which has exactly the same information. Simpler is better, both for reading and writing code and for developpers who will encounter this error msg.
Currently assert
+ friends (unlike unittest.check
) doesn't show runtime values on an assertion failure, but in future this could be implemented at least for the most common cases, controlled by a flag, maybe --errorcontexts:on
.
Until then, to show runtime values on errors, we need:
assert bounds.a <= bounds.b, $(bounds.a, bounds.b)
this shows:
t11954.nim(13, 10) `bounds.a <= bounds.b` (4, 3) [AssertionDefect]
which is IMO perfectly readable, especially if this becomes a pattern; simplicity wins here. We could also introduce a reusable helper macro to format those, eg:
assert bounds.a <= bounds.b, prettyMsg(bounds.a, bounds.b)
which would then show:
t11954.nim(13, 10) `bounds.a <= bounds.b` (bounds.a: 4, bounds.b: 3) [AssertionDefect]
Port(8800)
, etc), it leads to flaky tests; instead use Port(0)
+ getPort
refs https://github.com/nim-lang/Nim/pull/14327, https://github.com/nim-lang/Nim/pull/17559
either read github docs on how to do this, or do the following to avoid lots of conflicts:
before changing back target branch to devel, do this:
import stdtest/specialpaths; const dir = buildDir
) or in getTempDir()
rationale:
links
TODO