You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2024/09/14 14:01:15 UTC

(couchdb) branch main updated: Quote QuickJS path

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/main by this push:
     new 9ba4d31e5 Quote QuickJS path
9ba4d31e5 is described below

commit 9ba4d31e56dacf253e5ce1fa8051eacea6728cc0
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Sat Sep 14 07:42:36 2024 -0400

    Quote QuickJS path
    
    We used to quote the spawnkiller path like this to handle spaces in paths:
    
    ```
     "\"" ++ filename:join(PrivDir, "couchspawnkillable") ++ "\""
    ```
    
    So we stick with the same pattern here as well for QuickJS path.
---
 src/couch_quickjs/src/couch_quickjs.erl        |  4 ++--
 src/couch_quickjs/test/couch_quickjs_tests.erl | 18 +++++++++---------
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/couch_quickjs/src/couch_quickjs.erl b/src/couch_quickjs/src/couch_quickjs.erl
index 94307f667..8c7a22570 100644
--- a/src/couch_quickjs/src/couch_quickjs.erl
+++ b/src/couch_quickjs/src/couch_quickjs.erl
@@ -26,12 +26,12 @@
 mainjs_cmd() ->
     Path = filename:join([priv_dir(), "couchjs_mainjs" ++ ext()]),
     check_path(Path),
-    apply_config(Path).
+    apply_config("\"" ++ Path ++ "\"").
 
 coffee_cmd() ->
     Path = filename:join([priv_dir(), "couchjs_coffee" ++ ext()]),
     check_path(Path),
-    apply_config(Path).
+    apply_config("\"" ++ Path ++ "\"").
 
 priv_dir() ->
     case code:priv_dir(couch_quickjs) of
diff --git a/src/couch_quickjs/test/couch_quickjs_tests.erl b/src/couch_quickjs/test/couch_quickjs_tests.erl
index c29172e1c..b1089e3e5 100644
--- a/src/couch_quickjs/test/couch_quickjs_tests.erl
+++ b/src/couch_quickjs/test/couch_quickjs_tests.erl
@@ -36,13 +36,11 @@ quickjs_test_() ->
 
 t_get_mainjs_cmd(_) ->
     Cmd = couch_quickjs:mainjs_cmd(),
-    ?assert(filelib:is_file(Cmd)),
-    ?assertEqual("quickjs", os_cmd(Cmd ++ " -V")).
+    ?assertEqual(0, os_cmd(Cmd ++ " -V")).
 
 t_get_coffee_cmd(_) ->
     Cmd = couch_quickjs:coffee_cmd(),
-    ?assert(filelib:is_file(Cmd)),
-    ?assertEqual("quickjs", os_cmd(Cmd ++ " -V")).
+    ?assertEqual(0, os_cmd(Cmd ++ " -V")).
 
 t_can_configure_memory_limit(_) ->
     Limit = integer_to_list(4 * 1024 * 1024),
@@ -51,7 +49,7 @@ t_can_configure_memory_limit(_) ->
     ?assert(is_list(Cmd)),
     Expect = "-M " ++ Limit,
     ?assertEqual(Expect, string:find(Cmd, Expect)),
-    ?assertEqual("quickjs", os_cmd(Cmd ++ " -V")).
+    ?assertEqual(0, os_cmd(Cmd ++ " -V")).
 
 t_bad_memory_limit(_) ->
     Limit = integer_to_list(42),
@@ -60,9 +58,11 @@ t_bad_memory_limit(_) ->
     ?assert(is_list(Cmd)),
     ExpectCmd = "-M " ++ Limit,
     ?assertEqual(ExpectCmd, string:find(Cmd, ExpectCmd)),
-    Res = os_cmd(Cmd ++ " -V"),
-    ExpectRes = "Invalid stack size",
-    ?assertEqual(ExpectRes, string:find(Res, ExpectRes)).
+    ?assertEqual(1, os_cmd(Cmd ++ " -V")).
 
 os_cmd(Cmd) ->
-    string:trim(os:cmd(Cmd)).
+    Opts = [stream, {line, 4096}, binary, exit_status, hide],
+    Port = open_port({spawn, Cmd}, Opts),
+    receive
+        {Port, {exit_status, Status}} -> Status
+    end.