Skip to content

Commit 2de9242

Browse files
Add test for FS::open("w+") (#7241)
Verify that a file is truncated on opening with w+ even if no data is written to it, for all FSes. Co-authored-by: Develo <deveyes@gmail.com>
1 parent 368ca91 commit 2de9242

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tests/host/fs/test_fs.inc

+13
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,19 @@ TEST_CASE(TESTPRE "truncate", TESTPAT)
161161
REQUIRE( s == "some" );
162162
}
163163

164+
TEST_CASE(TESTPRE "open(w+) truncates file", TESTPAT)
165+
{
166+
FS_MOCK_DECLARE(64, 8, 512, "");
167+
REQUIRE(FSTYPE.begin());
168+
createFile("/file1", "some text");
169+
String s = readFile("/file1");
170+
REQUIRE( s == "some text");
171+
auto f = FSTYPE.open("/file1", "w+");
172+
f.close();
173+
String t = readFile("/file1");
174+
REQUIRE( t == "");
175+
}
176+
164177
#ifdef FS_HAS_DIRS
165178

166179
#if FSTYPE != SDFS

0 commit comments

Comments
 (0)