mirror of
https://github.com/donovanglover/nix-config.git
synced 2024-11-24 17:23:09 +01:00
meta: Drop deno tests
These shouldn't be needed anymore now that I know how to dynamically import modules and declare attribute sets with the built-in nix functions.
This commit is contained in:
parent
297a46d08e
commit
a193c91cd6
11
.github/workflows/tests.yml
vendored
11
.github/workflows/tests.yml
vendored
@ -7,17 +7,6 @@ on:
|
|||||||
branches: [ master ]
|
branches: [ master ]
|
||||||
|
|
||||||
jobs:
|
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:
|
nix:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
68
tests/lib.ts
68
tests/lib.ts
@ -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<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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 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<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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 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));
|
|
||||||
}
|
|
||||||
}
|
|
@ -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));
|
|
||||||
});
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user