diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index cf664011..37169526 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,17 +7,6 @@ on: branches: [ master ] jobs: - deno: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: denoland/setup-deno@v1 - with: - deno-version: v1.x - - name: Run tests - run: deno test tests/main.ts --allow-read - - name: Check formatting - run: deno fmt tests/ --check nix: runs-on: ubuntu-latest steps: diff --git a/tests/lib.ts b/tests/lib.ts deleted file mode 100644 index cf989fae..00000000 --- a/tests/lib.ts +++ /dev/null @@ -1,68 +0,0 @@ -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"; - -/** Gets files in a given directory. - * - * @param directory The directory to get files from. - * @returns An array of files in the given directory. - */ -async function getFilesInDirectory(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; -} - -/** Gets imports in a given nix file. - * - * @param file The file to search for nix imports. - * @returns An array of imports in the given nix file. - */ -async function getImportsInFile(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; -} - -/** Assets that all files in a given directory are imported in default.nix. - * - * @param directory The directory to assert. - * @param excludes Files to exclude from assertion. Useful for files imported elsewhere. - */ -export async function assertAllModulesInDirectory( - directory: string, - excludes?: string[], -) { - const files = await getFilesInDirectory(`./${directory}`); - const imports = await getImportsInFile(`./${directory}/default.nix`); - - for (const file of files) { - const basename = file.split(`${directory}/`)[1]; - - if (excludes && excludes.includes(basename)) { - continue; - } - - assert(imports.includes(file)); - } -} diff --git a/tests/main.ts b/tests/main.ts deleted file mode 100644 index 3dafa23f..00000000 --- a/tests/main.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { assertAllModulesInDirectory } from "./lib.ts"; - -/** A list of directories to check for all Nix modules being imported */ -const dirs = [ - "containers", - "home", - "modules", - "overlays", - "packages", - "specializations", -]; - -/** A helper function to return excluded files. - * - * @param directory The directory to get excludes for. - * @returns An array of excluded files for the given directory or undefined. - */ -function getExcludes(directory: string): string[] | undefined { - switch (directory) { - case "packages": - return ["hycov.nix"]; - } -} - -for (const dir of dirs) { - Deno.test(`imports all modules in ./${dir}`, async () => { - await assertAllModulesInDirectory(dir, getExcludes(dir)); - }); -}