@@ -11,20 +11,24 @@ use snapbox::{
1111 cmd:: { cargo_bin, Command as SnapboxCommand } ,
1212} ;
1313use std:: {
14+ env:: var,
1415 ffi:: OsStr ,
1516 fs:: { read_dir, read_to_string} ,
17+ path:: { Path , PathBuf } ,
1618 process:: Command ,
1719} ;
18- use tempfile:: tempdir;
1920
2021mod util;
2122use util:: { enabled, tee, token_modifier, Tee } ;
2223
2324#[ derive( Deserialize ) ]
2425#[ serde( deny_unknown_fields) ]
2526struct Test {
26- /// Repo url
27- url : String ,
27+ /// Repo path (cannot be used in conjunction with `url`)
28+ path : Option < String > ,
29+
30+ /// Repo url (cannot be used in conjunction with `path`)
31+ url : Option < String > ,
2832
2933 /// Repo revision; `None` (the default) means the head of the default branch
3034 #[ serde( default ) ]
@@ -33,16 +37,22 @@ struct Test {
3337
3438#[ test]
3539fn snapbox ( ) -> Result < ( ) > {
36- let mut read_dir = read_dir ( "tests/cases" ) ?;
37-
38- let test_paths = read_dir. try_fold ( Vec :: new ( ) , |mut url_paths, entry| {
39- let entry = entry?;
40- let path = entry. path ( ) ;
41- if path. extension ( ) == Some ( OsStr :: new ( "toml" ) ) {
42- url_paths. push ( path) ;
43- }
44- Result :: < _ > :: Ok ( url_paths)
45- } ) ?;
40+ let test_cases = Path :: new ( "tests/cases" ) ;
41+
42+ let test_paths = if let Ok ( testcase) = var ( "TESTCASE" ) {
43+ vec ! [ test_cases. join( testcase) . with_extension( "toml" ) ]
44+ } else {
45+ let mut read_dir = read_dir ( test_cases) ?;
46+
47+ read_dir. try_fold ( Vec :: new ( ) , |mut url_paths, entry| {
48+ let entry = entry?;
49+ let path = entry. path ( ) ;
50+ if path. extension ( ) == Some ( OsStr :: new ( "toml" ) ) {
51+ url_paths. push ( path) ;
52+ }
53+ Result :: < _ > :: Ok ( url_paths)
54+ } ) ?
55+ } ;
4656
4757 test_paths
4858 . into_par_iter ( )
@@ -55,32 +65,43 @@ fn snapbox() -> Result<()> {
5565
5666 let test: Test = toml:: from_str ( & raw ) . unwrap ( ) ;
5767
58- let tempdir = tempdir ( ) ?;
59-
60- let mut command = SnapboxCommand :: new ( "git" ) . args ( [
61- "clone" ,
62- & test. url ,
63- & tempdir. path ( ) . to_string_lossy ( ) ,
64- ] ) ;
65- if test. rev . is_none ( ) {
66- command = command. arg ( "--depth=1" ) ;
67- }
68- command. assert ( ) . success ( ) ;
69-
70- if let Some ( rev) = & test. rev {
71- SnapboxCommand :: new ( "git" )
72- . args ( [ "checkout" , rev] )
73- . current_dir ( & tempdir)
74- . assert ( )
75- . success ( ) ;
76- }
68+ let tempdir;
69+ let dir = match ( test. path , test. url ) {
70+ ( Some ( path) , None ) => PathBuf :: from ( path) ,
71+ ( None , Some ( url) ) => {
72+ tempdir = tempfile:: tempdir ( ) ?;
73+
74+ let mut command = SnapboxCommand :: new ( "git" ) . args ( [
75+ "clone" ,
76+ & url,
77+ & tempdir. path ( ) . to_string_lossy ( ) ,
78+ ] ) ;
79+ if test. rev . is_none ( ) {
80+ command = command. arg ( "--depth=1" ) ;
81+ }
82+ command. assert ( ) . success ( ) ;
83+
84+ if let Some ( rev) = & test. rev {
85+ SnapboxCommand :: new ( "git" )
86+ . args ( [ "checkout" , rev] )
87+ . current_dir ( & tempdir)
88+ . assert ( )
89+ . success ( ) ;
90+ }
91+ tempdir. path ( ) . to_owned ( )
92+ }
93+ ( _, _) => {
94+ panic ! ( "exactly one of `path` and `url` must be set" ) ;
95+ }
96+ } ;
7797
78- assert ! ( tempdir. path( ) . join( "Cargo.lock" ) . exists( ) ) ;
98+ let path = dir. join ( "Cargo.lock" ) ;
99+ assert ! ( path. exists( ) , "{path:?} does not exist" ) ;
79100
80101 let mut command = Command :: new ( cargo_bin ( "cargo-unmaintained" ) ) ;
81102 command
82103 . args ( [ "unmaintained" , "--color=never" , "--imprecise" ] )
83- . current_dir ( & tempdir ) ;
104+ . current_dir ( dir ) ;
84105
85106 if enabled ( "VERBOSE" ) {
86107 // smoelius If `VERBOSE` is enabled, don't bother comparing stderr, because it won't
0 commit comments