From 52a89a515ed44d861ea556a0bb70d6901660a9b5 Mon Sep 17 00:00:00 2001 From: David Knaack Date: Sun, 7 Jul 2024 16:15:56 +0200 Subject: [PATCH] fix(dotnet): Remove duplicate v in dotnet version (#6060) * Remove duplicate `v` in dotnet version Every language version provider returns the version without a leading 'v', and the shared code then prepends the 'v'. Take a look at Python for example. The Dotnet provider prepends a 'v' however, causing the version to be printed like 'vv8.0.203'. * Update src/modules/dotnet.rs * tests(dotnet): add test for obtaining version from cli --------- Co-authored-by: Bernd Verst --- src/modules/dotnet.rs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/modules/dotnet.rs b/src/modules/dotnet.rs index cdbb3f69..a0304d78 100644 --- a/src/modules/dotnet.rs +++ b/src/modules/dotnet.rs @@ -294,7 +294,7 @@ fn map_str_to_lower(value: Option<&OsStr>) -> Option { fn get_version_from_cli(context: &Context) -> Option { let version_output = context.exec_cmd("dotnet", &["--version"])?; - Some(format!("v{}", version_output.stdout.trim())) + Some(version_output.stdout.trim().to_string()) } fn get_latest_sdk_from_cli(context: &Context) -> Option { @@ -356,6 +356,7 @@ mod tests { use std::fs::{self, OpenOptions}; use std::io::{self, Write}; use tempfile::{self, TempDir}; + use utils::{write_file, CommandOutput}; #[test] fn shows_nothing_in_directory_with_zero_relevant_files() -> io::Result<()> { @@ -553,6 +554,36 @@ mod tests { workspace.close() } + #[test] + fn version_from_dotnet_cli() -> io::Result<()> { + let dir = tempfile::tempdir()?; + write_file(dir.path().join("main.cs"), "")?; + + let expected = Some(format!( + "via {}", + Color::Blue.bold().paint(".NET v8.0.301 ") + )); + let actual = ModuleRenderer::new("dotnet") + .path(dir.path()) + .cmd( + "dotnet --version", + Some(CommandOutput { + stdout: "8.0.301\n".to_string(), + stderr: String::new(), + }), + ) + .config(toml::toml! { + [dotnet] + heuristic = false + detect_extensions = ["cs"] + }) + .collect(); + + assert_eq!(expected, actual); + + dir.close() + } + fn create_workspace(is_repo: bool) -> io::Result { let repo_dir = tempfile::tempdir()?;