Skip to content

Commit

Permalink
Support for trybuild and similar macro testing tools (#168)
Browse files Browse the repository at this point in the history
Signed-off-by: Filippo Costa <filippo@neysofu.me>
  • Loading branch information
neysofu committed Sep 12, 2023
1 parent 44b6087 commit 67c46e7
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 2 deletions.
19 changes: 19 additions & 0 deletions dist/restore/index.js
Expand Up @@ -64354,6 +64354,25 @@ async function cleanTargetDir(targetDir, packages, checkTimestamp = false) {
}
async function cleanProfileTarget(profileDir, packages, checkTimestamp = false) {
lib_core.debug(`cleaning profile directory "${profileDir}"`);
// Quite a few testing utility crates store compilation artifacts as nested
// workspaces under `target/tests`. Notably, `target/tests/target` and
// `target/tests/trybuild`.
if (external_path_default().basename(profileDir) === "tests") {
try {
// https://github.com/vertexclique/kaos/blob/9876f6c890339741cc5be4b7cb9df72baa5a6d79/src/cargo.rs#L25
// https://github.com/eupn/macrotest/blob/c4151a5f9f545942f4971980b5d264ebcd0b1d11/src/cargo.rs#L27
cleanTargetDir(external_path_default().join(profileDir, "target"), packages, checkTimestamp);
}
catch { }
try {
// https://github.com/dtolnay/trybuild/blob/eec8ca6cb9b8f53d0caf1aa499d99df52cae8b40/src/cargo.rs#L50
cleanTargetDir(external_path_default().join(profileDir, "trybuild"), packages, checkTimestamp);
}
catch { }
// Delete everything else.
await rmExcept(profileDir, new Set(["target", "trybuild"]), checkTimestamp);
return;
}
let keepProfile = new Set(["build", ".fingerprint", "deps"]);
await rmExcept(profileDir, keepProfile);
const keepPkg = new Set(packages.map((p) => p.name));
Expand Down
19 changes: 19 additions & 0 deletions dist/save/index.js
Expand Up @@ -64354,6 +64354,25 @@ async function cleanTargetDir(targetDir, packages, checkTimestamp = false) {
}
async function cleanProfileTarget(profileDir, packages, checkTimestamp = false) {
core.debug(`cleaning profile directory "${profileDir}"`);
// Quite a few testing utility crates store compilation artifacts as nested
// workspaces under `target/tests`. Notably, `target/tests/target` and
// `target/tests/trybuild`.
if (external_path_default().basename(profileDir) === "tests") {
try {
// https://github.com/vertexclique/kaos/blob/9876f6c890339741cc5be4b7cb9df72baa5a6d79/src/cargo.rs#L25
// https://github.com/eupn/macrotest/blob/c4151a5f9f545942f4971980b5d264ebcd0b1d11/src/cargo.rs#L27
cleanTargetDir(external_path_default().join(profileDir, "target"), packages, checkTimestamp);
}
catch { }
try {
// https://github.com/dtolnay/trybuild/blob/eec8ca6cb9b8f53d0caf1aa499d99df52cae8b40/src/cargo.rs#L50
cleanTargetDir(external_path_default().join(profileDir, "trybuild"), packages, checkTimestamp);
}
catch { }
// Delete everything else.
await rmExcept(profileDir, new Set(["target", "trybuild"]), checkTimestamp);
return;
}
let keepProfile = new Set(["build", ".fingerprint", "deps"]);
await rmExcept(profileDir, keepProfile);
const keepPkg = new Set(packages.map((p) => p.name));
Expand Down
20 changes: 20 additions & 0 deletions src/cleanup.ts
Expand Up @@ -34,6 +34,26 @@ export async function cleanTargetDir(targetDir: string, packages: Packages, chec
async function cleanProfileTarget(profileDir: string, packages: Packages, checkTimestamp = false) {
core.debug(`cleaning profile directory "${profileDir}"`);

// Quite a few testing utility crates store compilation artifacts as nested
// workspaces under `target/tests`. Notably, `target/tests/target` and
// `target/tests/trybuild`.
if (path.basename(profileDir) === "tests") {
try {
// https://github.com/vertexclique/kaos/blob/9876f6c890339741cc5be4b7cb9df72baa5a6d79/src/cargo.rs#L25
// https://github.com/eupn/macrotest/blob/c4151a5f9f545942f4971980b5d264ebcd0b1d11/src/cargo.rs#L27
cleanTargetDir(path.join(profileDir, "target"), packages, checkTimestamp);
} catch { }
try {
// https://github.com/dtolnay/trybuild/blob/eec8ca6cb9b8f53d0caf1aa499d99df52cae8b40/src/cargo.rs#L50
cleanTargetDir(path.join(profileDir, "trybuild"), packages, checkTimestamp);
} catch { }

// Delete everything else.
await rmExcept(profileDir, new Set(["target", "trybuild"]), checkTimestamp);

return
}

let keepProfile = new Set(["build", ".fingerprint", "deps"]);
await rmExcept(profileDir, keepProfile);

Expand Down
64 changes: 62 additions & 2 deletions tests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tests/Cargo.toml
Expand Up @@ -9,5 +9,8 @@ edition = "2021"
reqwest = "0.11.18"
watto = { git = "https://github.com/getsentry/watto", rev = "d71c8218506bddba102a124a460d64da25e303dc", features = ["strings"] }

[dev-dependencies]
trybuild = "1"

[target.'cfg(not(target_env = "msvc"))'.dependencies]
tikv-jemallocator = "0.5.4"
6 changes: 6 additions & 0 deletions tests/tests/trybuild.rs
@@ -0,0 +1,6 @@
#[test]
fn test_trybuild() {
let t = trybuild::TestCases::new();
t.pass("tests/trybuild/empty_main.rs");
t.compile_fail("tests/trybuild/fail_to_compile.rs");
}
1 change: 1 addition & 0 deletions tests/tests/trybuild/empty_main.rs
@@ -0,0 +1 @@
fn main() {}
3 changes: 3 additions & 0 deletions tests/tests/trybuild/fail_to_compile.rs
@@ -0,0 +1,3 @@
fn main() {
"foobar".foobar();
}
5 changes: 5 additions & 0 deletions tests/tests/trybuild/fail_to_compile.stderr
@@ -0,0 +1,5 @@
error[E0599]: no method named `foobar` found for reference `&'static str` in the current scope
--> tests/trybuild/fail_to_compile.rs:2:14
|
2 | "foobar".foobar();
| ^^^^^^ method not found in `&str`

0 comments on commit 67c46e7

Please sign in to comment.