-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(tools): add integration test for scaffold (#836)
- Loading branch information
1 parent
5ca58cd
commit d11ee57
Showing
4 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { exists } from "https://deno.land/[email protected]/fs/mod.ts"; | ||
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
|
||
Deno.test( | ||
"Check if the files created by tools/scaffold.ts pass `cargo check`", | ||
async () => { | ||
const name = "dummy-lint-rule-for-testing"; | ||
const filename = name.replaceAll("-", "_"); | ||
const rulesPath = "./src/rules.rs"; | ||
|
||
// Preserve the original content of src/rules.rs | ||
const rulesRs = await Deno.readTextFile(rulesPath); | ||
|
||
try { | ||
console.log(`Run the scaffold script to create ${name} rule`); | ||
const p1 = Deno.run({ | ||
cmd: [ | ||
"deno", | ||
"run", | ||
"--allow-write=.", | ||
"--allow-read=.", | ||
"./tools/scaffold.ts", | ||
name, | ||
], | ||
}); | ||
const s1 = await p1.status(); | ||
p1.close(); | ||
|
||
assertEquals(s1.code, 0); | ||
console.log("Scaffold succeeded"); | ||
|
||
// Check if `cargo check` passes | ||
console.log("Run `cargo check`"); | ||
const p2 = Deno.run({ | ||
cmd: ["cargo", "check", "--all-targets", "--all-features"], | ||
}); | ||
const s2 = await p2.status(); | ||
p2.close(); | ||
|
||
assertEquals(s2.code, 0); | ||
console.log("`cargo check` succeeded"); | ||
} finally { | ||
console.log("Start cleanup..."); | ||
console.log("Restoring src/rules.rs..."); | ||
await Deno.writeTextFile(rulesPath, rulesRs); | ||
|
||
console.log(`Deleting src/rules/${filename}.rs...`); | ||
const rsPath = `./src/rules/${filename}.rs`; | ||
if (await exists(rsPath)) { | ||
await Deno.remove(rsPath); | ||
} | ||
|
||
console.log(`Deleting docs/rules/${filename}.md...`); | ||
const mdPath = `./docs/rules/${filename}.md`; | ||
if (await exists(mdPath)) { | ||
await Deno.remove(mdPath); | ||
} | ||
|
||
console.log("Cleanup finished"); | ||
} | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters