mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-12-29 04:23:26 +00:00
fix(dart): detect version output in stdout with dart 2.15+ (#3349)
This commit is contained in:
parent
10e8912159
commit
8d0cebdcbd
@ -3,6 +3,7 @@ use super::{Context, Module, RootModuleConfig};
|
||||
use crate::configs::dart::DartConfig;
|
||||
use crate::formatter::StringFormatter;
|
||||
use crate::formatter::VersionFormatter;
|
||||
use crate::utils::get_command_string_output;
|
||||
|
||||
/// Creates a module with the current Dart version
|
||||
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
@ -32,8 +33,8 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
})
|
||||
.map(|variable| match variable {
|
||||
"version" => {
|
||||
let dart_version =
|
||||
parse_dart_version(&context.exec_cmd("dart", &["--version"])?.stderr)?;
|
||||
let command = context.exec_cmd("dart", &["--version"])?;
|
||||
let dart_version = parse_dart_version(&get_command_string_output(command))?;
|
||||
VersionFormatter::format_module_version(
|
||||
module.get_name(),
|
||||
&dart_version,
|
||||
@ -71,6 +72,7 @@ fn parse_dart_version(dart_version: &str) -> Option<String> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::test::ModuleRenderer;
|
||||
use crate::utils::CommandOutput;
|
||||
use ansi_term::Color;
|
||||
use std::fs::{self, File};
|
||||
use std::io;
|
||||
@ -138,4 +140,25 @@ mod tests {
|
||||
assert_eq!(expected, actual);
|
||||
dir.close()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn detect_version_output_in_stdout() -> io::Result<()> {
|
||||
// after dart 2.15.0, version info output in stdout.
|
||||
let dir = tempfile::tempdir()?;
|
||||
File::create(dir.path().join("any.dart"))?.sync_all()?;
|
||||
|
||||
let actual = ModuleRenderer::new("dart")
|
||||
.cmd(
|
||||
"dart --version",
|
||||
Some(CommandOutput {
|
||||
stdout: String::from("Dart SDK version: 2.15.1 (stable) (Tue Dec 14 13:32:21 2021 +0100) on \"linux_x64\""),
|
||||
stderr: String::default(),
|
||||
}),
|
||||
)
|
||||
.path(dir.path())
|
||||
.collect();
|
||||
let expected = Some(format!("via {}", Color::Blue.bold().paint("🎯 v2.15.1 ")));
|
||||
assert_eq!(expected, actual);
|
||||
dir.close()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user