mirror of
				https://github.com/Swatinem/rust-cache.git
				synced 2025-10-31 23:33:48 +00:00 
			
		
		
		
	Support for trybuild and similar macro testing tools (#168)
				
					
				
			Signed-off-by: Filippo Costa <filippo@neysofu.me>
This commit is contained in:
		
							parent
							
								
									44b6087283
								
							
						
					
					
						commit
						67c46e7159
					
				
							
								
								
									
										19
									
								
								dist/restore/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										19
									
								
								dist/restore/index.js
									
									
									
									
										vendored
									
									
								
							| @ -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)); | ||||
|  | ||||
							
								
								
									
										19
									
								
								dist/save/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										19
									
								
								dist/save/index.js
									
									
									
									
										vendored
									
									
								
							| @ -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)); | ||||
|  | ||||
| @ -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); | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										64
									
								
								tests/Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										64
									
								
								tests/Cargo.lock
									
									
									
										generated
									
									
									
								
							| @ -14,6 +14,15 @@ version = "0.21.2" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" | ||||
| 
 | ||||
| [[package]] | ||||
| name = "basic-toml" | ||||
| version = "0.1.4" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "7bfc506e7a2370ec239e1d072507b2a80c833083699d3c6fa176fbb4de8448c6" | ||||
| dependencies = [ | ||||
|  "serde", | ||||
| ] | ||||
| 
 | ||||
| [[package]] | ||||
| name = "bitflags" | ||||
| version = "1.3.2" | ||||
| @ -148,6 +157,12 @@ dependencies = [ | ||||
|  "pin-utils", | ||||
| ] | ||||
| 
 | ||||
| [[package]] | ||||
| name = "glob" | ||||
| version = "0.3.1" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" | ||||
| 
 | ||||
| [[package]] | ||||
| name = "h2" | ||||
| version = "0.3.14" | ||||
| @ -524,6 +539,7 @@ version = "0.1.0" | ||||
| dependencies = [ | ||||
|  "reqwest", | ||||
|  "tikv-jemallocator", | ||||
|  "trybuild", | ||||
|  "watto", | ||||
| ] | ||||
| 
 | ||||
| @ -568,9 +584,20 @@ dependencies = [ | ||||
| 
 | ||||
| [[package]] | ||||
| name = "serde" | ||||
| version = "1.0.144" | ||||
| version = "1.0.185" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860" | ||||
| checksum = "be9b6f69f1dfd54c3b568ffa45c310d6973a5e5148fd40cf515acaf38cf5bc31" | ||||
| 
 | ||||
| [[package]] | ||||
| name = "serde_derive" | ||||
| version = "1.0.147" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" | ||||
| dependencies = [ | ||||
|  "proc-macro2", | ||||
|  "quote", | ||||
|  "syn", | ||||
| ] | ||||
| 
 | ||||
| [[package]] | ||||
| name = "serde_json" | ||||
| @ -639,6 +666,15 @@ dependencies = [ | ||||
|  "winapi", | ||||
| ] | ||||
| 
 | ||||
| [[package]] | ||||
| name = "termcolor" | ||||
| version = "1.2.0" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" | ||||
| dependencies = [ | ||||
|  "winapi-util", | ||||
| ] | ||||
| 
 | ||||
| [[package]] | ||||
| name = "thiserror" | ||||
| version = "1.0.33" | ||||
| @ -767,6 +803,21 @@ version = "0.2.3" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" | ||||
| 
 | ||||
| [[package]] | ||||
| name = "trybuild" | ||||
| version = "1.0.80" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "501dbdbb99861e4ab6b60eb6a7493956a9defb644fd034bc4a5ef27c693c8a3a" | ||||
| dependencies = [ | ||||
|  "basic-toml", | ||||
|  "glob", | ||||
|  "once_cell", | ||||
|  "serde", | ||||
|  "serde_derive", | ||||
|  "serde_json", | ||||
|  "termcolor", | ||||
| ] | ||||
| 
 | ||||
| [[package]] | ||||
| name = "unicode-bidi" | ||||
| version = "0.3.8" | ||||
| @ -923,6 +974,15 @@ version = "0.4.0" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" | ||||
| 
 | ||||
| [[package]] | ||||
| name = "winapi-util" | ||||
| version = "0.1.5" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" | ||||
| dependencies = [ | ||||
|  "winapi", | ||||
| ] | ||||
| 
 | ||||
| [[package]] | ||||
| name = "winapi-x86_64-pc-windows-gnu" | ||||
| version = "0.4.0" | ||||
|  | ||||
| @ -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
									
								
								tests/tests/trybuild.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								tests/tests/trybuild.rs
									
									
									
									
									
										Normal file
									
								
							| @ -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
									
								
								tests/tests/trybuild/empty_main.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								tests/tests/trybuild/empty_main.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | ||||
| fn main() {} | ||||
							
								
								
									
										3
									
								
								tests/tests/trybuild/fail_to_compile.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								tests/tests/trybuild/fail_to_compile.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,3 @@ | ||||
| fn main() { | ||||
|     "foobar".foobar(); | ||||
| } | ||||
							
								
								
									
										5
									
								
								tests/tests/trybuild/fail_to_compile.stderr
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								tests/tests/trybuild/fail_to_compile.stderr
									
									
									
									
									
										Normal file
									
								
							| @ -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` | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user