Skip to content

Commit

Permalink
tests/llvm: Don't check newline encoding in the printf test (#2691)
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Vesely <[email protected]>
  • Loading branch information
jvesely authored Jun 7, 2023
1 parent 1582baa commit ec00465
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions tests/llvm/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ def test_helper_all_close(mode, var1, var2, atol, rtol):
(pnlvm.ir.DoubleType(), "%lf", [x *.5 for x in range(0, 5)]),
], ids=["i32", "i64", "double"])
def test_helper_printf(capfd, ir_argtype, format_spec, values_to_check):
format_str = f"Hello {(format_spec+' ')*len(values_to_check)} \n"

format_str = f"Hello {(format_spec + ' ') * len(values_to_check)}\n"

with pnlvm.LLVMBuilderContext.get_current() as ctx:
func_ty = ir.FunctionType(ir.VoidType(), [])
ir_values_to_check = [ir_argtype(i) for i in values_to_check]
Expand All @@ -242,18 +244,20 @@ def test_helper_printf(capfd, ir_argtype, format_spec, values_to_check):
builder.ret_void()

bin_f = pnlvm.LLVMBinaryFunction.get(custom_name)


bin_f()

# Printf is buffered in libc.
libc = ctypes.util.find_library("msvcrt" if sys.platform == "win32" else "c")
libc = ctypes.CDLL(libc)
libc.fflush(0)

# Convert format specifier to Python compatible
python_format_spec = {"%lld":"%ld"}.get(format_spec, format_spec)
python_format_str = f"Hello {(python_format_spec+' ')*len(values_to_check)} \n"
assert capfd.readouterr().out == python_format_str % tuple(values_to_check)

# The string below omits the newline character used above and the check below
# uses 'startswith' to avoid issues with different newline encoding across OSes.
python_format_str = f"Hello {(python_format_spec + ' ') * len(values_to_check)}"
assert capfd.readouterr().out.startswith(python_format_str % tuple(values_to_check))

class TestHelperTypegetters:
FLOAT_TYPE = pnlvm.ir.FloatType()
Expand Down

0 comments on commit ec00465

Please sign in to comment.