[njs] Hiding the unit tests' output under the verbose mode.

Dmitry Volyntsev xeioex at nginx.com
Tue Feb 20 16:19:28 UTC 2018


details:   http://hg.nginx.org/njs/rev/18e0275576a3
branches:  
changeset: 449:18e0275576a3
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Tue Feb 20 19:12:53 2018 +0300
description:
Hiding the unit tests' output under the verbose mode.

diffstat:

 Makefile                        |   2 +-
 njs/test/njs_interactive_test.c |  26 ++++++++++++++++++++++----
 njs/test/njs_unit_test.c        |  25 ++++++++++++++++---------
 3 files changed, 39 insertions(+), 14 deletions(-)

diffs (129 lines):

diff -r e7bc9d328a20 -r 18e0275576a3 Makefile
--- a/Makefile	Tue Feb 20 19:12:53 2018 +0300
+++ b/Makefile	Tue Feb 20 19:12:53 2018 +0300
@@ -91,7 +91,7 @@ test:	njs_interactive_test \
 	$(NXT_BUILDDIR)/njs_unit_test \
 	$(NXT_BUILDDIR)/njs_benchmark \
 
-	$(NXT_BUILDDIR)/njs_unit_test d
+	$(NXT_BUILDDIR)/njs_unit_test
 
 clean:
 	rm -rf $(NXT_BUILDDIR)
diff -r e7bc9d328a20 -r 18e0275576a3 njs/test/njs_interactive_test.c
--- a/njs/test/njs_interactive_test.c	Tue Feb 20 19:12:53 2018 +0300
+++ b/njs/test/njs_interactive_test.c	Tue Feb 20 19:12:53 2018 +0300
@@ -192,7 +192,7 @@ static njs_interactive_test_t  njs_test[
 
 
 static nxt_int_t
-njs_interactive_test(void)
+njs_interactive_test(nxt_bool_t verbose)
 {
     u_char                  *start, *last, *end;
     njs_vm_t                *vm;
@@ -210,8 +210,10 @@ njs_interactive_test(void)
 
         test = &njs_test[i];
 
-        printf("\"%.*s\"\n", (int) test->script.length, test->script.start);
-        fflush(stdout);
+        if (verbose) {
+            printf("\"%.*s\"\n", (int) test->script.length, test->script.start);
+            fflush(stdout);
+        }
 
         memset(&options, 0, sizeof(njs_vm_opt_t));
 
@@ -279,5 +281,21 @@ done:
 int nxt_cdecl
 main(int argc, char **argv)
 {
-    return njs_interactive_test();
+    nxt_bool_t  verbose;
+
+    verbose = 0;
+
+    if (argc > 1) {
+        switch (argv[1][0]) {
+
+        case 'v':
+            verbose = 1;
+            break;
+
+        default:
+            break;
+        }
+    }
+
+    return njs_interactive_test(verbose);
 }
diff -r e7bc9d328a20 -r 18e0275576a3 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Tue Feb 20 19:12:53 2018 +0300
+++ b/njs/test/njs_unit_test.c	Tue Feb 20 19:12:53 2018 +0300
@@ -9376,7 +9376,7 @@ njs_externals_init(njs_vm_t *vm)
 
 
 static nxt_int_t
-njs_unit_test(nxt_bool_t disassemble)
+njs_unit_test(nxt_bool_t disassemble, nxt_bool_t verbose)
 {
     u_char        *start;
     njs_vm_t      *vm, *nvm;
@@ -9401,9 +9401,11 @@ njs_unit_test(nxt_bool_t disassemble)
 
     for (i = 0; i < nxt_nitems(njs_test); i++) {
 
-        printf("\"%.*s\"\n",
-               (int) njs_test[i].script.length, njs_test[i].script.start);
-        fflush(stdout);
+        if (verbose) {
+            printf("\"%.*s\"\n",
+                   (int) njs_test[i].script.length, njs_test[i].script.start);
+            fflush(stdout);
+        }
 
         memset(&options, 0, sizeof(njs_vm_opt_t));
 
@@ -9462,10 +9464,10 @@ njs_unit_test(nxt_bool_t disassemble)
             continue;
         }
 
-        printf("njs(\"%.*s\") failed: \"%.*s\" vs \"%.*s\"\n",
+        printf("njs(\"%.*s\")\nexpected: \"%.*s\"\n     got: \"%.*s\"\n",
                (int) njs_test[i].script.length, njs_test[i].script.start,
-               (int) njs_test[i].ret.length, njs_test[i].ret.start,
-               (int) s.length, s.start);
+               (int) s.length, s.start, (int) njs_test[i].ret.length,
+               njs_test[i].ret.start);
 
         goto done;
     }
@@ -9493,9 +9495,10 @@ done:
 int nxt_cdecl
 main(int argc, char **argv)
 {
-    nxt_bool_t  disassemble;
+    nxt_bool_t  disassemble, verbose;
 
     disassemble = 0;
+    verbose = 0;
 
     if (argc > 1) {
         switch (argv[1][0]) {
@@ -9504,10 +9507,14 @@ main(int argc, char **argv)
             disassemble = 1;
             break;
 
+        case 'v':
+            verbose = 1;
+            break;
+
         default:
             break;
         }
     }
 
-    return njs_unit_test(disassemble);
+    return njs_unit_test(disassemble, verbose);
 }


More information about the nginx-devel mailing list