[njs] Tests: fixed "fs" tests with custom build directory.

Dmitry Volyntsev xeioex at nginx.com
Thu Dec 30 13:30:35 UTC 2021


details:   https://hg.nginx.org/njs/rev/d11d962c40cd
branches:  
changeset: 1796:d11d962c40cd
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Wed Dec 29 17:19:55 2021 +0000
description:
Tests: fixed "fs" tests with custom build directory.

diffstat:

 test/fs/methods.t.js     |  16 ++++++++--------
 test/fs/promises_01.t.js |   2 +-
 test/fs/promises_02.t.js |   2 +-
 test/fs/promises_03.t.js |   2 +-
 test/fs/promises_04.t.js |   7 +++----
 test/fs/promises_05.t.js |   5 ++---
 test/fs/promises_06.t.js |   5 ++++-
 test/fs/promises_07.t.js |   4 ++--
 test/fs/promises_08.t.js |   2 +-
 test/fs/promises_09.t.js |   2 +-
 test/harness/compatFs.js |   3 +++
 test/help                |   2 --
 test/test262             |   2 +-
 13 files changed, 28 insertions(+), 26 deletions(-)

diffs (220 lines):

diff -r 1ad65f9d50f5 -r d11d962c40cd test/fs/methods.t.js
--- a/test/fs/methods.t.js	Wed Dec 29 16:56:47 2021 +0000
+++ b/test/fs/methods.t.js	Wed Dec 29 17:19:55 2021 +0000
@@ -9,7 +9,7 @@ function p(args, default_opts) {
     let fname = params.args[0];
 
     if (fname[0] == '@') {
-        let gen = `build/test/fs_test_${Math.round(Math.random() * 1000000)}`;
+        let gen = `${test_dir}/fs_test_${Math.round(Math.random() * 1000000)}`;
         params.args = params.args.map(v => v);
         params.args[0] = gen + fname.slice(1);
     }
@@ -368,9 +368,9 @@ async function realpath_test(params) {
 }
 
 let realpath_tests = () => [
-    { args: ["build/test/.."],
-      check: (data) => data.endsWith("build") },
-    { args: ["build/test/", {encoding:'buffer'}],
+    { args: ["test/fs/.."],
+      check: (data) => data.endsWith("test") },
+    { args: ["test/fs/ascii", {encoding:'buffer'}],
       check: (data) => data instanceof Buffer },
 ];
 
@@ -478,14 +478,14 @@ let stat_tests = () => [
           return true;
       } },
 
-    { args: ["build/"],
+    { args: ["test/fs/ascii"],
       check: (st) => contains(Object.keys(st),
                               [ "atime", "atimeMs", "birthtime", "birthtimeMs",
                                 "blksize", "blocks", "ctime", "ctimeMs", "dev",
                                 "gid", "ino", "mode", "mtime", "mtimeMs","nlink",
                                 "rdev", "size", "uid" ]) },
 
-    { args: ["build/"],
+    { args: ["test/fs/ascii"],
       check: (st) => Object.keys(st).every(p => {
         let v = st[p];
         if (p == 'atime' || p == 'ctime' || p == 'mtime' || p == 'birthtime') {
@@ -503,7 +503,7 @@ let stat_tests = () => [
         return true;
       }) },
 
-    { args: ["build/"],
+    { args: ["test/fs/ascii"],
       check: (st) => ['atime', 'birthtime', 'ctime', 'mtime'].every(p => {
           let date = st[p].valueOf();
           let num = st[p + 'Ms'];
@@ -515,7 +515,7 @@ let stat_tests = () => [
           return true;
       }) },
 
-    { args: ["build/"],
+    { args: [test_dir],
       check: (st) => ['isBlockDevice',
                       'isCharacterDevice',
                       'isDirectory',
diff -r 1ad65f9d50f5 -r d11d962c40cd test/fs/promises_01.t.js
--- a/test/fs/promises_01.t.js	Wed Dec 29 16:56:47 2021 +0000
+++ b/test/fs/promises_01.t.js	Wed Dec 29 17:19:55 2021 +0000
@@ -3,7 +3,7 @@ includes: [compareArray.js, compatFs.js]
 flags: [async]
 ---*/
 
-var fname = 'build/test/fs_promises_01';
+var fname = `${test_dir}/fs_promises_01`;
 
 let stages = [];
 
diff -r 1ad65f9d50f5 -r d11d962c40cd test/fs/promises_02.t.js
--- a/test/fs/promises_02.t.js	Wed Dec 29 16:56:47 2021 +0000
+++ b/test/fs/promises_02.t.js	Wed Dec 29 17:19:55 2021 +0000
@@ -3,7 +3,7 @@ includes: [compareArray.js, compatFs.js]
 flags: [async]
 ---*/
 
-var fname = 'build/test/fs_promises_02';
+var fname = `${test_dir}/fs_promises_02`;
 
 var testSync = new Promise((resolve, reject) => {
     var failed = false;
diff -r 1ad65f9d50f5 -r d11d962c40cd test/fs/promises_03.t.js
--- a/test/fs/promises_03.t.js	Wed Dec 29 16:56:47 2021 +0000
+++ b/test/fs/promises_03.t.js	Wed Dec 29 17:19:55 2021 +0000
@@ -3,7 +3,7 @@ includes: [compareArray.js, compatFs.js]
 flags: [async]
 ---*/
 
-var fname = 'build/test/fs_promises_03';
+var fname = `${test_dir}/fs_promises_03`;
 
 var testSync = () => new Promise((resolve, reject) => {
     try {
diff -r 1ad65f9d50f5 -r d11d962c40cd test/fs/promises_04.t.js
--- a/test/fs/promises_04.t.js	Wed Dec 29 16:56:47 2021 +0000
+++ b/test/fs/promises_04.t.js	Wed Dec 29 17:19:55 2021 +0000
@@ -3,10 +3,9 @@ includes: [compareArray.js, compatFs.js]
 flags: [async]
 ---*/
 
-var dname = 'build/test/';
-var fname = dname + 'fs_promises_04';
-var fname_utf8 = dname + 'fs_promises_αβγ_04';
-var lname = dname + 'fs_promises_04_lnk';
+var fname = `${test_dir}/fs_promises_04`;
+var fname_utf8 = `${test_dir}/fs_promises_αβγ_04`;
+var lname = `${test_dir}/fs_promises_lnk_04`;
 
 var testSync = () => new Promise((resolve, reject) => {
     try {
diff -r 1ad65f9d50f5 -r d11d962c40cd test/fs/promises_05.t.js
--- a/test/fs/promises_05.t.js	Wed Dec 29 16:56:47 2021 +0000
+++ b/test/fs/promises_05.t.js	Wed Dec 29 17:19:55 2021 +0000
@@ -3,9 +3,8 @@ includes: [compareArray.js, compatFs.js]
 flags: [async]
 ---*/
 
-var rname = 'build/test/';
-var dname = rname + 'fs_promises_05';
-var dname_utf8 = rname + 'fs_promises_αβγ_05';
+var dname = `${test_dir}/fs_promises_05`;
+var dname_utf8 = `${test_dir}/fs_promises_αβγ_05`;
 var fname = (d) => d + '/fs_promises_05_file';
 
 var testSync = () => new Promise((resolve, reject) => {
diff -r 1ad65f9d50f5 -r d11d962c40cd test/fs/promises_06.t.js
--- a/test/fs/promises_06.t.js	Wed Dec 29 16:56:47 2021 +0000
+++ b/test/fs/promises_06.t.js	Wed Dec 29 17:19:55 2021 +0000
@@ -3,7 +3,7 @@ includes: [compareArray.js, compatFs.js]
 flags: [async]
 ---*/
 
-var dname = 'build/test/';
+var dname = `${test_dir}/`;
 var fname = (d) => d + '/fs_promises_06_file';
 var fname_utf8 = (d) => d + '/fs_promises_αβγ_06';
 
@@ -73,6 +73,9 @@ Promise.resolve()
 .then(() => {
     stages.push("renameSync");
 })
+.catch((e) => {
+    console.log('test fs.renameSync failed', JSON.stringify(e));
+})
 
 .then(testCallback)
 .then(() => {
diff -r 1ad65f9d50f5 -r d11d962c40cd test/fs/promises_07.t.js
--- a/test/fs/promises_07.t.js	Wed Dec 29 16:56:47 2021 +0000
+++ b/test/fs/promises_07.t.js	Wed Dec 29 17:19:55 2021 +0000
@@ -3,8 +3,8 @@ includes: [compareArray.js, compatFs.js]
 flags: [async]
 ---*/
 
-var dname = 'build/test/fs_promises_07';
-var dname_utf8 = 'build/test/fs_promises_αβγ_07';
+var dname = `${test_dir}/fs_promises_07`;
+var dname_utf8 = `${test_dir}/fs_promises_αβγ_07`;
 var fname = (d) => d + '/fs_promises_07_file';
 var lname = (d) => d + '/fs_promises_07_link';
 var cname = (d) => d + '/fs_promises_αβγ_07_dir';
diff -r 1ad65f9d50f5 -r d11d962c40cd test/fs/promises_08.t.js
--- a/test/fs/promises_08.t.js	Wed Dec 29 16:56:47 2021 +0000
+++ b/test/fs/promises_08.t.js	Wed Dec 29 17:19:55 2021 +0000
@@ -3,7 +3,7 @@ includes: [compareArray.js, compatFs.js]
 flags: [async]
 ---*/
 
-var dname = 'build/test/fs_promises_αβγ_08/';
+var dname = `${test_dir}/fs_promises_αβγ_08/`;
 var path = 'one/two/three/αβγ';
 
 var wipePath = (root, path, nofail) => {
diff -r 1ad65f9d50f5 -r d11d962c40cd test/fs/promises_09.t.js
--- a/test/fs/promises_09.t.js	Wed Dec 29 16:56:47 2021 +0000
+++ b/test/fs/promises_09.t.js	Wed Dec 29 17:19:55 2021 +0000
@@ -3,7 +3,7 @@ includes: [compareArray.js, compatFs.js]
 flags: [async]
 ---*/
 
-var root = 'build/test/';
+var root = test_dir;
 var dname = 'fs_promises_αβγ_09/';
 var lname = 'fs_promises_αβγ_09_lnk';
 var path = 'one/two/three/αβγ';
diff -r 1ad65f9d50f5 -r d11d962c40cd test/harness/compatFs.js
--- a/test/harness/compatFs.js	Wed Dec 29 16:56:47 2021 +0000
+++ b/test/harness/compatFs.js	Wed Dec 29 17:19:55 2021 +0000
@@ -9,3 +9,6 @@ if (typeof require == 'function') {
 function has_fs() {
     return fs;
 }
+
+let test_dir = process.env && process.env['NJS_TEST_DIR'] || 'build';
+test_dir = `${test_dir}/test`;
diff -r 1ad65f9d50f5 -r d11d962c40cd test/help
--- a/test/help	Wed Dec 29 16:56:47 2021 +0000
+++ b/test/help	Wed Dec 29 17:19:55 2021 +0000
@@ -17,6 +17,4 @@ default: "$NJS_TEST_LOG"
 default: "$NJS_TEST_DIR"
   --verbose=YES             enables verbose output, \
 default: "$NJS_TEST_VERBOSE"
-  --leave=YES               disables removing of "$NJS_TEST_DIR", \
-default: "$NJS_TEST_LEAVE"
 END
diff -r 1ad65f9d50f5 -r d11d962c40cd test/test262
--- a/test/test262	Wed Dec 29 16:56:47 2021 +0000
+++ b/test/test262	Wed Dec 29 17:19:55 2021 +0000
@@ -19,7 +19,7 @@ for njs_test in $NJS_TESTS; do
 running $njs_test $njs_log
 END
 
-    if /bin/sh -c "($NJS_TEST_BINARY $NJS_TEST_DIR/$njs_test)" > $njs_log 2>&1; then
+    if /bin/sh -c "(NJS_TEST_DIR=$NJS_TEST_DIR $NJS_TEST_BINARY $NJS_TEST_DIR/$njs_test)" > $njs_log 2>&1; then
         njs_success=yes
     else
         njs_success=no


More information about the nginx-devel mailing list