@@ -2,6 +2,7 @@ use predicates::prelude::predicate;
2
2
use soroban_cli:: xdr:: { Limited , Limits , ReadXdr , ScMetaEntry , ScMetaV0 } ;
3
3
use soroban_spec_tools:: contract:: Spec ;
4
4
use soroban_test:: TestEnv ;
5
+ use std:: env;
5
6
use std:: io:: Cursor ;
6
7
7
8
#[ test]
@@ -16,11 +17,9 @@ fn build_all() {
16
17
. arg ( "--print-commands-only" )
17
18
. assert ( )
18
19
. success ( )
19
- . stdout ( predicate:: eq ( "\
20
- cargo rustc --manifest-path=contracts/add/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
20
+ . stdout ( predicate:: eq ( with_flags ( "cargo rustc --manifest-path=contracts/add/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
21
21
cargo rustc --manifest-path=contracts/call/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
22
- cargo rustc --manifest-path=contracts/add/add2/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
23
- " ) ) ;
22
+ cargo rustc --manifest-path=contracts/add/add2/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release" ) ) ) ;
24
23
}
25
24
26
25
#[ test]
@@ -36,9 +35,7 @@ fn build_package_by_name() {
36
35
. arg ( "--package=add" )
37
36
. assert ( )
38
37
. success ( )
39
- . stdout ( predicate:: eq ( "\
40
- cargo rustc --manifest-path=contracts/add/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
41
- " ) ) ;
38
+ . stdout ( predicate:: eq ( with_flags ( "cargo rustc --manifest-path=contracts/add/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release" ) ) ) ;
42
39
}
43
40
44
41
#[ test]
@@ -54,9 +51,7 @@ fn build_package_by_current_dir() {
54
51
. assert ( )
55
52
. success ( )
56
53
. stdout ( predicate:: eq (
57
- "\
58
- cargo rustc --manifest-path=Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
59
- " ,
54
+ with_flags ( "cargo rustc --manifest-path=Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release" ) ,
60
55
) ) ;
61
56
}
62
57
@@ -85,20 +80,17 @@ fn build_all_when_in_non_package_directory() {
85
80
let sandbox = TestEnv :: default ( ) ;
86
81
let cargo_dir = std:: path:: PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
87
82
let fixture_path = cargo_dir. join ( "tests/fixtures/workspace/contracts/add/src/" ) ;
83
+
88
84
sandbox
89
85
. new_assert_cmd ( "contract" )
90
86
. current_dir ( fixture_path)
91
87
. arg ( "build" )
92
88
. arg ( "--print-commands-only" )
93
89
. assert ( )
94
90
. success ( )
95
- . stdout ( predicate:: eq (
96
- "\
97
- cargo rustc --manifest-path=../Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
98
- cargo rustc --manifest-path=../../call/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
99
- cargo rustc --manifest-path=../add2/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
100
- " ,
101
- ) ) ;
91
+ . stdout ( predicate:: eq ( with_flags (
92
+ "cargo rustc --manifest-path=../Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release"
93
+ ) ) ) ;
102
94
}
103
95
104
96
#[ test]
@@ -113,11 +105,7 @@ fn build_default_members() {
113
105
. arg ( "--print-commands-only" )
114
106
. assert ( )
115
107
. success ( )
116
- . stdout ( predicate:: eq (
117
- "\
118
- cargo rustc --manifest-path=contracts/add/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
119
- " ,
120
- ) ) ;
108
+ . stdout ( predicate:: eq ( with_flags ( "cargo rustc --manifest-path=contracts/add/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release" ) ) ) ;
121
109
}
122
110
123
111
#[ test]
@@ -185,3 +173,30 @@ fn build_with_metadata() {
185
173
186
174
assert_eq ! ( entries, expected_entries) ;
187
175
}
176
+
177
+ fn with_flags ( expected : & str ) -> String {
178
+ let cargo_home = home:: cargo_home ( ) . unwrap ( ) ;
179
+ let cargo_home = format ! ( "{}" , cargo_home. display( ) ) ;
180
+ let registry_prefix = format ! ( "{cargo_home}/registry/src/" ) ;
181
+
182
+ let vec: Vec < _ > = if env:: var ( "RUSTFLAGS" ) . is_ok ( ) {
183
+ expected. split ( "\n " ) . map ( |x| x. to_string ( ) ) . collect ( )
184
+ } else {
185
+ expected
186
+ . split ( "\n " )
187
+ . map ( |x| {
188
+ format ! (
189
+ "CARGO_BUILD_RUSTFLAGS=--remap-path-prefix={}= {}" ,
190
+ registry_prefix, x
191
+ )
192
+ } )
193
+ . collect ( )
194
+ } ;
195
+
196
+ return format ! (
197
+ "\
198
+ {}
199
+ " ,
200
+ vec. join( "\n " )
201
+ ) ;
202
+ }
0 commit comments