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.
This commit is contained in:
Donovan Glover 2023-08-31 11:20:32 -04:00
parent 41b784ec9b
commit fb7694a844
No known key found for this signature in database
GPG Key ID: EA7408A77AE1BE65
2 changed files with 41 additions and 7 deletions

View File

@ -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")

41
tests/main.ts Normal file
View File

@ -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<string[]> => {
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<string[]> => {
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))
}
})