summaryrefslogtreecommitdiff
path: root/test.ts
diff options
context:
space:
mode:
authorYoshiya Hinosawa <stibium121@gmail.com>2019-06-03 10:42:27 +0900
committerRyan Dahl <ry@tinyclouds.org>2019-06-02 21:42:27 -0400
commit21684c679bf64c4e17bdab03d10ac12cdca56b3c (patch)
treeb807c87680169cf745ec658766dff52f31063a21 /test.ts
parente729d442fb904ac3db41da03874c7e5277547e52 (diff)
Check file changes during test (denoland/deno_std#476)
Original: https://github.com/denoland/deno_std/commit/7daa887b09d4662710ad58e68de1a01a318455bb
Diffstat (limited to 'test.ts')
-rwxr-xr-xtest.ts39
1 files changed, 38 insertions, 1 deletions
diff --git a/test.ts b/test.ts
index 478ae61f8..edaca7a21 100755
--- a/test.ts
+++ b/test.ts
@@ -21,4 +21,41 @@ import "./textproto/test.ts";
import "./util/test.ts";
import "./ws/test.ts";
-import "./testing/main.ts";
+import { xrun } from "./prettier/util.ts";
+import { red, green } from "./colors/mod.ts";
+import { runTests } from "./testing/mod.ts";
+
+async function run(): Promise<void> {
+ const startTime = Date.now();
+ await runTests();
+ await checkSourceFileChanges(startTime);
+}
+
+/**
+ * Checks whether any source file is changed since the given start time.
+ * If some files are changed, this function exits with 1.
+ */
+async function checkSourceFileChanges(startTime: number): Promise<void> {
+ console.log("test checkSourceFileChanges ...");
+ const changed = new TextDecoder()
+ .decode(await xrun({ args: ["git", "ls-files"], stdout: "piped" }).output())
+ .trim()
+ .split("\n")
+ .filter(file => {
+ const stat = Deno.lstatSync(file);
+ if (stat != null) {
+ return (stat as any).modified * 1000 > startTime;
+ }
+ });
+ if (changed.length > 0) {
+ console.log(red("FAILED"));
+ console.log(
+ `Error: Some source files are modified during test: ${changed.join(", ")}`
+ );
+ Deno.exit(1);
+ } else {
+ console.log(green("ok"));
+ }
+}
+
+run();