[njs] Unit tests: replacing njs_vm_retval_string() with njs_vm_retval_dump().

Dmitry Volyntsev xeioex at nginx.com
Tue Feb 28 03:09:12 UTC 2023


details:   https://hg.nginx.org/njs/rev/e92881f2b395
branches:  
changeset: 2052:e92881f2b395
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Mon Feb 27 19:05:03 2023 -0800
description:
Unit tests: replacing njs_vm_retval_string() with njs_vm_retval_dump().

The change allows to cover CLI behaviour more closely.

diffstat:

 src/test/njs_unit_test.c |  20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)

diffs (71 lines):

diff -r 82e673ec5f19 -r e92881f2b395 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Mon Feb 27 18:39:44 2023 -0800
+++ b/src/test/njs_unit_test.c	Mon Feb 27 19:05:03 2023 -0800
@@ -22823,12 +22823,12 @@ static njs_unit_test_t  njs_shell_test[]
 
     { njs_str("var a = \"aa\\naa\"" ENTER
               "a" ENTER),
-      njs_str("aa\naa") },
+      njs_str("'aa\\naa'") },
 
     { njs_str("var a = 3" ENTER
               "var a = 'str'" ENTER
               "a" ENTER),
-      njs_str("str") },
+      njs_str("'str'") },
 
     { njs_str("var a = 2" ENTER
               "a *= 2" ENTER
@@ -22862,7 +22862,7 @@ static njs_unit_test_t  njs_shell_test[]
               "case 0: a += '0';"
               "case 1: a += '1';"
               "}; a" ENTER),
-      njs_str("A") },
+      njs_str("'A'") },
 
     { njs_str("var a = 0; try { a = 5 }"
               "catch (e) { a = 9 } finally { a++ } a" ENTER),
@@ -22879,7 +22879,7 @@ static njs_unit_test_t  njs_shell_test[]
 
     { njs_str("Number.prototype.test = 'test'" ENTER
               "Number.prototype.test" ENTER),
-      njs_str("test") },
+      njs_str("'test'") },
 
     { njs_str("function f(a) {return a}" ENTER
               "function f(a) {return a}; f(2)" ENTER),
@@ -22929,11 +22929,12 @@ static njs_unit_test_t  njs_shell_test[]
               "function(){}()" ENTER),
       njs_str("SyntaxError: Unexpected token \"(\" in 1") },
 
-    /* Exception in njs_vm_retval_string() */
+    { njs_str("var o = { toString: function() { return [1] } }; o" ENTER),
+      njs_str("{\n toString: [Function: toString]\n}") },
 
     { njs_str("var o = { toString: function() { return [1] } }" ENTER
-              "o" ENTER),
-      njs_str("TypeError: Cannot convert object to primitive value") },
+              "o.toString()" ENTER),
+      njs_str("[\n 1\n]") },
 };
 
 
@@ -23630,8 +23631,8 @@ njs_interactive_test(njs_unit_test_t tes
             }
         }
 
-        if (njs_vm_retval_string(vm, &s) != NJS_OK) {
-            njs_printf("njs_vm_retval_string() failed\n");
+        if (njs_vm_retval_dump(vm, &s, 0) != NJS_OK) {
+            njs_printf("njs_vm_retval_dump() failed\n");
             goto done;
         }
 
@@ -24956,7 +24957,6 @@ static njs_test_suite_t  njs_suites[] =
       { .externals = 1, .repeat = 1, .unsafe = 1 },
       njs_shell_test,
       njs_nitems(njs_shell_test),
-
       njs_interactive_test },
 
     { njs_str("backtraces"),


More information about the nginx-devel mailing list