aboutsummaryrefslogtreecommitdiff
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.tar.gz
luasystem-34e1632092d1a9695b539d0244ce948194ed76c9.tar.bz2
luasystem-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()
306 306
307 307
308 308
309 pending("getnonblock()", function() 309 describe("getnonblock()", function()
310 310
311 pending("sets the consoleflags, if called with flags", function() 311 nix_it("gets the non-blocking flag", function()
312 local nb, err = system.getnonblock(io.stdin)
313 assert.is_nil(err)
314 assert.is_boolean(nb)
315 end)
316
317 win_it("gets the non-blocking flag, always false", function()
318 local nb, err = system.getnonblock(io.stdin)
319 assert.is_nil(err)
320 assert.is_false(nb)
312 end) 321 end)
313 322
314 end) 323 end)
315 324
316 325
317 326
318 pending("setnonblock()", function() 327 describe("setnonblock()", function()
319 328
320 pending("sets the consoleflags, if called with flags", function() 329 nix_it("sets the non-blocking flag", function()
330 local old_nb = system.getnonblock(io.stdin)
331 assert.is.boolean(old_nb)
332
333 finally(function()
334 system.setnonblock(io.stdin, old_nb) -- ensure we restore the original one
335 end)
336
337 local new_nb = not old_nb
338
339 local success, err = system.setnonblock(io.stdin, new_nb)
340 assert.is_nil(err)
341 assert.is_true(success)
342
343 local updated_nb = assert(system.getnonblock(io.stdin))
344 assert.equals(new_nb, updated_nb)
345 end)
346
347
348 win_it("sets the non-blocking flag, always succeeds", function()
349 local success, err = system.setnonblock(io.stdin, true)
350 assert.is_nil(err)
351 assert.is_true(success)
352 end)
353
354
355 it("returns an error if called with an invalid argument", function()
356 assert.has.error(function()
357 system.setnonblock("invalid")
358 end, "bad argument #1 to 'setnonblock' (FILE* expected, got string)")
321 end) 359 end)
322 360
323 end) 361 end)