summaryrefslogtreecommitdiff
path: root/AK/Tests/TestFormat.cpp
diff options
context:
space:
mode:
authorasynts <asynts@gmail.com>2020-10-15 13:46:00 +0200
committerAndreas Kling <kling@serenityos.org>2020-10-17 23:20:31 +0200
commit0508fdbbcd82deeec23cdbe5ccf139b84da21d10 (patch)
tree35c91eabccdfc25e967480b34298a793f6b86aeb /AK/Tests/TestFormat.cpp
parenta274a8e5a079c105ee070efd0f90cdc6d9e95847 (diff)
downloadserenity-0508fdbbcd82deeec23cdbe5ccf139b84da21d10.zip
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.
Diffstat (limited to 'AK/Tests/TestFormat.cpp')
-rw-r--r--AK/Tests/TestFormat.cpp21
1 files changed, 21 insertions, 0 deletions
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<u8, 256> 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)