@@ -96,12 +96,11 @@ impl Manifest {
9696 let toolchain_value = serde_json:: to_value ( toolchain) . unknown ( ) ?;
9797 map. insert ( "toolchain" . to_string ( ) , toolchain_value) ;
9898
99- // TODO: write to file
99+ // serialize the updated contents back to package.json
100100 let file = File :: create ( package_file) . unknown ( ) ?;
101101 let formatter =
102102 serde_json:: ser:: PrettyFormatter :: with_indent ( indent. indent ( ) . as_bytes ( ) ) ;
103103 let mut ser = serde_json:: Serializer :: with_formatter ( file, formatter) ;
104-
105104 map. serialize ( & mut ser) . unknown ( ) ?;
106105 }
107106 Ok ( ( ) )
@@ -128,39 +127,21 @@ pub mod tests {
128127 #[ test]
129128 fn gets_node_version ( ) {
130129 let project_path = fixture_path ( "basic" ) ;
131- let version = match Manifest :: for_dir ( & project_path) {
132- Ok ( manifest) => manifest. node ( ) . unwrap ( ) ,
133- _ => panic ! (
134- "Error: Could not get manifest for project {:?}" ,
135- project_path
136- ) ,
137- } ;
130+ let version = Manifest :: for_dir ( & project_path) . expect ( "Could not get manifest" ) . node ( ) . unwrap ( ) ;
138131 assert_eq ! ( version, VersionReq :: parse( "=6.11.1" ) . unwrap( ) ) ;
139132 }
140133
141134 #[ test]
142135 fn gets_yarn_version ( ) {
143136 let project_path = fixture_path ( "basic" ) ;
144- let version = match Manifest :: for_dir ( & project_path) {
145- Ok ( manifest) => manifest. yarn ( ) ,
146- _ => panic ! (
147- "Error: Could not get manifest for project {:?}" ,
148- project_path
149- ) ,
150- } ;
137+ let version = Manifest :: for_dir ( & project_path) . expect ( "Could not get manifest" ) . yarn ( ) ;
151138 assert_eq ! ( version. unwrap( ) , VersionReq :: parse( "=1.2" ) . unwrap( ) ) ;
152139 }
153140
154141 #[ test]
155142 fn gets_dependencies ( ) {
156143 let project_path = fixture_path ( "basic" ) ;
157- let dependencies = match Manifest :: for_dir ( & project_path) {
158- Ok ( manifest) => manifest. dependencies ,
159- _ => panic ! (
160- "Error: Could not get manifest for project {:?}" ,
161- project_path
162- ) ,
163- } ;
144+ let dependencies = Manifest :: for_dir ( & project_path) . expect ( "Could not get manifest" ) . dependencies ;
164145 let mut expected_deps = HashMap :: new ( ) ;
165146 expected_deps. insert ( "@namespace/some-dep" . to_string ( ) , "0.2.4" . to_string ( ) ) ;
166147 expected_deps. insert ( "rsvp" . to_string ( ) , "^3.5.0" . to_string ( ) ) ;
@@ -170,13 +151,7 @@ pub mod tests {
170151 #[ test]
171152 fn gets_dev_dependencies ( ) {
172153 let project_path = fixture_path ( "basic" ) ;
173- let dev_dependencies = match Manifest :: for_dir ( & project_path) {
174- Ok ( manifest) => manifest. dev_dependencies ,
175- _ => panic ! (
176- "Error: Could not get manifest for project {:?}" ,
177- project_path
178- ) ,
179- } ;
154+ let dev_dependencies = Manifest :: for_dir ( & project_path) . expect ( "Could not get manifest" ) . dev_dependencies ;
180155 let mut expected_deps = HashMap :: new ( ) ;
181156 expected_deps. insert (
182157 "@namespaced/something-else" . to_string ( ) ,
@@ -189,26 +164,14 @@ pub mod tests {
189164 #[ test]
190165 fn node_for_no_toolchain ( ) {
191166 let project_path = fixture_path ( "no_toolchain" ) ;
192- let manifest = match Manifest :: for_dir ( & project_path) {
193- Ok ( manifest) => manifest,
194- _ => panic ! (
195- "Error: Could not get manifest for project {:?}" ,
196- project_path
197- ) ,
198- } ;
167+ let manifest = Manifest :: for_dir ( & project_path) . expect ( "Could not get manifest" ) ;
199168 assert_eq ! ( manifest. node( ) , None ) ;
200169 }
201170
202171 #[ test]
203172 fn yarn_for_no_toolchain ( ) {
204173 let project_path = fixture_path ( "no_toolchain" ) ;
205- let manifest = match Manifest :: for_dir ( & project_path) {
206- Ok ( manifest) => manifest,
207- _ => panic ! (
208- "Error: Could not get manifest for project {:?}" ,
209- project_path
210- ) ,
211- } ;
174+ let manifest = Manifest :: for_dir ( & project_path) . expect ( "Could not get manifest" ) ;
212175 assert_eq ! ( manifest. yarn( ) , None ) ;
213176 }
214177
0 commit comments