Skip to content

Commit

Permalink
fix timeout tests
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Apr 6, 2021
1 parent 782c1ac commit 90a2bed
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -510,16 +510,31 @@ end

# PR #28038 (prompt/getpass stream args)
@test_throws MethodError Base.getpass(IOBuffer(), stdout, "pass")
let buf = IOBuffer()
@test Base.prompt(IOBuffer("foo\nbar\n"), buf, "baz") == "foo"
@test String(take!(buf)) == "baz: "
@test Base.prompt(IOBuffer("\n"), buf, "baz", default="foobar") == "foobar"
@test String(take!(buf)) == "baz [foobar]: "
@test Base.prompt(IOBuffer("blah\n"), buf, "baz", default="foobar") == "blah"
take!(buf)
# prompt timeout
@test Base.prompt(stdin, buf, "baz", default="foobar", timeout = 1) == "foobar"
@test String(take!(buf)) == "baz [foobar] timeout 1 second: timed out\n"
original_stdin = stdin
try
let buf = IOBuffer()
@test Base.prompt(IOBuffer("foo\nbar\n"), buf, "baz") == "foo"
@test String(take!(buf)) == "baz: "
@test Base.prompt(IOBuffer("\n"), buf, "baz", default="foobar") == "foobar"
@test String(take!(buf)) == "baz [foobar]: "
@test Base.prompt(IOBuffer("blah\n"), buf, "baz", default="foobar") == "blah"
take!(buf)
# prompt timeout

(rd, wr) = redirect_stdin()
@test Base.prompt(rd, buf, "baz", default="foobar", timeout = 1) == "foobar"
@test String(take!(buf)) == "baz [foobar] timeout 1 second: timed out\n"
@test Base.prompt(rd, buf, "baz", default="foobar", timeout = 2) == "foobar"
@test String(take!(buf)) == "baz [foobar] timeout 2 seconds: timed out\n"
@test Base.prompt(IOBuffer("foo\n"), buf, "baz", default="foobar", timeout = 1) == "foo"
@test String(take!(buf)) == "baz [foobar] timeout 1 second: "
@test Base.prompt(IOBuffer("\n"), buf, "baz", default="foobar", timeout = 1) == "foobar"
@test String(take!(buf)) == "baz [foobar] timeout 1 second: "
end
catch
rethrow()
finally
redirect_stdin(original_stdin)
end

# these tests are not in a test block so that they will compile separately
Expand Down

0 comments on commit 90a2bed

Please sign in to comment.