diff options
author | Thijs <thijs@thijsschreijer.nl> | 2024-05-20 12:39:33 +0200 |
---|---|---|
committer | Thijs <thijs@thijsschreijer.nl> | 2024-05-20 14:27:40 +0200 |
commit | 06c186da3c9108c9d0378e25a18bc6f605d43644 (patch) | |
tree | 90a3c1a3b71e5a1690eecfdf4435c102c87d769c | |
parent | dcd5d62501e61e0f6901d4d4687ab56430a4b8a7 (diff) | |
download | luasystem-06c186da3c9108c9d0378e25a18bc6f605d43644.zip |
implement getconsoleflags tests
-rw-r--r-- | spec/04-term_spec.lua | 32 | ||||
-rw-r--r-- | src/term.c | 10 |
2 files changed, 28 insertions, 14 deletions
diff --git a/spec/04-term_spec.lua b/spec/04-term_spec.lua index ee4145a..487a0ce 100644 --- a/spec/04-term_spec.lua +++ b/spec/04-term_spec.lua @@ -106,21 +106,29 @@ describe("Terminal:", function() - pending("getconsoleflags()", function() - - pending("returns the consoleflags, if called without flags", function() -print"1" -package.loaded["system"] = nil -package.loaded["system.core"] = nil -print"2" -local system = require "system" -print"3" -for k,v in pairs(system) do print(k,v) end -for k,v in pairs(debug.getinfo(system.isatty)) do print(k,v) end + describe("getconsoleflags()", function() + win_it("returns the consoleflags #manual", function() local flags, err = system.getconsoleflags(io.stdin) assert.is_nil(err) - assert.is_integer(flags) + assert.is_userdata(flags) + assert.equals("bitflags:", tostring(flags):sub(1,9)) + end) + + + nix_it("returns the consoleflags, as value 0", function() + local flags, err = system.getconsoleflags(io.stdin) + assert.is_nil(err) + assert.is_userdata(flags) + assert.equals("bitflags:", tostring(flags):sub(1,9)) + assert.equals(0, flags:value()) + end) + + + it("returns an error if called with an invalid argument", function() + assert.has.error(function() + system.getconsoleflags("invalid") + end, "bad argument #1 to 'getconsoleflags' (FILE* expected, got string)") end) end) @@ -309,6 +309,7 @@ static HANDLE get_console_handle(lua_State *L, int flags_optional) // Lua error if the file is not one of these. static int get_console_handle(lua_State *L) { +printf("get_console_handle\n"); FILE **file = (FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE); if (file == NULL || *file == NULL) { return luaL_argerror(L, 1, "expected file handle"); // call doesn't return @@ -375,9 +376,12 @@ static int lst_setconsoleflags(lua_State *L) return 2; } -#endif - lua_pushboolean(L, 1); +#else + get_console_handle(L); // to validate args + lua_pushboolean(L, 1); // always return true on Posix return 1; + +#endif } @@ -417,6 +421,8 @@ static int lst_getconsoleflags(lua_State *L) lua_pushliteral(L, "failed to get console mode"); return 2; } +#else + get_console_handle(L); // to validate args #endif lsbf_pushbitflags(L, console_mode); |