Skip to content

Commit 827f32b

Browse files
try tests without redirect_stdin
1 parent ce8de24 commit 827f32b

File tree

1 file changed

+23
-35
lines changed

1 file changed

+23
-35
lines changed

test/misc.jl

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -510,41 +510,29 @@ end
510510

511511
# PR #28038 (prompt/getpass stream args)
512512
@test_throws MethodError Base.getpass(IOBuffer(), stdout, "pass")
513-
original_stdin = stdin
514-
try
515-
let buf = IOBuffer()
516-
(rd, wr) = redirect_stdin()
517-
print(wr, "foo\nbar\n")
518-
@test Base.prompt(rd, buf, "baz") == "foo"
519-
@test String(take!(buf)) == "baz: "
520-
readavailable(rd)
521-
print(wr, "\n")
522-
@test Base.prompt(rd, buf, "baz", default="foobar") == "foobar"
523-
@test String(take!(buf)) == "baz [foobar]: "
524-
print(wr, "blah\n")
525-
@test Base.prompt(rd, buf, "baz", default="foobar") == "blah"
526-
take!(buf)
527-
# prompt timeout
528-
529-
@test Base.prompt(rd, buf, "baz", default="foobar", timeout = 1) == "foobar"
530-
@test String(take!(buf)) == "baz [foobar] timeout 1 second: timed out\n"
531-
@test Base.prompt(rd, buf, "baz", default="foobar", timeout = 2) == "foobar"
532-
@test String(take!(buf)) == "baz [foobar] timeout 2 seconds: timed out\n"
533-
print(wr, "foo\n")
534-
@test Base.prompt(rd, buf, "baz", default="foobar", timeout = 1) == "foo"
535-
@test String(take!(buf)) == "baz [foobar] timeout 1 second: "
536-
print(wr, "\n")
537-
@test Base.prompt(rd, buf, "baz", default="foobar", timeout = 1) == "foobar"
538-
@test String(take!(buf)) == "baz [foobar] timeout 1 second: "
539-
end
540-
catch
541-
rethrow()
542-
finally
543-
try
544-
redirect_stdin(original_stdin)
545-
catch ex
546-
@error "Could not redirect back to stdin" ex
547-
end
513+
let buf = IOBuffer()
514+
write(stdin.buffer, "foo\nbar\n")
515+
@test Base.prompt(stdin, buf, "baz") == "foo"
516+
@test String(take!(buf)) == "baz: "
517+
readavailable(stdin)
518+
write(stdin.buffer, "\n")
519+
@test Base.prompt(stdin, buf, "baz", default="foobar") == "foobar"
520+
@test String(take!(buf)) == "baz [foobar]: "
521+
write(stdin.buffer, "blah\n")
522+
@test Base.prompt(stdin, buf, "baz", default="foobar") == "blah"
523+
take!(buf)
524+
# prompt timeout
525+
526+
@test Base.prompt(stdin, buf, "baz", default="foobar", timeout = 1) == "foobar"
527+
@test String(take!(buf)) == "baz [foobar] timeout 1 second: timed out\n"
528+
@test Base.prompt(stdin, buf, "baz", default="foobar", timeout = 2) == "foobar"
529+
@test String(take!(buf)) == "baz [foobar] timeout 2 seconds: timed out\n"
530+
write(stdin.buffer, "foo\n")
531+
@test Base.prompt(stdin, buf, "baz", default="foobar", timeout = 1) == "foo"
532+
@test String(take!(buf)) == "baz [foobar] timeout 1 second: "
533+
write(stdin.buffer, "\n")
534+
@test Base.prompt(stdin, buf, "baz", default="foobar", timeout = 1) == "foobar"
535+
@test String(take!(buf)) == "baz [foobar] timeout 1 second: "
548536
end
549537

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

0 commit comments

Comments
 (0)