mirror of
https://github.com/starship/starship.git
synced 2026-06-21 02:02:14 +07:00
chore: add const for 500ms (#7125)
This commit is contained in:
+2
-2
@@ -1,5 +1,5 @@
|
||||
use crate::shadow;
|
||||
use crate::utils::{self, exec_cmd};
|
||||
use crate::utils::{self, DEFAULT_COMMAND_TIMEOUT_MS, exec_cmd};
|
||||
use nu_ansi_term::Style;
|
||||
|
||||
use std::fs;
|
||||
@@ -250,7 +250,7 @@ fn get_starship_config() -> String {
|
||||
}
|
||||
|
||||
fn get_shell_version(shell: &str) -> String {
|
||||
let time_limit = Duration::from_millis(500);
|
||||
let time_limit = Duration::from_millis(DEFAULT_COMMAND_TIMEOUT_MS);
|
||||
match shell {
|
||||
"powershell" => exec_cmd(
|
||||
shell,
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
}
|
||||
} else {
|
||||
log::warn!(
|
||||
"`threshold` in [jobs] is deprecated . Please remove it and use `symbol_threshold` and `number_threshold`."
|
||||
"`threshold` in [jobs] is deprecated. Please remove it and use `symbol_threshold` and `number_threshold`."
|
||||
);
|
||||
|
||||
// The symbol should be shown if there are *any* background
|
||||
|
||||
+26
-8
@@ -10,6 +10,9 @@ use std::time::{Duration, Instant};
|
||||
use crate::context::Context;
|
||||
use crate::context::Shell;
|
||||
|
||||
/// Default timeout for command execution in milliseconds
|
||||
pub const DEFAULT_COMMAND_TIMEOUT_MS: u64 = 500;
|
||||
|
||||
/// Create a `PathBuf` from an absolute path, where the root directory will be mocked in test
|
||||
#[cfg(not(test))]
|
||||
#[inline]
|
||||
@@ -824,7 +827,7 @@ mod tests {
|
||||
let result = exec_cmd(
|
||||
"dummy_command",
|
||||
&[] as &[&OsStr],
|
||||
Duration::from_millis(500),
|
||||
Duration::from_millis(DEFAULT_COMMAND_TIMEOUT_MS),
|
||||
);
|
||||
let expected = Some(CommandOutput {
|
||||
stdout: String::from("stdout ok!\n"),
|
||||
@@ -840,7 +843,11 @@ mod tests {
|
||||
#[test]
|
||||
#[cfg(not(windows))]
|
||||
fn exec_no_output() {
|
||||
let result = internal_exec_cmd("true", &[] as &[&OsStr], Duration::from_millis(500));
|
||||
let result = internal_exec_cmd(
|
||||
"true",
|
||||
&[] as &[&OsStr],
|
||||
Duration::from_millis(DEFAULT_COMMAND_TIMEOUT_MS),
|
||||
);
|
||||
let expected = Some(CommandOutput {
|
||||
stdout: String::new(),
|
||||
stderr: String::new(),
|
||||
@@ -852,8 +859,11 @@ mod tests {
|
||||
#[test]
|
||||
#[cfg(not(windows))]
|
||||
fn exec_with_output_stdout() {
|
||||
let result =
|
||||
internal_exec_cmd("/bin/sh", &["-c", "echo hello"], Duration::from_millis(500));
|
||||
let result = internal_exec_cmd(
|
||||
"/bin/sh",
|
||||
&["-c", "echo hello"],
|
||||
Duration::from_millis(DEFAULT_COMMAND_TIMEOUT_MS),
|
||||
);
|
||||
let expected = Some(CommandOutput {
|
||||
stdout: String::from("hello\n"),
|
||||
stderr: String::new(),
|
||||
@@ -868,7 +878,7 @@ mod tests {
|
||||
let result = internal_exec_cmd(
|
||||
"/bin/sh",
|
||||
&["-c", "echo hello >&2"],
|
||||
Duration::from_millis(500),
|
||||
Duration::from_millis(DEFAULT_COMMAND_TIMEOUT_MS),
|
||||
);
|
||||
let expected = Some(CommandOutput {
|
||||
stdout: String::new(),
|
||||
@@ -884,7 +894,7 @@ mod tests {
|
||||
let result = internal_exec_cmd(
|
||||
"/bin/sh",
|
||||
&["-c", "echo hello; echo world >&2"],
|
||||
Duration::from_millis(500),
|
||||
Duration::from_millis(DEFAULT_COMMAND_TIMEOUT_MS),
|
||||
);
|
||||
let expected = Some(CommandOutput {
|
||||
stdout: String::from("hello\n"),
|
||||
@@ -897,7 +907,11 @@ mod tests {
|
||||
#[test]
|
||||
#[cfg(not(windows))]
|
||||
fn exec_with_non_zero_exit_code() {
|
||||
let result = internal_exec_cmd("false", &[] as &[&OsStr], Duration::from_millis(500));
|
||||
let result = internal_exec_cmd(
|
||||
"false",
|
||||
&[] as &[&OsStr],
|
||||
Duration::from_millis(DEFAULT_COMMAND_TIMEOUT_MS),
|
||||
);
|
||||
let expected = None;
|
||||
|
||||
assert_eq!(result, expected);
|
||||
@@ -906,7 +920,11 @@ mod tests {
|
||||
#[test]
|
||||
#[cfg(not(windows))]
|
||||
fn exec_slow_command() {
|
||||
let result = internal_exec_cmd("sleep", &["500"], Duration::from_millis(500));
|
||||
let result = internal_exec_cmd(
|
||||
"sleep",
|
||||
&["500"],
|
||||
Duration::from_millis(DEFAULT_COMMAND_TIMEOUT_MS),
|
||||
);
|
||||
let expected = None;
|
||||
|
||||
assert_eq!(result, expected);
|
||||
|
||||
Reference in New Issue
Block a user