summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThijs Schreijer <thijs@thijsschreijer.nl>2024-05-22 21:47:25 +0200
committerThijs Schreijer <thijs@thijsschreijer.nl>2024-05-22 21:47:25 +0200
commit34e1632092d1a9695b539d0244ce948194ed76c9 (patch)
treeb0569e3c2cf051069e385cbfa8f8e31e6b6fa712
parent2746189f0a504d5929f8aa69edcc116dbbeff105 (diff)
downloadluasystem-34e1632092d1a9695b539d0244ce948194ed76c9.zip
add tests for get/setnonblock
-rw-r--r--spec/04-term_spec.lua46
1 files changed, 42 insertions, 4 deletions
diff --git a/spec/04-term_spec.lua b/spec/04-term_spec.lua
index eb975b5..c649579 100644
--- a/spec/04-term_spec.lua
+++ b/spec/04-term_spec.lua
@@ -306,18 +306,56 @@ describe("Terminal:", function()
- pending("getnonblock()", function()
+ describe("getnonblock()", function()
- pending("sets the consoleflags, if called with flags", function()
+ nix_it("gets the non-blocking flag", function()
+ local nb, err = system.getnonblock(io.stdin)
+ assert.is_nil(err)
+ assert.is_boolean(nb)
+ end)
+
+ win_it("gets the non-blocking flag, always false", function()
+ local nb, err = system.getnonblock(io.stdin)
+ assert.is_nil(err)
+ assert.is_false(nb)
end)
end)
- pending("setnonblock()", function()
+ describe("setnonblock()", function()
- pending("sets the consoleflags, if called with flags", function()
+ nix_it("sets the non-blocking flag", function()
+ local old_nb = system.getnonblock(io.stdin)
+ assert.is.boolean(old_nb)
+
+ finally(function()
+ system.setnonblock(io.stdin, old_nb) -- ensure we restore the original one
+ end)
+
+ local new_nb = not old_nb
+
+ local success, err = system.setnonblock(io.stdin, new_nb)
+ assert.is_nil(err)
+ assert.is_true(success)
+
+ local updated_nb = assert(system.getnonblock(io.stdin))
+ assert.equals(new_nb, updated_nb)
+ end)
+
+
+ win_it("sets the non-blocking flag, always succeeds", function()
+ local success, err = system.setnonblock(io.stdin, true)
+ assert.is_nil(err)
+ assert.is_true(success)
+ end)
+
+
+ it("returns an error if called with an invalid argument", function()
+ assert.has.error(function()
+ system.setnonblock("invalid")
+ end, "bad argument #1 to 'setnonblock' (FILE* expected, got string)")
end)
end)