Skip to content

Commit 469d84a

Browse files
committed
error tests
1 parent fcb838d commit 469d84a

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// REQUIRES: swift_swift_parser
2+
3+
// RUN: %empty-directory(%t)
4+
5+
// RUN: split-file %s %t
6+
7+
//#-- Prepare the Wasm macro plugin.
8+
// RUN: %swift-build-wasm-c-plugin %t/MacroDefinition.c -o %t/Plugin.wasm
9+
10+
// RUN: %target-swift-frontend \
11+
// RUN: -typecheck -verify \
12+
// RUN: -swift-version 5 \
13+
// RUN: -load-plugin %t/Plugin.wasm:%swift-plugin-server#MacroDefinition \
14+
// RUN: -module-name MyApp \
15+
// RUN: %t/test.swift
16+
17+
//--- test.swift
18+
// expected-warning @+2 {{Wasm plugin has an unknown ABI (could not find 'swift_wasm_macro_v1_pump')}}
19+
// expected-note @+1 {{declared here}}
20+
@freestanding(expression) macro constInt() -> Int = #externalMacro(module: "MacroDefinition", type: "ConstMacro")
21+
22+
func foo() {
23+
// expected-error @+1 {{Wasm plugin has an unknown ABI (could not find 'swift_wasm_macro_v1_pump')}}
24+
let _: Int = #constInt
25+
}
26+
27+
//--- MacroDefinition.c
28+
__attribute__((export_name("_start")))
29+
void _start(void) {}
30+
31+
__attribute__((export_name("swift_wasm_macro_v100_pump")))
32+
void pump(void) {}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// REQUIRES: swift_swift_parser
2+
3+
// RUN: %empty-directory(%t)
4+
5+
// RUN: split-file %s %t
6+
7+
//#-- Prepare the Wasm macro plugin.
8+
// RUN: %swift-build-wasm-c-plugin %t/MacroDefinition.c -o %t/Plugin.wasm
9+
10+
// RUN: %target-swift-frontend \
11+
// RUN: -typecheck -verify \
12+
// RUN: -swift-version 5 \
13+
// RUN: -load-plugin %t/Plugin.wasm:%swift-plugin-server#MacroDefinition \
14+
// RUN: -module-name MyApp \
15+
// RUN: %t/test.swift \
16+
// RUN: 2>%t/macro-loading.txt
17+
18+
// RUN: %FileCheck %s < %t/macro-loading.txt
19+
20+
// CHECK: guest error!
21+
22+
//--- test.swift
23+
@freestanding(expression) macro constInt() -> Int = #externalMacro(module: "MacroDefinition", type: "ConstMacro")
24+
25+
func foo() {
26+
// expected-error @+1 {{failed to communicate with external macro}}
27+
let _: Int = #constInt
28+
}
29+
30+
//--- MacroDefinition.c
31+
#include "Inputs/wasi_shim.h"
32+
33+
__attribute__((export_name("_start")))
34+
void _start(void) {}
35+
36+
__attribute__((export_name("swift_wasm_macro_v1_pump")))
37+
void pump(void) {
38+
swift_abort("guest error!\n");
39+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// REQUIRES: swift_swift_parser
2+
3+
// RUN: %empty-directory(%t)
4+
5+
// RUN: split-file %s %t
6+
7+
//#-- Prepare the Wasm macro plugin.
8+
// RUN: %swift-build-wasm-c-plugin %t/MacroDefinition.c -o %t/Plugin.wasm
9+
10+
// RUN: %target-swift-frontend \
11+
// RUN: -typecheck -verify \
12+
// RUN: -swift-version 5 \
13+
// RUN: -load-plugin %t/Plugin.wasm:%swift-plugin-server#MacroDefinition \
14+
// RUN: -module-name MyApp \
15+
// RUN: %t/test.swift
16+
17+
//--- test.swift
18+
// expected-warning @+2 {{Wasm plugin does not have a '_start' entrypoint}}
19+
// expected-note @+1 {{declared here}}
20+
@freestanding(expression) macro constInt() -> Int = #externalMacro(module: "MacroDefinition", type: "ConstMacro")
21+
22+
func foo() {
23+
// expected-error @+1 {{Wasm plugin does not have a '_start' entrypoint}}
24+
let _: Int = #constInt
25+
}
26+
27+
//--- MacroDefinition.c
28+
__attribute__((export_name("_tart")))
29+
void _start(void) {}
30+
31+
__attribute__((export_name("swift_wasm_macro_v1_pump")))
32+
void pump(void) {}

0 commit comments

Comments
 (0)