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.tar.gz luasystem-06c186da3c9108c9d0378e25a18bc6f605d43644.tar.bz2 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() | |||
| 106 | 106 | ||
| 107 | 107 | ||
| 108 | 108 | ||
| 109 | pending("getconsoleflags()", function() | 109 | describe("getconsoleflags()", function() |
| 110 | |||
| 111 | pending("returns the consoleflags, if called without flags", function() | ||
| 112 | print"1" | ||
| 113 | package.loaded["system"] = nil | ||
| 114 | package.loaded["system.core"] = nil | ||
| 115 | print"2" | ||
| 116 | local system = require "system" | ||
| 117 | print"3" | ||
| 118 | for k,v in pairs(system) do print(k,v) end | ||
| 119 | for k,v in pairs(debug.getinfo(system.isatty)) do print(k,v) end | ||
| 120 | 110 | ||
| 111 | win_it("returns the consoleflags #manual", function() | ||
| 121 | local flags, err = system.getconsoleflags(io.stdin) | 112 | local flags, err = system.getconsoleflags(io.stdin) |
| 122 | assert.is_nil(err) | 113 | assert.is_nil(err) |
| 123 | assert.is_integer(flags) | 114 | assert.is_userdata(flags) |
| 115 | assert.equals("bitflags:", tostring(flags):sub(1,9)) | ||
| 116 | end) | ||
| 117 | |||
| 118 | |||
| 119 | nix_it("returns the consoleflags, as value 0", function() | ||
| 120 | local flags, err = system.getconsoleflags(io.stdin) | ||
| 121 | assert.is_nil(err) | ||
| 122 | assert.is_userdata(flags) | ||
| 123 | assert.equals("bitflags:", tostring(flags):sub(1,9)) | ||
| 124 | assert.equals(0, flags:value()) | ||
| 125 | end) | ||
| 126 | |||
| 127 | |||
| 128 | it("returns an error if called with an invalid argument", function() | ||
| 129 | assert.has.error(function() | ||
| 130 | system.getconsoleflags("invalid") | ||
| 131 | end, "bad argument #1 to 'getconsoleflags' (FILE* expected, got string)") | ||
| 124 | end) | 132 | end) |
| 125 | 133 | ||
| 126 | end) | 134 | end) |
| @@ -309,6 +309,7 @@ static HANDLE get_console_handle(lua_State *L, int flags_optional) | |||
| 309 | // Lua error if the file is not one of these. | 309 | // Lua error if the file is not one of these. |
| 310 | static int get_console_handle(lua_State *L) | 310 | static int get_console_handle(lua_State *L) |
| 311 | { | 311 | { |
| 312 | printf("get_console_handle\n"); | ||
| 312 | FILE **file = (FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE); | 313 | FILE **file = (FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE); |
| 313 | if (file == NULL || *file == NULL) { | 314 | if (file == NULL || *file == NULL) { |
| 314 | return luaL_argerror(L, 1, "expected file handle"); // call doesn't return | 315 | return luaL_argerror(L, 1, "expected file handle"); // call doesn't return |
| @@ -375,9 +376,12 @@ static int lst_setconsoleflags(lua_State *L) | |||
| 375 | return 2; | 376 | return 2; |
| 376 | } | 377 | } |
| 377 | 378 | ||
| 378 | #endif | 379 | #else |
| 379 | lua_pushboolean(L, 1); | 380 | get_console_handle(L); // to validate args |
| 381 | lua_pushboolean(L, 1); // always return true on Posix | ||
| 380 | return 1; | 382 | return 1; |
| 383 | |||
| 384 | #endif | ||
| 381 | } | 385 | } |
| 382 | 386 | ||
| 383 | 387 | ||
| @@ -417,6 +421,8 @@ static int lst_getconsoleflags(lua_State *L) | |||
| 417 | lua_pushliteral(L, "failed to get console mode"); | 421 | lua_pushliteral(L, "failed to get console mode"); |
| 418 | return 2; | 422 | return 2; |
| 419 | } | 423 | } |
| 424 | #else | ||
| 425 | get_console_handle(L); // to validate args | ||
| 420 | 426 | ||
| 421 | #endif | 427 | #endif |
| 422 | lsbf_pushbitflags(L, console_mode); | 428 | lsbf_pushbitflags(L, console_mode); |
