fix(simu): reset error bits on stream after incomplete read (#6566)

This commit is contained in:
Raphael Coeffic
2025-09-02 09:52:20 +10:00
committed by GitHub
parent 7230b26dc3
commit ac0acbec97
2 changed files with 24 additions and 0 deletions
+23
View File
@@ -27,6 +27,8 @@
#include "edgetx.h"
#include "lua/lua_states.h"
#include <filesystem>
#define MIXSRC_THR (MIXSRC_FIRST_STICK + inputMappingGetThrottle())
#define MIXSRC_TRIMTHR (MIXSRC_FIRST_TRIM + inputMappingGetThrottle())
@@ -220,4 +222,25 @@ TEST(Lua, testLegacyNames)
#endif
}
TEST(Lua, ioSeek)
{
const char io_seek_tst[] =
"local file_name = \"seek-test.txt\"\n"
"local file = io.open(file_name, \"w\")\n"
"io.write(file, \"abcd\")\n"
"io.close(file)\n"
"file = io.open(file_name, \"r\")\n"
// the file should have 4 characters
"assert(#io.read(file, 32) == 4)\n"
// io.seek() should return 0 if it is successful
"assert(io.seek(file, 2) == 0)\n"
"local r = io.read(file, 32)\n"
// if reading from position 2,
// we should read 2 characters,
"assert(#r == 2)\n";
luaExecStr(io_seek_tst);
std::filesystem::remove(simuFatfsGetRealPath("seek-test.txt"));
}
#endif // #if defined(LUA)