diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-03-28 17:49:00 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-28 21:49:00 +0000 |
commit | 6fb6b0c1f302e8637c96131c9ffc4c4b9f3f5f0f (patch) | |
tree | dff55c1b345f317ebd3ec5a3b62c26ed27d5830c /runtime/permissions/prompter.rs | |
parent | c65149c0a072fa710098b14776c6cd3cc8a204d6 (diff) |
chore: restore pty tests and make them run on the Linux CI (#18424)
1. Rewrites the tests to be more back and forth rather than getting the
output all at once (which I believe was causing the hangs on linux and
maybe mac)
2. Runs the pty tests on the linux ci.
3. Fixes a bunch of tests that were just wrong.
4. Adds timeouts on the pty tests.
Diffstat (limited to 'runtime/permissions/prompter.rs')
-rw-r--r-- | runtime/permissions/prompter.rs | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/runtime/permissions/prompter.rs b/runtime/permissions/prompter.rs index d94264b1a..502771636 100644 --- a/runtime/permissions/prompter.rs +++ b/runtime/permissions/prompter.rs @@ -4,10 +4,11 @@ use crate::colors; use deno_core::error::AnyError; use deno_core::parking_lot::Mutex; use once_cell::sync::Lazy; +use std::fmt::Write; /// Helper function to strip ansi codes and ASCII control characters. fn strip_ansi_codes_and_ascii_control(s: &str) -> std::borrow::Cow<str> { - console_static_text::strip_ansi_codes(s) + console_static_text::ansi::strip_ansi_codes(s) .chars() .filter(|c| !c.is_ascii_control()) .collect() @@ -221,17 +222,25 @@ impl PermissionPrompter for TtyPrompter { } else { "[y/n] (y = yes, allow; n = no, deny)".to_string() }; - eprint!("┌ {PERMISSION_EMOJI} "); - eprint!("{}", colors::bold("Deno requests ")); - eprint!("{}", colors::bold(message.clone())); - eprintln!("{}", colors::bold(".")); - if let Some(api_name) = api_name.clone() { - eprintln!("├ Requested by `{api_name}` API"); + + // output everything in one shot to make the tests more reliable + { + let mut output = String::new(); + write!(&mut output, "┌ {PERMISSION_EMOJI} ").unwrap(); + write!(&mut output, "{}", colors::bold("Deno requests ")).unwrap(); + write!(&mut output, "{}", colors::bold(message.clone())).unwrap(); + writeln!(&mut output, "{}", colors::bold(".")).unwrap(); + if let Some(api_name) = api_name.clone() { + writeln!(&mut output, "├ Requested by `{api_name}` API.").unwrap(); + } + let msg = format!("Run again with --allow-{name} to bypass this prompt."); + writeln!(&mut output, "├ {}", colors::italic(&msg)).unwrap(); + write!(&mut output, "└ {}", colors::bold("Allow?")).unwrap(); + write!(&mut output, " {opts} > ").unwrap(); + + eprint!("{}", output); } - let msg = format!("Run again with --allow-{name} to bypass this prompt."); - eprintln!("├ {}", colors::italic(&msg)); - eprint!("└ {}", colors::bold("Allow?")); - eprint!(" {opts} > "); + let value = loop { let mut input = String::new(); let stdin = std::io::stdin(); |