@@ -832,6 +832,55 @@ impl Runner<'_> {
832
832
runner_wasm : & Path ,
833
833
test_components : & [ ( & Component , & Path ) ] ,
834
834
) -> Result < ( ) > {
835
+ // If possible use `wasm-compose` to compose the test together. This is
836
+ // only possible when customization isn't used though. This is also only
837
+ // done for async tests at this time to ensure that there's a version of
838
+ // composition that's done which is at the same version as wasmparser
839
+ // and friends.
840
+ let composed = if case. config . wac . is_none ( ) && test_components. len ( ) == 1 {
841
+ self . compose_wasm_with_wasm_compose ( runner_wasm, test_components) ?
842
+ } else {
843
+ self . compose_wasm_with_wac ( case, runner, runner_wasm, test_components) ?
844
+ } ;
845
+
846
+ let dst = runner_wasm. parent ( ) . unwrap ( ) ;
847
+ let mut filename = format ! (
848
+ "composed-{}" ,
849
+ runner. path. file_name( ) . unwrap( ) . to_str( ) . unwrap( ) ,
850
+ ) ;
851
+ for ( test, _) in test_components {
852
+ filename. push_str ( "-" ) ;
853
+ filename. push_str ( test. path . file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ) ;
854
+ }
855
+ filename. push_str ( ".wasm" ) ;
856
+ let composed_wasm = dst. join ( filename) ;
857
+ write_if_different ( & composed_wasm, & composed) ?;
858
+
859
+ self . run_command ( self . test_runner . command ( ) . arg ( & composed_wasm) ) ?;
860
+ Ok ( ( ) )
861
+ }
862
+
863
+ fn compose_wasm_with_wasm_compose (
864
+ & self ,
865
+ runner_wasm : & Path ,
866
+ test_components : & [ ( & Component , & Path ) ] ,
867
+ ) -> Result < Vec < u8 > > {
868
+ assert ! ( test_components. len( ) == 1 ) ;
869
+ let test_wasm = test_components[ 0 ] . 1 ;
870
+ let mut config = wasm_compose:: config:: Config :: default ( ) ;
871
+ config. definitions = vec ! [ test_wasm. to_path_buf( ) ] ;
872
+ wasm_compose:: composer:: ComponentComposer :: new ( runner_wasm, & config)
873
+ . compose ( )
874
+ . with_context ( || format ! ( "failed to compose {runner_wasm:?} with {test_wasm:?}" ) )
875
+ }
876
+
877
+ fn compose_wasm_with_wac (
878
+ & self ,
879
+ case : & Test ,
880
+ runner : & Component ,
881
+ runner_wasm : & Path ,
882
+ test_components : & [ ( & Component , & Path ) ] ,
883
+ ) -> Result < Vec < u8 > > {
835
884
let document = match & case. config . wac {
836
885
Some ( path) => {
837
886
let wac_config = case. path . join ( path) ;
@@ -891,31 +940,15 @@ impl Runner<'_> {
891
940
// TODO: should figure out how to render these errors better.
892
941
let document =
893
942
wac_parser:: Document :: parse ( & document) . context ( "failed to parse wac script" ) ?;
894
- let composed = document
943
+ document
895
944
. resolve ( packages)
896
945
. context ( "failed to run `wac` resolve" ) ?
897
946
. encode ( wac_graph:: EncodeOptions {
898
947
define_components : true ,
899
948
validate : false ,
900
949
processor : None ,
901
950
} )
902
- . context ( "failed to encode `wac` result" ) ?;
903
-
904
- let dst = runner_wasm. parent ( ) . unwrap ( ) ;
905
- let mut filename = format ! (
906
- "composed-{}" ,
907
- runner. path. file_name( ) . unwrap( ) . to_str( ) . unwrap( ) ,
908
- ) ;
909
- for ( test, _) in test_components {
910
- filename. push_str ( "-" ) ;
911
- filename. push_str ( test. path . file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ) ;
912
- }
913
- filename. push_str ( ".wasm" ) ;
914
- let composed_wasm = dst. join ( filename) ;
915
- write_if_different ( & composed_wasm, & composed) ?;
916
-
917
- self . run_command ( self . test_runner . command ( ) . arg ( & composed_wasm) ) ?;
918
- Ok ( ( ) )
951
+ . context ( "failed to encode `wac` result" )
919
952
}
920
953
921
954
/// Helper to execute an external process and generate a helpful error
0 commit comments