summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Haessle <thomas.haessle@gmail.com>2020-07-05 19:20:11 +0200
committerGitHub <noreply@github.com>2020-07-05 13:20:11 -0400
commit021d82a224ffe6d3bfc4802fe0178c2f0a92f113 (patch)
tree08218a784a250f0a7d64361d2f4fee7053592c2a
parentc6c1bc435d21e2175bf82aa041aacacb4a589c9d (diff)
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>
-rw-r--r--src/modules/nodejs.rs20
-rw-r--r--src/modules/ocaml.rs20
-rw-r--r--src/utils.rs4
3 files changed, 40 insertions, 4 deletions
diff --git a/src/modules/nodejs.rs b/src/modules/nodejs.rs
index e1717a0ac..100717f82 100644
--- a/src/modules/nodejs.rs
+++ b/src/modules/nodejs.rs
@@ -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;
}
@@ -64,6 +69,19 @@ mod tests {
}
#[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()?;
File::create(dir.path().join(".node-version"))?.sync_all()?;
diff --git a/src/modules/ocaml.rs b/src/modules/ocaml.rs
index ad61305cc..be132b0ee 100644
--- a/src/modules/ocaml.rs
+++ b/src/modules/ocaml.rs
@@ -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()
}
diff --git a/src/utils.rs b/src/utils.rs
index ee7af608d..79b8d8835 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -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"),