@@ -128,36 +128,6 @@ fn it_supports_wit_keywords() -> Result<()> {
128128 Ok ( ( ) )
129129}
130130
131- #[ test]
132- fn it_adds_a_producers_field ( ) -> Result < ( ) > {
133- let project = Project :: new ( "foo" , true ) ?;
134-
135- project
136- . cargo_component ( [ "build" , "--release" ] )
137- . assert ( )
138- . stderr ( contains ( "Finished `release` profile [optimized] target(s)" ) )
139- . success ( ) ;
140-
141- let path = project. release_wasm ( "foo" ) ;
142-
143- validate_component ( & path) ?;
144-
145- let wasm = fs:: read ( & path)
146- . with_context ( || format ! ( "failed to read wasm file `{path}`" , path = path. display( ) ) ) ?;
147- let section = wasm_metadata:: Producers :: from_wasm ( & wasm) ?. expect ( "missing producers section" ) ;
148-
149- assert_eq ! (
150- section
151- . get( "processed-by" )
152- . expect( "missing processed-by field" )
153- . get( env!( "CARGO_PKG_NAME" ) )
154- . expect( "missing cargo-component field" ) ,
155- option_env!( "CARGO_VERSION_INFO" ) . unwrap_or( env!( "CARGO_PKG_VERSION" ) )
156- ) ;
157-
158- Ok ( ( ) )
159- }
160-
161131#[ test]
162132fn it_builds_wasm32_unknown_unknown_from_cli ( ) -> Result < ( ) > {
163133 let project = Project :: new ( "foo" , true ) ?;
@@ -1008,3 +978,132 @@ edition = "2021"
1008978
1009979 Ok ( ( ) )
1010980}
981+
982+ #[ test]
983+ fn it_adds_a_producers_field ( ) -> Result < ( ) > {
984+ let project = Project :: new ( "foo" , true ) ?;
985+
986+ project
987+ . cargo_component ( [ "build" , "--release" ] )
988+ . assert ( )
989+ . stderr ( contains ( "Finished `release` profile [optimized] target(s)" ) )
990+ . success ( ) ;
991+
992+ let path = project. release_wasm ( "foo" ) ;
993+
994+ validate_component ( & path) ?;
995+
996+ let wasm = fs:: read ( & path)
997+ . with_context ( || format ! ( "failed to read wasm file `{path}`" , path = path. display( ) ) ) ?;
998+ let section = wasm_metadata:: Producers :: from_wasm ( & wasm) ?. expect ( "missing producers section" ) ;
999+
1000+ assert_eq ! (
1001+ section
1002+ . get( "processed-by" )
1003+ . expect( "missing processed-by field" )
1004+ . get( env!( "CARGO_PKG_NAME" ) )
1005+ . expect( "missing cargo-component field" ) ,
1006+ option_env!( "CARGO_VERSION_INFO" ) . unwrap_or( env!( "CARGO_PKG_VERSION" ) )
1007+ ) ;
1008+
1009+ Ok ( ( ) )
1010+ }
1011+
1012+ #[ test]
1013+ fn it_adds_metadata_from_cargo_toml ( ) -> Result < ( ) > {
1014+ let name = "foo" ;
1015+ let authors = "Jane Doe <jane@example.com>" ;
1016+ let description = "A test package" ;
1017+ let license = "Apache-2.0" ;
1018+ let version = "1.0.0" ;
1019+ let documentation = "https://example.com/docs" ;
1020+ let homepage = "https://example.com/home" ;
1021+ let repository = "https://example.com/repo" ;
1022+
1023+ let project = Project :: new ( name, true ) ?;
1024+ project. update_manifest ( |mut doc| {
1025+ let package = & mut doc[ "package" ] ;
1026+ package[ "name" ] = value ( name) ;
1027+ package[ "version" ] = value ( version) ;
1028+ package[ "authors" ] = value ( Array :: from_iter ( [ authors] ) ) ;
1029+ package[ "description" ] = value ( description) ;
1030+ package[ "license" ] = value ( license) ;
1031+ package[ "documentation" ] = value ( documentation) ;
1032+ package[ "homepage" ] = value ( homepage) ;
1033+ package[ "repository" ] = value ( repository) ;
1034+ Ok ( doc)
1035+ } ) ?;
1036+
1037+ project
1038+ . cargo_component ( [ "build" , "--release" ] )
1039+ . assert ( )
1040+ . stderr ( contains ( "Finished `release` profile [optimized] target(s)" ) )
1041+ . success ( ) ;
1042+
1043+ let path = project. release_wasm ( "foo" ) ;
1044+
1045+ validate_component ( & path) ?;
1046+
1047+ let wasm = fs:: read ( & path)
1048+ . with_context ( || format ! ( "failed to read wasm file `{path}`" , path = path. display( ) ) ) ?;
1049+
1050+ let metadata = match wasm_metadata:: Payload :: from_binary ( & wasm) ? {
1051+ wasm_metadata:: Payload :: Component { metadata, .. } => metadata,
1052+ wasm_metadata:: Payload :: Module ( _) => unreachable ! ( "found a wasm module" ) ,
1053+ } ;
1054+
1055+ assert_eq ! (
1056+ & metadata. name. as_ref( ) . expect( "missing name" ) . to_string( ) ,
1057+ name
1058+ ) ;
1059+ assert_eq ! (
1060+ & metadata
1061+ . authors
1062+ . as_ref( )
1063+ . expect( "missing authors" )
1064+ . to_string( ) ,
1065+ authors
1066+ ) ;
1067+ assert_eq ! (
1068+ & metadata
1069+ . description
1070+ . as_ref( )
1071+ . expect( "missing description" )
1072+ . to_string( ) ,
1073+ description
1074+ ) ;
1075+ assert_eq ! (
1076+ & metadata
1077+ . licenses
1078+ . as_ref( )
1079+ . expect( "missing licenses" )
1080+ . to_string( ) ,
1081+ license
1082+ ) ;
1083+ assert_eq ! (
1084+ & metadata
1085+ . source
1086+ . as_ref( )
1087+ . expect( "missing source" )
1088+ . to_string( ) ,
1089+ repository
1090+ ) ;
1091+ assert_eq ! (
1092+ & metadata
1093+ . homepage
1094+ . as_ref( )
1095+ . expect( "missing homepage" )
1096+ . to_string( ) ,
1097+ homepage
1098+ ) ;
1099+ assert_eq ! (
1100+ & metadata
1101+ . version
1102+ . as_ref( )
1103+ . expect( "missing version" )
1104+ . to_string( ) ,
1105+ version
1106+ ) ;
1107+
1108+ Ok ( ( ) )
1109+ }
0 commit comments