@@ -9,6 +9,7 @@ use forge::Template;
9
9
use forge:: scarb:: config:: SCARB_MANIFEST_TEMPLATE_CONTENT ;
10
10
use indoc:: { formatdoc, indoc} ;
11
11
use regex:: Regex ;
12
+ use scarb_api:: ScarbCommand ;
12
13
use shared:: consts:: FREE_RPC_PROVIDER_URL ;
13
14
use shared:: test_utils:: output_assert:: assert_stdout_contains;
14
15
use snapbox:: assert_matches;
@@ -43,7 +44,7 @@ fn init_new_project() {
43
44
) ,
44
45
) ;
45
46
46
- validate_init ( & temp. join ( "test_name" ) , false , & Template :: BalanceContract ) ;
47
+ validate_init ( & temp. join ( "test_name" ) , None , & Template :: BalanceContract ) ;
47
48
}
48
49
49
50
#[ test_case( & Template :: CairoProgram ; "cairo-program" ) ]
@@ -66,7 +67,7 @@ fn create_new_project_dir_not_exist(template: &Template) {
66
67
. assert ( )
67
68
. success ( ) ;
68
69
69
- validate_init ( & project_path, false , template) ;
70
+ validate_init ( & project_path, None , template) ;
70
71
}
71
72
72
73
#[ test]
@@ -105,35 +106,73 @@ fn create_new_project_dir_exists_and_empty() {
105
106
. assert ( )
106
107
. success ( ) ;
107
108
108
- validate_init ( & project_path, false , & Template :: BalanceContract ) ;
109
+ validate_init ( & project_path, None , & Template :: BalanceContract ) ;
109
110
}
110
111
111
112
#[ test]
112
113
fn init_new_project_from_scarb ( ) {
113
114
let temp = tempdir_with_tool_versions ( ) . unwrap ( ) ;
114
115
115
- SnapboxCommand :: new ( "scarb" )
116
- . current_dir ( & temp)
117
- . args ( [ "new" , "test_name" ] )
118
- . env ( "SCARB_INIT_TEST_RUNNER" , "starknet-foundry" )
119
- . env (
120
- "PATH" ,
121
- append_to_path_var ( snforge_test_bin_path ( ) . parent ( ) . unwrap ( ) ) ,
122
- )
123
- . assert ( )
124
- . success ( ) ;
125
-
126
- validate_init ( & temp. join ( "test_name" ) , true , & Template :: BalanceContract ) ;
116
+ SnapboxCommand :: from_std (
117
+ ScarbCommand :: new ( )
118
+ . current_dir ( temp. path ( ) )
119
+ . args ( [ "new" , "test_name" ] )
120
+ . env ( "SCARB_INIT_TEST_RUNNER" , "starknet-foundry" )
121
+ . env (
122
+ "PATH" ,
123
+ append_to_path_var ( snforge_test_bin_path ( ) . parent ( ) . unwrap ( ) ) ,
124
+ )
125
+ . command ( ) ,
126
+ )
127
+ . assert ( )
128
+ . success ( ) ;
129
+
130
+ validate_init (
131
+ & temp. join ( "test_name" ) ,
132
+ Some ( SnforgeStd :: Normal ) ,
133
+ & Template :: BalanceContract ,
134
+ ) ;
127
135
}
128
136
137
+ #[ test]
138
+ #[ cfg_attr( not( feature = "scarb_2_9_1" ) , ignore) ]
139
+ fn init_new_project_from_scarb_with_snforge_std_compatibility ( ) {
140
+ let temp = tempdir_with_tool_versions ( ) . unwrap ( ) ;
141
+ let tool_version_path = temp. join ( ".tool-versions" ) ;
142
+ fs:: write ( tool_version_path, "scarb 2.11.4" ) . unwrap ( ) ;
143
+
144
+ SnapboxCommand :: from_std (
145
+ ScarbCommand :: new ( )
146
+ . current_dir ( temp. path ( ) )
147
+ . args ( [ "new" , "test_name" ] )
148
+ . env ( "SCARB_INIT_TEST_RUNNER" , "starknet-foundry" )
149
+ . env (
150
+ "PATH" ,
151
+ append_to_path_var ( snforge_test_bin_path ( ) . parent ( ) . unwrap ( ) ) ,
152
+ )
153
+ . command ( ) ,
154
+ )
155
+ . assert ( )
156
+ . success ( ) ;
157
+
158
+ validate_init (
159
+ & temp. join ( "test_name" ) ,
160
+ Some ( SnforgeStd :: Compatibility ) ,
161
+ & Template :: BalanceContract ,
162
+ ) ;
163
+ }
129
164
pub fn append_to_path_var ( path : & Path ) -> OsString {
130
165
let script_path = iter:: once ( path. to_path_buf ( ) ) ;
131
166
let os_path = env:: var_os ( "PATH" ) . unwrap ( ) ;
132
167
let other_paths = env:: split_paths ( & os_path) ;
133
168
env:: join_paths ( script_path. chain ( other_paths) ) . unwrap ( )
134
169
}
135
170
136
- fn validate_init ( project_path : & PathBuf , validate_snforge_std : bool , template : & Template ) {
171
+ fn validate_init (
172
+ project_path : & PathBuf ,
173
+ validate_snforge_std : Option < SnforgeStd > ,
174
+ template : & Template ,
175
+ ) {
137
176
let manifest_path = project_path. join ( "Scarb.toml" ) ;
138
177
let scarb_toml = fs:: read_to_string ( manifest_path. clone ( ) ) . unwrap ( ) ;
139
178
@@ -160,7 +199,7 @@ fn validate_init(project_path: &PathBuf, validate_snforge_std: bool, template: &
160
199
dependencies. remove ( "snforge_std" ) ;
161
200
dependencies. insert ( "snforge_std" , Item :: Value ( Value :: InlineTable ( snforge_std) ) ) ;
162
201
163
- std :: fs:: write ( manifest_path, scarb_toml. to_string ( ) ) . unwrap ( ) ;
202
+ fs:: write ( manifest_path, scarb_toml. to_string ( ) ) . unwrap ( ) ;
164
203
165
204
let output = test_runner ( & TempDir :: new ( ) . unwrap ( ) )
166
205
. current_dir ( project_path)
@@ -171,11 +210,21 @@ fn validate_init(project_path: &PathBuf, validate_snforge_std: bool, template: &
171
210
assert_stdout_contains ( output, expected) ;
172
211
}
173
212
174
- fn get_expected_manifest_content ( template : & Template , validate_snforge_std : bool ) -> String {
175
- let snforge_std_assert = if validate_snforge_std {
176
- "\n snforge_std = \" [..]\" "
177
- } else {
178
- ""
213
+ enum SnforgeStd {
214
+ Normal ,
215
+ Compatibility ,
216
+ }
217
+
218
+ fn get_expected_manifest_content (
219
+ template : & Template ,
220
+ validate_snforge_std : Option < SnforgeStd > ,
221
+ ) -> String {
222
+ let snforge_std_assert = match validate_snforge_std {
223
+ None => "" ,
224
+ Some ( snforge_std) => match snforge_std {
225
+ SnforgeStd :: Normal => "\n snforge_std = \" [..]\" " ,
226
+ SnforgeStd :: Compatibility => "\n snforge_std_compatibility = \" [..]\" " ,
227
+ } ,
179
228
} ;
180
229
181
230
let target_contract_entry = "[[target.starknet-contract]]\n sierra = true" ;
0 commit comments