Skip to content

Commit 7fe01cc

Browse files
committed
Import component dependencies in tests instead of defining inline.
The tests will now import the component dependencies instead of copying them inline which will both test encoding a bit more and hopefully make the encoded wat a wee bit easier to read.
1 parent f398c13 commit 7fe01cc

3 files changed

Lines changed: 99 additions & 187 deletions

File tree

crates/wac-graph/tests/encoding.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,13 @@ fn encoding() -> Result<()> {
312312
.into_composition_graph(&path, test_case)
313313
.and_then(|graph| {
314314
graph
315-
.encode(EncodeOptions::default())
315+
.encode(EncodeOptions {
316+
// We import the component definitions instead
317+
// of defining them inline to make the encoded wat
318+
// more readable and to test encoding a bit more.
319+
define_components: false,
320+
validate: true,
321+
})
316322
.context("failed to encode the graph")
317323
});
318324

crates/wac-graph/tests/graphs/merged-usings/encoded.wat

Lines changed: 56 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -16,178 +16,78 @@
1616
)
1717
)
1818
(import "foo:bar/qux" (instance (;1;) (type 2)))
19-
(component (;0;)
20-
(type (;0;)
21-
(instance
22-
(export (;0;) "x" (type (sub resource)))
19+
(type (;3;)
20+
(component
21+
(type (;0;)
22+
(instance
23+
(export (;0;) "x" (type (sub resource)))
24+
)
2325
)
24-
)
25-
(import "foo:bar/baz" (instance (;0;) (type 0)))
26-
(alias export 0 "x" (type (;1;)))
27-
(type (;2;)
28-
(instance
29-
(alias outer 1 1 (type (;0;)))
30-
(export (;1;) "x" (type (eq 0)))
31-
(type (;2;) (own 1))
32-
(type (;3;) (func (result 2)))
33-
(export (;0;) "f" (func (type 3)))
34-
)
35-
)
36-
(import "foo:bar/qux" (instance (;1;) (type 2)))
37-
(core module (;0;)
38-
(type (;0;) (func (param i32)))
39-
(type (;1;) (func (result i32)))
40-
(type (;2;) (func (param i32 i32 i32 i32) (result i32)))
41-
(import "foo:bar/baz" "[resource-drop]x" (func (;0;) (type 0)))
42-
(import "foo:bar/qux" "f" (func (;1;) (type 1)))
43-
(func (;2;) (type 1) (result i32)
44-
unreachable
45-
)
46-
(func (;3;) (type 2) (param i32 i32 i32 i32) (result i32)
47-
unreachable
48-
)
49-
(memory (;0;) 0)
50-
(export "foo:bar/qux#f" (func 2))
51-
(export "memory" (memory 0))
52-
(export "cabi_realloc" (func 3))
53-
(@producers
54-
(processed-by "wit-component" "0.202.0")
55-
)
56-
)
57-
(alias export 0 "x" (type (;3;)))
58-
(core func (;0;) (canon resource.drop 3))
59-
(core instance (;0;)
60-
(export "[resource-drop]x" (func 0))
61-
)
62-
(alias export 1 "f" (func (;0;)))
63-
(core func (;1;) (canon lower (func 0)))
64-
(core instance (;1;)
65-
(export "f" (func 1))
66-
)
67-
(core instance (;2;) (instantiate 0
68-
(with "foo:bar/baz" (instance 0))
69-
(with "foo:bar/qux" (instance 1))
26+
(import "foo:bar/baz" (instance (;0;) (type 0)))
27+
(alias export 0 "x" (type (;1;)))
28+
(type (;2;)
29+
(instance
30+
(alias outer 1 1 (type (;0;)))
31+
(export (;1;) "x" (type (eq 0)))
32+
(type (;2;) (own 1))
33+
(type (;3;) (func (result 2)))
34+
(export (;0;) "f" (func (type 3)))
35+
)
7036
)
71-
)
72-
(alias core export 2 "memory" (core memory (;0;)))
73-
(alias core export 2 "cabi_realloc" (core func (;2;)))
74-
(alias export 0 "x" (type (;4;)))
75-
(type (;5;) (own 4))
76-
(type (;6;) (func (result 5)))
77-
(alias core export 2 "foo:bar/qux#f" (core func (;3;)))
78-
(func (;1;) (type 6) (canon lift (core func 3)))
79-
(alias export 0 "x" (type (;7;)))
80-
(component (;0;)
81-
(import "import-type-x" (type (;0;) (sub resource)))
82-
(import "import-type-x0" (type (;1;) (eq 0)))
83-
(type (;2;) (own 1))
84-
(type (;3;) (func (result 2)))
85-
(import "import-func-f" (func (;0;) (type 3)))
86-
(export (;4;) "x" (type 0))
87-
(type (;5;) (own 4))
88-
(type (;6;) (func (result 5)))
89-
(export (;1;) "f" (func 0) (func (type 6)))
90-
)
91-
(instance (;2;) (instantiate 0
92-
(with "import-func-f" (func 1))
93-
(with "import-type-x" (type 7))
94-
(with "import-type-x0" (type 4))
37+
(import "foo:bar/qux" (instance (;1;) (type 2)))
38+
(alias export 0 "x" (type (;3;)))
39+
(type (;4;)
40+
(instance
41+
(alias outer 1 3 (type (;0;)))
42+
(export (;1;) "x" (type (eq 0)))
43+
(type (;2;) (own 1))
44+
(type (;3;) (func (result 2)))
45+
(export (;0;) "f" (func (type 3)))
46+
)
9547
)
96-
)
97-
(export (;3;) "foo:bar/qux" (instance 2))
98-
(@producers
99-
(processed-by "wit-component" "0.202.0")
48+
(export (;2;) "foo:bar/qux" (instance (type 4)))
10049
)
10150
)
51+
(import "unlocked-dep=<test:bar>" (component (;0;) (type 3)))
10252
(instance $component2 (;2;) (instantiate 0
10353
(with "foo:bar/baz" (instance 0))
10454
(with "foo:bar/qux" (instance 1))
10555
)
10656
)
10757
(alias export $component2 "foo:bar/qux" (instance $alias (;3;)))
108-
(component (;1;)
109-
(type (;0;)
110-
(instance
111-
(export (;0;) "x" (type (sub resource)))
58+
(type (;4;)
59+
(component
60+
(type (;0;)
61+
(instance
62+
(export (;0;) "x" (type (sub resource)))
63+
)
11264
)
113-
)
114-
(import "foo:bar/baz" (instance (;0;) (type 0)))
115-
(alias export 0 "x" (type (;1;)))
116-
(type (;2;)
117-
(instance
118-
(alias outer 1 1 (type (;0;)))
119-
(export (;1;) "x" (type (eq 0)))
120-
(type (;2;) (own 1))
121-
(type (;3;) (func (result 2)))
122-
(export (;0;) "f" (func (type 3)))
123-
)
124-
)
125-
(import "foo:bar/qux" (instance (;1;) (type 2)))
126-
(core module (;0;)
127-
(type (;0;) (func (param i32)))
128-
(type (;1;) (func (result i32)))
129-
(type (;2;) (func (param i32 i32 i32 i32) (result i32)))
130-
(import "foo:bar/baz" "[resource-drop]x" (func (;0;) (type 0)))
131-
(import "foo:bar/qux" "f" (func (;1;) (type 1)))
132-
(func (;2;) (type 1) (result i32)
133-
unreachable
134-
)
135-
(func (;3;) (type 2) (param i32 i32 i32 i32) (result i32)
136-
unreachable
137-
)
138-
(memory (;0;) 0)
139-
(export "foo:bar/qux#f" (func 2))
140-
(export "memory" (memory 0))
141-
(export "cabi_realloc" (func 3))
142-
(@producers
143-
(processed-by "wit-component" "0.202.0")
144-
)
145-
)
146-
(alias export 0 "x" (type (;3;)))
147-
(core func (;0;) (canon resource.drop 3))
148-
(core instance (;0;)
149-
(export "[resource-drop]x" (func 0))
150-
)
151-
(alias export 1 "f" (func (;0;)))
152-
(core func (;1;) (canon lower (func 0)))
153-
(core instance (;1;)
154-
(export "f" (func 1))
155-
)
156-
(core instance (;2;) (instantiate 0
157-
(with "foo:bar/baz" (instance 0))
158-
(with "foo:bar/qux" (instance 1))
65+
(import "foo:bar/baz" (instance (;0;) (type 0)))
66+
(alias export 0 "x" (type (;1;)))
67+
(type (;2;)
68+
(instance
69+
(alias outer 1 1 (type (;0;)))
70+
(export (;1;) "x" (type (eq 0)))
71+
(type (;2;) (own 1))
72+
(type (;3;) (func (result 2)))
73+
(export (;0;) "f" (func (type 3)))
74+
)
15975
)
160-
)
161-
(alias core export 2 "memory" (core memory (;0;)))
162-
(alias core export 2 "cabi_realloc" (core func (;2;)))
163-
(alias export 0 "x" (type (;4;)))
164-
(type (;5;) (own 4))
165-
(type (;6;) (func (result 5)))
166-
(alias core export 2 "foo:bar/qux#f" (core func (;3;)))
167-
(func (;1;) (type 6) (canon lift (core func 3)))
168-
(alias export 0 "x" (type (;7;)))
169-
(component (;0;)
170-
(import "import-type-x" (type (;0;) (sub resource)))
171-
(import "import-type-x0" (type (;1;) (eq 0)))
172-
(type (;2;) (own 1))
173-
(type (;3;) (func (result 2)))
174-
(import "import-func-f" (func (;0;) (type 3)))
175-
(export (;4;) "x" (type 0))
176-
(type (;5;) (own 4))
177-
(type (;6;) (func (result 5)))
178-
(export (;1;) "f" (func 0) (func (type 6)))
179-
)
180-
(instance (;2;) (instantiate 0
181-
(with "import-func-f" (func 1))
182-
(with "import-type-x" (type 7))
183-
(with "import-type-x0" (type 4))
76+
(import "foo:bar/qux" (instance (;1;) (type 2)))
77+
(alias export 0 "x" (type (;3;)))
78+
(type (;4;)
79+
(instance
80+
(alias outer 1 3 (type (;0;)))
81+
(export (;1;) "x" (type (eq 0)))
82+
(type (;2;) (own 1))
83+
(type (;3;) (func (result 2)))
84+
(export (;0;) "f" (func (type 3)))
85+
)
18486
)
185-
)
186-
(export (;3;) "foo:bar/qux" (instance 2))
187-
(@producers
188-
(processed-by "wit-component" "0.202.0")
87+
(export (;2;) "foo:bar/qux" (instance (type 4)))
18988
)
19089
)
90+
(import "unlocked-dep=<test:foo>" (component (;1;) (type 4)))
19191
(instance $component1 (;4;) (instantiate 1
19292
(with "foo:bar/qux" (instance $alias))
19393
(with "foo:bar/baz" (instance 0))

crates/wac-graph/tests/graphs/simple/encoded.wat

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,49 +18,55 @@
1818
(import "i2" (instance (;2;) (type 2)))
1919
(type (;3;) (func))
2020
(import "my-foo" (func $my-foo (;0;) (type 3)))
21-
(component (;0;)
22-
(type (;0;) (func))
23-
(type (;1;) (func))
24-
(import "foo" (func (;0;) (type 1)))
25-
(type (;2;)
26-
(instance)
27-
)
28-
(import "i1" (instance (;0;) (type 2)))
29-
(type (;3;)
30-
(instance
31-
(type (;0;) (func))
32-
(export (;0;) "a" (func (type 0)))
33-
(type (;1;) (func))
34-
(export (;1;) "b" (func (type 1)))
21+
(type (;4;)
22+
(component
23+
(type (;0;) (func))
24+
(import "foo" (func (;0;) (type 0)))
25+
(type (;1;)
26+
(instance)
27+
)
28+
(import "i1" (instance (;0;) (type 1)))
29+
(type (;2;)
30+
(instance
31+
(type (;0;) (func))
32+
(export (;0;) "a" (func (type 0)))
33+
(type (;1;) (func))
34+
(export (;1;) "b" (func (type 1)))
35+
)
3536
)
37+
(import "merged" (instance (;1;) (type 2)))
38+
(export (;1;) "bar" (func (type 0)))
39+
(type (;3;) (func))
40+
(export (;4;) "f" (type (eq 3)))
3641
)
37-
(import "merged" (instance (;1;) (type 3)))
38-
(export (;1;) "bar" (func 0))
39-
(export (;4;) "f" (type 0))
4042
)
43+
(import "unlocked-dep=<test:foo>" (component (;0;) (type 4)))
4144
(instance $foo (;3;) (instantiate 0
4245
(with "foo" (func $my-foo))
4346
(with "i1" (instance 0))
4447
(with "merged" (instance 1))
4548
)
4649
)
4750
(alias export $foo "bar" (func $e (;1;)))
48-
(component (;1;)
49-
(type (;0;) (func))
50-
(import "e" (func (;0;) (type 0)))
51-
(type (;1;)
52-
(instance)
53-
)
54-
(import "i2" (instance (;0;) (type 1)))
55-
(type (;2;)
56-
(instance
57-
(type (;0;) (func))
58-
(export (;0;) "a" (func (type 0)))
51+
(type (;5;)
52+
(component
53+
(type (;0;) (func))
54+
(import "e" (func (;0;) (type 0)))
55+
(type (;1;)
56+
(instance)
57+
)
58+
(import "i2" (instance (;0;) (type 1)))
59+
(type (;2;)
60+
(instance
61+
(type (;0;) (func))
62+
(export (;0;) "a" (func (type 0)))
63+
)
5964
)
65+
(import "merged" (instance (;1;) (type 2)))
66+
(export (;1;) "e" (func (type 0)))
6067
)
61-
(import "merged" (instance (;1;) (type 2)))
62-
(export (;1;) "e" (func 0))
6368
)
69+
(import "unlocked-dep=<test:bar>" (component (;1;) (type 5)))
6470
(instance $bar (;4;) (instantiate 1
6571
(with "e" (func $e))
6672
(with "i2" (instance 2))

0 commit comments

Comments
 (0)