about summary refs log tree commit diff
path: root/src/tools/rustdoc-gui/tester.js
diff options
context:
space:
mode:
authorStefan Schindler <dns2utf8@estada.ch>2021-08-09 22:34:44 +0200
committerStefan Schindler <dns2utf8@estada.ch>2021-08-10 00:47:05 +0200
commitc17628be18b1c99b1cb4c78b28670068da0f2fc4 (patch)
tree0f91b3d703e2fc5e8b41418d48a16f6c05677206 /src/tools/rustdoc-gui/tester.js
parenteca2b3be3d7d52cb03277fb86e57cf3bc969694a (diff)
downloadrust-c17628be18b1c99b1cb4c78b28670068da0f2fc4.tar.gz
rust-c17628be18b1c99b1cb4c78b28670068da0f2fc4.zip
Implement summarised results
Diffstat (limited to 'src/tools/rustdoc-gui/tester.js')
-rw-r--r--src/tools/rustdoc-gui/tester.js91
1 files changed, 54 insertions, 37 deletions
diff --git a/src/tools/rustdoc-gui/tester.js b/src/tools/rustdoc-gui/tester.js
index f0e5aef0ec1..92535f34178 100644
--- a/src/tools/rustdoc-gui/tester.js
+++ b/src/tools/rustdoc-gui/tester.js
@@ -70,12 +70,33 @@ function parseOptions(args) {
     return null;
 }
 
-function print_test_successful() {
-    process.stdout.write(".");
+/// Print single char status information without \n
+function char_printer(n_tests) {
+    const max_per_line = 10;
+    let current = 0;
+    return {
+        successful: function() {
+            current += 1;
+            if (current % max_per_line === 0) {
+                process.stdout.write(`. (${current}/${n_tests})\n`);
+            } else {
+                process.stdout.write(".");
+            }
+        },
+        erroneous: function() {
+            current += 1;
+            if (current % max_per_line === 0) {
+                process.stderr.write(`F (${current}/${n_tests})\n`);
+            } else {
+                process.stderr.write("F");
+            }
+        },
+    };
 }
 
-function print_test_erroneous() {
-    process.stderr.write("F");
+/// Sort array by .file_name property
+function by_filename(a, b) {
+    return a.file_name - b.file_name;
 }
 
 async function main(argv) {
@@ -129,32 +150,36 @@ async function main(argv) {
     console.log(`Running ${files.length} rustdoc-gui tests...`);
     process.setMaxListeners(files.length + 1);
     let tests = [];
-    let results = new Array(files.length);
-    // poormans enum
-    const RUN_SUCCESS = 42, RUN_FAILED = 23, RUN_ERRORED = 13;
+    let results = {
+        successful: [],
+        failed: [],
+        errored: [],
+    };
+    const status_bar = char_printer(files.length);
     for (let i = 0; i < files.length; ++i) {
-        const testPath = path.join(opts["tests_folder"], files[i]);
+        const file_name = files[i];
+        const testPath = path.join(opts["tests_folder"], file_name);
         tests.push(
             runTest(testPath, options)
             .then(out => {
                 const [output, nb_failures] = out;
-                results[i] = {
-                    status: nb_failures === 0 ? RUN_SUCCESS : RUN_FAILED,
+                results[nb_failures === 0 ? "successful" : "failed"].push({
+                    file_name: file_name,
                     output: output,
-                };
+                });
                 if (nb_failures > 0) {
-                    print_test_erroneous()
+                    status_bar.erroneous()
                     failed = true;
                 } else {
-                    print_test_successful()
+                    status_bar.successful()
                 }
             })
             .catch(err => {
-                results[i] = {
-                    status: RUN_ERRORED,
+                results.errored.push({
+                    file_name: file_name,
                     output: err,
-                };
-                print_test_erroneous();
+                });
+                status_bar.erroneous();
                 failed = true;
             })
         );
@@ -166,28 +191,20 @@ async function main(argv) {
     // final \n after the tests
     console.log("\n");
 
-    results.forEach(r => {
-        switch (r.status) {
-            case RUN_SUCCESS:
-                if (debug === false) {
-                    break;
-                }
-            case RUN_FAILED:
-                console.log(r.output);
-                break;
-            case RUN_ERRORED:
-                // skip
-                break;
-            default:
-                console.error(`unexpected status = ${r.status}`);
-                process.exit(4);
-        }
+    if (debug === false) {
+        results.successful.sort(by_filename);
+        results.successful.forEach(r => {
+            console.log(r.output);
+        });
+    }
+    results.failed.sort(by_filename);
+    results.failed.forEach(r => {
+        console.log(r.output);
     });
     // print run errors on the bottom so developers see them better
-    results.forEach(r => {
-        if (r.status === RUN_ERRORED) {
-            console.error(r.output);
-        }
+    results.errored.sort(by_filename);
+    results.errored.forEach(r => {
+        console.error(r.output);
     });
 
     if (failed) {