Skip to content

Commit

Permalink
Merge pull request #671 from pbialon/fix-path
Browse files Browse the repository at this point in the history
Fixed setting path; removed dummy unit tests
  • Loading branch information
pascalbreuninger authored Sep 1, 2023
2 parents fd32215 + e937e95 commit e3d2393
Showing 1 changed file with 2 additions and 25 deletions.
27 changes: 2 additions & 25 deletions desktop/src-tauri/src/fix_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ fn read_path_env_cmd(shell: String, var_name: String) -> Result<Output, Error> {
.map_err(Error::Shell);
}

fn set_var(env_raw_line: &str) {
let mut s = env_raw_line.splitn(2, '=');
if let (Some(var), Some(value)) = (s.next(), s.next()) {
std::env::set_var(var, value);
}
}

pub fn fix_env(var_name: &str) -> Result<(), Error> {
#[cfg(windows)]
{
Expand All @@ -50,8 +43,8 @@ pub fn fix_env(var_name: &str) -> Result<(), Error> {
if out.status.success() {
let stdout = String::from_utf8_lossy(&out.stdout).into_owned();
let cleaned = &strip_ansi_escapes::strip(stdout)?;
let line = String::from_utf8_lossy(cleaned);
set_var(line.as_ref());
let value = String::from_utf8_lossy(cleaned);
std::env::set_var(var_name, value.as_ref());
Ok(())
} else {
Err(Error::EchoFailed(
Expand All @@ -60,19 +53,3 @@ pub fn fix_env(var_name: &str) -> Result<(), Error> {
}
}
}

#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_fix_env() {
std::env::set_var("_TEST_VARIABLE", "test_value");
assert_eq!(std::env::var("_TEST_VARIABLE").unwrap(), "test_value");
}

#[test]
fn test_fix_env_multiline() {
std::env::set_var("_TEST_VARIABLE", "test_value\nnew_line\nanother_line");
assert_eq!(std::env::var("_TEST_VARIABLE").unwrap(), "test_value\nnew_line\nanother_line");
}
}

0 comments on commit e3d2393

Please sign in to comment.