Skip to content

Commit 141a912

Browse files
DougGregorhamishknight
authored andcommitted
Add test case for expanding a macro defined in terms of another macro
1 parent a3f70c3 commit 141a912

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

test/Macros/macro_expand_other.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Expanding macros that are defined in terms of other macros.
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -parse-as-library -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift -g -no-toolchain-stdlib-rpath
5+
6+
// Diagnostics testing
7+
// RUN: %target-typecheck-verify-swift -swift-version 5 -enable-experimental-feature FreestandingMacros -load-plugin-library %t/%target-library-name(MacroDefinition) -I %swift-host-lib-dir -module-name MacroUser -DTEST_DIAGNOSTICS
8+
9+
// Execution testing
10+
// RUN: %target-build-swift -swift-version 5 -enable-experimental-feature FreestandingMacros -load-plugin-library %t/%target-library-name(MacroDefinition) -I %swift-host-lib-dir -L %swift-host-lib-dir %s -o %t/main -module-name MacroUser
11+
// RUN: %target-run %t/main | %FileCheck %s
12+
// RUN: %target-codesign %t/main
13+
// REQUIRES: swift_swift_parser, executable_test
14+
15+
@freestanding(expression) macro stringify<T>(_ value: T) -> (T, String) = #externalMacro(module: "MacroDefinition", type: "StringifyMacro")
16+
17+
@freestanding(expression) macro stringifySeven() -> (Int, String) = #stringify(7)
18+
19+
@freestanding(expression) macro recurse(_: Bool) = #externalMacro(module: "MacroDefinition", type: "RecursiveMacro")
20+
21+
@freestanding(expression) macro recurseThrough(_ value: Bool) = #recurse(value)
22+
23+
func testFreestandingExpansionOfOther() {
24+
// CHECK: ---testFreestandingExpansionOfOther
25+
print("---testFreestandingExpansionOfOther")
26+
27+
// CHECK-NEXT: (7, "7")
28+
print(#stringifySeven)
29+
30+
#recurseThrough(false)
31+
32+
#if TEST_DIAGNOSTICS
33+
#recurseThrough(true)
34+
// expected-note@-1 2{{in expansion of macro 'recurseThrough' here}}
35+
#endif
36+
}
37+
38+
testFreestandingExpansionOfOther()

0 commit comments

Comments
 (0)