Skip to content

Commit

Permalink
try tests without redirect_stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Apr 15, 2021
1 parent ce8de24 commit 827f32b
Showing 1 changed file with 23 additions and 35 deletions.
58 changes: 23 additions & 35 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -510,41 +510,29 @@ end

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

@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"
print(wr, "foo\n")
@test Base.prompt(rd, buf, "baz", default="foobar", timeout = 1) == "foo"
@test String(take!(buf)) == "baz [foobar] timeout 1 second: "
print(wr, "\n")
@test Base.prompt(rd, buf, "baz", default="foobar", timeout = 1) == "foobar"
@test String(take!(buf)) == "baz [foobar] timeout 1 second: "
end
catch
rethrow()
finally
try
redirect_stdin(original_stdin)
catch ex
@error "Could not redirect back to stdin" ex
end
let buf = IOBuffer()
write(stdin.buffer, "foo\nbar\n")
@test Base.prompt(stdin, buf, "baz") == "foo"
@test String(take!(buf)) == "baz: "
readavailable(stdin)
write(stdin.buffer, "\n")
@test Base.prompt(stdin, buf, "baz", default="foobar") == "foobar"
@test String(take!(buf)) == "baz [foobar]: "
write(stdin.buffer, "blah\n")
@test Base.prompt(stdin, 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"
@test Base.prompt(stdin, buf, "baz", default="foobar", timeout = 2) == "foobar"
@test String(take!(buf)) == "baz [foobar] timeout 2 seconds: timed out\n"
write(stdin.buffer, "foo\n")
@test Base.prompt(stdin, buf, "baz", default="foobar", timeout = 1) == "foo"
@test String(take!(buf)) == "baz [foobar] timeout 1 second: "
write(stdin.buffer, "\n")
@test Base.prompt(stdin, buf, "baz", default="foobar", timeout = 1) == "foobar"
@test String(take!(buf)) == "baz [foobar] timeout 1 second: "
end

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

0 comments on commit 827f32b

Please sign in to comment.