Skip to content

Commit

Permalink
Add test for FS::open("w+") (#7241)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
earlephilhower and devyte committed Apr 23, 2020
1 parent 368ca91 commit 2de9242
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/host/fs/test_fs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2de9242

Please sign in to comment.