diff options
author | Arne Döring <arne.doering@gmx.net> | 2019-03-06 08:12:16 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-03-06 08:12:16 +0100 |
commit | 2c01f0ad8d1e321e608acc9e939afa99ed4c2250 (patch) | |
tree | 9a66234a35d733481952ca0a1de34af3a4ea8132 /tests | |
parent | 63c847dc50cbf292629d8d7f72f0570b9f109b0c (diff) | |
download | Nim-2c01f0ad8d1e321e608acc9e939afa99ed4c2250.tar.gz |
tsizeof test is now correct (#10788)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/misc/tsizeof.nim | 63 |
1 files changed, 47 insertions, 16 deletions
diff --git a/tests/misc/tsizeof.nim b/tests/misc/tsizeof.nim index c56e08062..c53cfb676 100644 --- a/tests/misc/tsizeof.nim +++ b/tests/misc/tsizeof.nim @@ -1,5 +1,9 @@ discard """ - output: "OK" + output: ''' +body executed +body executed +OK +''' """ type @@ -138,15 +142,41 @@ type ValueA ValueB -template testinstance(body: untyped): untyped = - block: - {.pragma: objectconfig.} - body - block: - {.pragma: objectconfig, packed.} - body +proc transformObjectconfigPacked(arg: NimNode): NimNode = + let debug = arg.kind == nnkPragmaExpr + if arg.eqIdent("objectconfig"): + result = ident"packed" + else: + result = copyNimNode(arg) + for child in arg: + result.add transformObjectconfigPacked(child) + +proc removeObjectconfig(arg: NimNode): NimNode = + if arg.kind == nnkPragmaExpr and arg[1][0].eqIdent "objectconfig": + result = arg[0] + else: + result = copyNimNode(arg) + for child in arg: + result.add removeObjectconfig(child) + +macro testinstance(body: untyped): untyped = + let bodyPure = removeObjectconfig(body) + let bodyPacked = transformObjectconfigPacked(body) + + result = quote do: + proc pureblock(): void = + const usePacked {.inject.} = false + `bodyPure` + + pureblock() + + proc packedblock(): void = + const usePacked {.inject.} = true + `bodyPacked` + + packedblock() proc testPrimitiveTypes(): void = testAlign(pointer) @@ -284,13 +314,6 @@ testinstance: a: int32 b: T - #Float128Test = object - # a: byte - # b: float128 - - #Bazang = object of RootObj - # a: float128 - const trivialSize = sizeof(TrivialType) # needs to be able to evaluate at compile time proc main(): void = @@ -314,9 +337,14 @@ testinstance: eoa: EnumObjectA eob: EnumObjectB - testAlign(SimpleAlignment) + # sanity check to ensure both branches are actually executed + when usePacked: + doAssert sizeof(SimpleAlignment) == 10 + else: + doAssert sizeof(SimpleAlignment) > 10 + testSizeAlignOf(t,a,b,c,d,e,f,g,ro,go, e1, e2, e4, e8, eoa, eob) when not defined(cpp): @@ -380,6 +408,9 @@ testinstance: testOffsetOf(RecursiveStuff, d1) testOffsetOf(RecursiveStuff, d2) + echo "body executed" # sanity check to ensure this logic isn't skipped entirely + + main() {.emit: """/*TYPESECTION*/ |