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"])
|
.set_folders(&["node_modules"])
|
||||||
.is_match();
|
.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;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,6 +68,19 @@ mod tests {
|
||||||
dir.close()
|
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]
|
#[test]
|
||||||
fn folder_with_node_version() -> io::Result<()> {
|
fn folder_with_node_version() -> io::Result<()> {
|
||||||
let dir = tempfile::tempdir()?;
|
let dir = tempfile::tempdir()?;
|
||||||
|
|
|
@ -24,7 +24,17 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||||
return None;
|
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 formatted_version = format!("v{}", &ocaml_version);
|
||||||
|
|
||||||
let mut module = context.new_module("ocaml");
|
let mut module = context.new_module("ocaml");
|
||||||
|
@ -79,9 +89,13 @@ mod tests {
|
||||||
fn folder_with_esy_lock_directory() -> io::Result<()> {
|
fn folder_with_esy_lock_directory() -> io::Result<()> {
|
||||||
let dir = tempfile::tempdir()?;
|
let dir = tempfile::tempdir()?;
|
||||||
fs::create_dir_all(dir.path().join("esy.lock"))?;
|
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 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);
|
assert_eq!(expected, actual);
|
||||||
dir.close()
|
dir.close()
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,6 +87,10 @@ active boot switches: -d:release\n",
|
||||||
stdout: String::from("4.10.0"),
|
stdout: String::from("4.10.0"),
|
||||||
stderr: String::default(),
|
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;" => {
|
"php -nr echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION.'.'.PHP_RELEASE_VERSION;" => {
|
||||||
Some(CommandOutput {
|
Some(CommandOutput {
|
||||||
stdout: String::from("7.3.8"),
|
stdout: String::from("7.3.8"),
|
||||||
|
|
Loading…
Reference in New Issue