From fb7694a844a4e3a11552bf9aa02e46bba8f0ec6b Mon Sep 17 00:00:00 2001 From: Donovan Glover Date: Thu, 31 Aug 2023 11:20:32 -0400 Subject: [PATCH] meta: Begin re-writing tests in TypeScript/Deno 2 months ago, I figured out how to make Crystal work on NixOS and made an upstream PR to fix Crystal being unable to find -lpcre. Unfortunately, that change hasn't been merged yet and I even encountered a core dumped error when trying to build Crystal myself recently. Although people may be busy, I am concerned about the popularity of Crystal relative to other languages. It could be the case that the build was broken for so long precisely because no one used Crystal, and that the language isn't popular enough to generate comments on the patch either. In any case, JavaScript/TypeScript is here to stay, and it certainly has better tooling and community support than Crystal at the moment. Deno has been going strong for a few years now, and now that I know Rust, I can also contribute to it if I want to. --- tests/main.cr | 7 ------- tests/main.ts | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 7 deletions(-) delete mode 100644 tests/main.cr create mode 100644 tests/main.ts diff --git a/tests/main.cr b/tests/main.cr deleted file mode 100644 index 88be851..0000000 --- a/tests/main.cr +++ /dev/null @@ -1,7 +0,0 @@ -require "./check_top_level_imports" - -check_top_level_imports("containers") -check_top_level_imports("home") -check_top_level_imports("modules") -check_top_level_imports("overlays") -check_top_level_imports("specializations") diff --git a/tests/main.ts b/tests/main.ts new file mode 100644 index 0000000..c48acc0 --- /dev/null +++ b/tests/main.ts @@ -0,0 +1,41 @@ +import { assert } from "https://deno.land/std@0.200.0/assert/mod.ts"; +import { walk } from "https://deno.land/std@0.200.0/fs/walk.ts"; + +const getFilesInDirectory = async (directory: string): Promise => { + const files = []; + + for await (const walkEntry of walk(directory)) { + if (walkEntry.isFile) { + if (walkEntry.path.includes("default.nix")) continue + files.push(walkEntry.path) + } + } + + return files +} + +const getImportsInFile = async (file: string): Promise => { + const text = await Deno.readTextFile(file); + const lines = text.split("\n") + const imports = []; + + for (let i = 0; i < lines.length; i++) { + if (lines[i].includes("./")) { + imports.push(file.split("./")[1].split("/")[0] + "/" + lines[i].split("./")[1].split(" ")[0]) + } + } + + return imports +} + +Deno.test("imports all modules in ./packages", async () => { + const packageFiles = await getFilesInDirectory("./packages") + const packageImports = await getImportsInFile("./packages/default.nix") + + console.log(packageFiles) + console.log(packageImports) + + for (const file of packageFiles) { + assert(packageImports.includes(file)) + } +})