Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 9727a9b

Browse files
committed
[[ Bug ]] Fix failing LCB varargs test on Linux
This patch fixes the LCB varargs tests on Linux. The test was failing due to the assumption that the %p printf format would render a nullptr as 0x0 as it does on macOS - this was an incorrect assumption. To resolve this, the varargs tests have been restructured, with the nullptr test being separated out. Rather than check for a specific output string, it just checks it begins with the known string (the issue was a crash, so the only thing which needs to be checked is that the crash doesn't happen!).
1 parent f57e6a3 commit 9727a9b

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

tests/lcb/vm/foreign-invoke.lcb

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,46 @@ foreign handler sprintf(in pTarget as Pointer, in pFormat as ZStringNative, ...)
2626
foreign handler MCStringCreateWithCString(in pCString as Pointer, out rString as String) returns CBool binds to "<builtin>"
2727

2828
public handler TestForeignInvoke_Varargs()
29-
variable tString1 as String
30-
variable tString2 as String
29+
variable tOutputBuffer as Pointer
3130
unsafe
32-
variable tOutputBuffer as Pointer
3331
put malloc(4096) into tOutputBuffer
32+
end unsafe
3433

34+
variable tString1 as String
35+
unsafe
3536
sprintf(tOutputBuffer, "no formats")
3637
MCStringCreateWithCString(tOutputBuffer, tString1)
38+
end unsafe
39+
test "sprintf works with no variadic arguments" when tString1 is "no formats"
3740

41+
variable tString2 as String
42+
unsafe
3843
variable tInt as SInt16
3944
variable tLong as SInt32
4045
variable tLongLong as SInt64
4146
variable tFloat as CFloat
4247
variable tDouble as CDouble
43-
variable tNothing as optional Pointer
4448
put 1000 into tInt
4549
put 1000000000 into tLong
4650
put tLong * 1000000 into tLongLong
4751
put 3.5 into tFloat
4852
put 7.5 into tDouble
49-
sprintf(tOutputBuffer, "%d %ld %lld %.1f %.1lf %p", tInt, tLong, tLongLong, tFloat, tDouble, tNothing)
53+
sprintf(tOutputBuffer, "%d %ld %lld %.1f %.1lf", tInt, tLong, tLongLong, tFloat, tDouble)
5054
MCStringCreateWithCString(tOutputBuffer, tString2)
55+
end unsafe
56+
test "sprintf works with variadic arguments" when tString2 is "1000 1000000000 1000000000000000 3.5 7.5"
57+
58+
variable tString3 as String
59+
unsafe
60+
variable tNothing as optional Pointer
61+
sprintf(tOutputBuffer, "nullptr %p", tNothing)
62+
MCStringCreateWithCString(tOutputBuffer, tString3)
63+
end unsafe
64+
test "sprintf works with nullptr variadic argument" when tString3 begins with "nullptr "
5165

66+
unsafe
5267
free(tOutputBuffer)
5368
end unsafe
54-
test "sprintf works with no variadic arguments" when tString1 is "no formats"
55-
test "sprintf works with variadic arguments" when tString2 is "1000 1000000000 1000000000000000 3.5 7.5 0x0"
5669
end handler
5770

5871
--------

0 commit comments

Comments
 (0)