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.
diff --git a/src/couch_quickjs/src/couch_quickjs.erl b/src/couch_quickjs/src/couch_quickjs.erl
index 94307f6..8c7a225 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 c29172e..b1089e3 100644
--- a/src/couch_quickjs/test/couch_quickjs_tests.erl
+++ b/src/couch_quickjs/test/couch_quickjs_tests.erl
@@ -36,13 +36,11 @@
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 @@
?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 @@
?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.