mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-28 15:56:28 +00:00
fix: manage sandboxed version of OCaml (#1433)
* fix: manage sandboxed version of OCaml * fmt: apply cargo fmt Co-authored-by: Thomas Haesslé <thaessle@cutii.io>
This commit is contained in:
parent
c6c1bc435d
commit
021d82a224
@ -18,7 +18,12 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
.set_folders(&["node_modules"])
|
||||
.is_match();
|
||||
|
||||
if !is_js_project {
|
||||
let is_esy_project = context
|
||||
.try_begin_scan()?
|
||||
.set_folders(&["esy.lock"])
|
||||
.is_match();
|
||||
|
||||
if !is_js_project || is_esy_project {
|
||||
return None;
|
||||
}
|
||||
|
||||
@ -63,6 +68,19 @@ mod tests {
|
||||
dir.close()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn folder_with_package_json_and_esy_lock() -> io::Result<()> {
|
||||
let dir = tempfile::tempdir()?;
|
||||
File::create(dir.path().join("package.json"))?.sync_all()?;
|
||||
let esy_lock = dir.path().join("esy.lock");
|
||||
fs::create_dir_all(&esy_lock)?;
|
||||
|
||||
let actual = render_module("nodejs", dir.path(), None);
|
||||
let expected = None;
|
||||
assert_eq!(expected, actual);
|
||||
dir.close()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn folder_with_node_version() -> io::Result<()> {
|
||||
let dir = tempfile::tempdir()?;
|
||||
|
@ -24,7 +24,17 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
return None;
|
||||
}
|
||||
|
||||
let ocaml_version = utils::exec_cmd("ocaml", &["-vnum"])?.stdout;
|
||||
let is_esy_project = context
|
||||
.try_begin_scan()?
|
||||
.set_folders(&["esy.lock"])
|
||||
.is_match();
|
||||
|
||||
let ocaml_version = if is_esy_project {
|
||||
utils::exec_cmd("esy", &["ocaml", "-vnum"])?.stdout
|
||||
} else {
|
||||
utils::exec_cmd("ocaml", &["-vnum"])?.stdout
|
||||
};
|
||||
|
||||
let formatted_version = format!("v{}", &ocaml_version);
|
||||
|
||||
let mut module = context.new_module("ocaml");
|
||||
@ -79,9 +89,13 @@ mod tests {
|
||||
fn folder_with_esy_lock_directory() -> io::Result<()> {
|
||||
let dir = tempfile::tempdir()?;
|
||||
fs::create_dir_all(dir.path().join("esy.lock"))?;
|
||||
|
||||
File::create(dir.path().join("package.json"))?.sync_all()?;
|
||||
fs::write(
|
||||
dir.path().join("package.lock"),
|
||||
"{\"dependencies\": {\"ocaml\": \"4.8.1000\"}}",
|
||||
)?;
|
||||
let actual = render_module("ocaml", dir.path(), None);
|
||||
let expected = Some(format!("via {} ", Color::Yellow.bold().paint("🐫 v4.10.0")));
|
||||
let expected = Some(format!("via {} ", Color::Yellow.bold().paint("🐫 v4.08.1")));
|
||||
assert_eq!(expected, actual);
|
||||
dir.close()
|
||||
}
|
||||
|
@ -87,6 +87,10 @@ active boot switches: -d:release\n",
|
||||
stdout: String::from("4.10.0"),
|
||||
stderr: String::default(),
|
||||
}),
|
||||
"esy ocaml -vnum" => Some(CommandOutput {
|
||||
stdout: String::from("4.08.1"),
|
||||
stderr: String::default(),
|
||||
}),
|
||||
"php -nr echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION.'.'.PHP_RELEASE_VERSION;" => {
|
||||
Some(CommandOutput {
|
||||
stdout: String::from("7.3.8"),
|
||||
|
Loading…
Reference in New Issue
Block a user