]> git.kaiwu.me - njs.git/commitdiff
Fixed njs_run expect tests.
authorDmitry Volyntsev <xeioex@nginx.com>
Fri, 14 Jun 2019 18:20:25 +0000 (21:20 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Fri, 14 Jun 2019 18:20:25 +0000 (21:20 +0300)
Using exec instead of spawn to get the njs output
synchronously.

njs/njs_shell.c
njs/test/njs_expect_test.exp

index b2f7d49cfec99813f186d90258dc6f4d8b01f07c..706c4111717d80301b219bdfe4c72ef8236f7f4e 100644 (file)
@@ -327,7 +327,7 @@ njs_get_options(njs_opts_t *opts, int argc, char** argv)
         switch (*p) {
         case '?':
         case 'h':
-            (void) write(STDIN_FILENO, help, nxt_length(help));
+            (void) write(STDOUT_FILENO, help, nxt_length(help));
             return ret;
 
         case 'c':
index b29203022bf54a8965fd68739eec455800badc87..351981a270b939870bf98ab0e2ffdfa8c12a0b46 100644 (file)
@@ -42,9 +42,11 @@ type console.help() for more information\r
     expect eof
 }
 
-proc njs_run {opts output} {
-    eval spawn  -nottycopy njs $opts
-    expect -re $output
+proc njs_run {opts expected_re} {
+    catch {exec njs {*}$opts} out
+    if {[regexp $expected_re $out match] == 0} {
+        return -code error "njs_run: unexpected output '$out' vs '$expected_re'"
+    }
 }
 
 njs_test {
@@ -625,35 +627,36 @@ njs_test {
 
 # Modules
 
-njs_run "-p njs/test/module/libs ./njs/test/module/normal.js" \
+njs_run {"-p" "njs/test/module/libs" "./njs/test/module/normal.js"} \
         "passed!"
 
-njs_run "-p njs/test/module/libs/ ./njs/test/module/normal.js" \
+njs_run {"-p" "njs/test/module/libs/" "./njs/test/module/normal.js"} \
         "passed!"
 
-njs_run "-p njs/test/module -p njs/test/module/libs ./njs/test/module/normal.js" \
+njs_run {"-p" "njs/test/module" "-p" "njs/test/module/libs" "./njs/test/module/normal.js"} \
         "passed!"
 
-njs_run "./njs/test/module/normal.js" \
+njs_run {"./njs/test/module/normal.js"} \
         "SyntaxError: Cannot find module \"hash.js\" in sub2.js:5"
 
-njs_run "-p njs/test/module/libs ./njs/test/module/exception.js" \
-        "at error \\(sub1.js:5\\)\r\n    at exception \\(lib3.js:5\\)"
+njs_run {"-p" "njs/test/module/libs" "./njs/test/module/exception.js"} \
+        "at error \\(sub1.js:5\\)"
 
-njs_run "-p njs/test/module ./njs/test/module/recursive.js" \
+njs_run {"-p" "njs/test/module" "./njs/test/module/recursive.js"} \
         "SyntaxError: Cannot import itself \"./recursive.js\" in recursive.js:3"
 
 # CLI OPTIONS
 
 # help
 
-njs_run "-h" "Interactive njs shell.\r\n\r\nOptions:"
+njs_run {"-h"} "Options"
 
 # command
 
-njs_run "-c 'console.log(\"a b c\")'" "a b c"
+njs_run {"-c" "console.log(\"a b c\")"} "a b c"
+
+njs_run {"-c" "console.log("} "SyntaxError: Unexpected end of input in string:1"
 
-njs_run "-c 'console.log('" "SyntaxError: Unexpected token \"\" in string:1"
 
 # disassemble
 
@@ -720,10 +723,10 @@ njs_test {
      "12\r\n"}
 } "-p njs/test/module/"
 
-njs_run "-q ./njs/test/module/normal.js" \
+njs_run {"-q" "./njs/test/module/normal.js"} \
         "SyntaxError: Cannot find module \"hash.js\" in 5"
 
-njs_run "-p njs/test/module/libs/ -d ./njs/test/module/normal.js" \
+njs_run {"-p" "njs/test/module/libs/" "-d" "./njs/test/module/normal.js"} \
         "passed!"
 
 # sandboxing
@@ -756,5 +759,5 @@ njs_test {
 
 # version
 
-njs_run "-v" "\\d+\.\\d+\.\\d+"
+njs_run {"-v"} "\\d+\.\\d+\.\\d+"