@@ -510,16 +510,31 @@ end
510510
511511# PR #28038 (prompt/getpass stream args)
512512@test_throws MethodError Base. getpass (IOBuffer (), stdout , " pass" )
513- let buf = IOBuffer ()
514- @test Base. prompt (IOBuffer (" foo\n bar\n " ), buf, " baz" ) == " foo"
515- @test String (take! (buf)) == " baz: "
516- @test Base. prompt (IOBuffer (" \n " ), buf, " baz" , default= " foobar" ) == " foobar"
517- @test String (take! (buf)) == " baz [foobar]: "
518- @test Base. prompt (IOBuffer (" blah\n " ), buf, " baz" , default= " foobar" ) == " blah"
519- take! (buf)
520- # prompt timeout
521- @test Base. prompt (stdin , buf, " baz" , default= " foobar" , timeout = 1 ) == " foobar"
522- @test String (take! (buf)) == " baz [foobar] timeout 1 second: timed out\n "
513+ original_stdin = stdin
514+ try
515+ let buf = IOBuffer ()
516+ @test Base. prompt (IOBuffer (" foo\n bar\n " ), buf, " baz" ) == " foo"
517+ @test String (take! (buf)) == " baz: "
518+ @test Base. prompt (IOBuffer (" \n " ), buf, " baz" , default= " foobar" ) == " foobar"
519+ @test String (take! (buf)) == " baz [foobar]: "
520+ @test Base. prompt (IOBuffer (" blah\n " ), buf, " baz" , default= " foobar" ) == " blah"
521+ take! (buf)
522+ # prompt timeout
523+
524+ (rd, wr) = redirect_stdin ()
525+ @test Base. prompt (rd, buf, " baz" , default= " foobar" , timeout = 1 ) == " foobar"
526+ @test String (take! (buf)) == " baz [foobar] timeout 1 second: timed out\n "
527+ @test Base. prompt (rd, buf, " baz" , default= " foobar" , timeout = 2 ) == " foobar"
528+ @test String (take! (buf)) == " baz [foobar] timeout 2 seconds: timed out\n "
529+ @test Base. prompt (IOBuffer (" foo\n " ), buf, " baz" , default= " foobar" , timeout = 1 ) == " foo"
530+ @test String (take! (buf)) == " baz [foobar] timeout 1 second: "
531+ @test Base. prompt (IOBuffer (" \n " ), buf, " baz" , default= " foobar" , timeout = 1 ) == " foobar"
532+ @test String (take! (buf)) == " baz [foobar] timeout 1 second: "
533+ end
534+ catch
535+ rethrow ()
536+ finally
537+ redirect_stdin (original_stdin)
523538end
524539
525540# these tests are not in a test block so that they will compile separately
0 commit comments