From ba3d5ca6a002a32086dea33a367cf7d9c11abda6 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Wed, 22 Apr 2020 10:24:10 -0700 Subject: [PATCH] Add test for FS::open("w+") Verify that a file is truncated on opening with w+ even if no data is written to it, for all FSes. --- tests/host/fs/test_fs.inc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/host/fs/test_fs.inc b/tests/host/fs/test_fs.inc index e6bedfa181..9a10e688f4 100644 --- a/tests/host/fs/test_fs.inc +++ b/tests/host/fs/test_fs.inc @@ -161,6 +161,19 @@ TEST_CASE(TESTPRE "truncate", TESTPAT) REQUIRE( s == "some" ); } +TEST_CASE(TESTPRE "open(w+) truncates file", TESTPAT) +{ + FS_MOCK_DECLARE(64, 8, 512, ""); + REQUIRE(FSTYPE.begin()); + createFile("/file1", "some text"); + String s = readFile("/file1"); + REQUIRE( s == "some text"); + auto f = FSTYPE.open("/file1", "w+"); + f.close(); + String t = readFile("/file1"); + REQUIRE( t == ""); +} + #ifdef FS_HAS_DIRS #if FSTYPE != SDFS