Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test coverage #67

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"test": { "include": ["src/", "test/"] },
"tasks": {
"gen": "deno run --allow-read --allow-write ./src/main.ts",
"test": "deno test --allow-read --allow-write"
"test": "deno test --allow-read --allow-write --parallel --shuffle"
},
"imports": {
"@libs/xml": "jsr:@libs/[email protected]",
Expand Down
6 changes: 3 additions & 3 deletions src/libs/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { convertToOPML, convertToTOML } from "./mod.ts";
export async function readTOML(file: string): Promise<Lists> {
try {
const data: string = await Deno.readTextFile(file);
return await convertToTOML(data);
return convertToTOML(data);
} catch (error) {
if (error instanceof Deno.errors.NotFound) {
throw Error(`File not found: "${file}"`);
throw new Error(`File not found: "${file}"`);
} else if (error instanceof Deno.errors.PermissionDenied) {
throw Error(`Permission denied: "${file}"`);
throw new Error(`Permission denied: "${file}"`);
} else throw error;
}
}
Expand Down
28 changes: 27 additions & 1 deletion test/libs/io_test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals } from "@std/assert";
import { assertEquals, assertIsError } from "@std/assert";
import { join } from "@std/path";
import {
convertToOPML,
Expand All @@ -25,6 +25,32 @@ xmlUrl = "https://example.com/feed"
assertEquals(convertToTOML(toml), lists);
});

Deno.test("Read TOML (File not found)", async () => {
try {
await readTOML("file-not-found.toml");
} catch (error) {
assertEquals(error.message, 'File not found: "file-not-found.toml"');
}
});

Deno.test("Read TOML (Permission denied)", async () => {
const file: string = await Deno.makeTempFile({ suffix: ".toml" });
await Deno.chmod(file, 0o000);
try {
await readTOML(file);
} catch (error) {
assertEquals(error.message, `Permission denied: "${file}"`);
}
});

Deno.test("Read TOML (Unexpected error)", async () => {
try {
await readTOML("");
} catch (error) {
assertIsError(error);
}
});

Deno.test("Write XML", async () => {
const feeds: Lists = {
lists: [
Expand Down
Loading