From 0508fdbbcd82deeec23cdbe5ccf139b84da21d10 Mon Sep 17 00:00:00 2001 From: asynts Date: Thu, 15 Oct 2020 13:46:00 +0200 Subject: AK+Format: Add outln(FILE*, ...) overload. This commit also removes a few functions like raw_out and vwarn. If we want to write raw output, we can do this as follows: out("{}", "Hello, World!"); The vout stuff isn't really public API anyways, so no need for another vwarn. --- AK/Tests/TestFormat.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'AK/Tests/TestFormat.cpp') diff --git a/AK/Tests/TestFormat.cpp b/AK/Tests/TestFormat.cpp index 7d426fb4e1..4f3f9924f3 100644 --- a/AK/Tests/TestFormat.cpp +++ b/AK/Tests/TestFormat.cpp @@ -214,4 +214,25 @@ TEST_CASE(format_if_supported) EXPECT_EQ(String::formatted("{}", FormatIfSupported { B {} }), "B"); } +TEST_CASE(file_descriptor) +{ + char filename[] = "/tmp/test-file-descriptor-XXXXXX"; + + int fd = mkstemp(filename); + FILE* file = fdopen(fd, "w+"); + + outln(file, "{}", "Hello, World!"); + new_out(file, "foo"); + outln(file, "bar"); + + rewind(file); + + Array buffer; + const auto nread = fread(buffer.data(), 1, buffer.size(), file); + + EXPECT_EQ(StringView { "Hello, World!\nfoobar\n" }, StringView { buffer.span().trim(nread) }); + + fclose(file); +} + TEST_MAIN(Format) -- cgit v1.2.3