Skip to content

Commit bbcba6a

Browse files
committed
[DiagnosticVerifier] add test with diagnostics in unparsed clang attr
1 parent 827c30f commit bbcba6a

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
// RUN: not %target-swift-frontend -typecheck -verify %t/test.swift -I %t -plugin-path %swift-plugin-dir -Rmacro-expansions 2>&1 | \
5+
// RUN: %FileCheck %s --implicit-check-not error: --implicit-check-not note: --implicit-check-not warning: --implicit-check-not remark: --match-full-lines --sanitize TEST_H=%t%{fs-sep}test.h
6+
7+
//--- test.h
8+
void foo(int len, int *p) __attribute__((
9+
swift_attr("@_SwiftifyImport(.countedBy(pointer: .param(2), count: \"len\"))")));
10+
11+
//--- test.swift
12+
import TestClang
13+
14+
func bar(x: UnsafeMutableBufferPointer<CInt>) {
15+
foo(x) // trigger macro expansion
16+
}
17+
18+
//--- module.modulemap
19+
module TestClang {
20+
header "test.h"
21+
export *
22+
}
23+
24+
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:1:1: error: unexpected remark produced: macro content: |/// This is an auto-generated wrapper for safer interop|
25+
// CHECK: TEST_H:1:25: note: in expansion from here
26+
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:1:1: note: file '@__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' is not parsed for 'expected' statements. Use '-verify-additional-file @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
27+
// CHECK: TEST_H:1:25: note: in expansion from here
28+
// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here
29+
// CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len"))
30+
// CHECK: note: file '' is not parsed for 'expected' statements. Use '-verify-additional-file ' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
31+
32+
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:2:1: error: unexpected remark produced: macro content: |@_alwaysEmitIntoClient @_disfavoredOverload public func foo(_ p: UnsafeMutableBufferPointer<Int32>) {|
33+
// CHECK: TEST_H:1:25: note: in expansion from here
34+
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:2:1: note: file '@__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' is not parsed for 'expected' statements. Use '-verify-additional-file @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
35+
// CHECK: TEST_H:1:25: note: in expansion from here
36+
// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here
37+
// CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len"))
38+
// CHECK: note: file '' is not parsed for 'expected' statements. Use '-verify-additional-file ' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
39+
40+
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:3:1: error: unexpected remark produced: macro content: | let len = Int32(exactly: p.count)!|
41+
// CHECK: TEST_H:1:25: note: in expansion from here
42+
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:3:1: note: file '@__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' is not parsed for 'expected' statements. Use '-verify-additional-file @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
43+
// CHECK: TEST_H:1:25: note: in expansion from here
44+
// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here
45+
// CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len"))
46+
// CHECK: note: file '' is not parsed for 'expected' statements. Use '-verify-additional-file ' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
47+
48+
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:4:1: error: unexpected remark produced: macro content: | return unsafe foo(len, p.baseAddress!)|
49+
// CHECK: TEST_H:1:25: note: in expansion from here
50+
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:4:1: note: file '@__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' is not parsed for 'expected' statements. Use '-verify-additional-file @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
51+
// CHECK: TEST_H:1:25: note: in expansion from here
52+
// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here
53+
// CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len"))
54+
// CHECK: note: file '' is not parsed for 'expected' statements. Use '-verify-additional-file ' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
55+
56+
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:5:1: error: unexpected remark produced: macro content: |}|
57+
// CHECK: TEST_H:1:25: note: in expansion from here
58+
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:5:1: note: file '@__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' is not parsed for 'expected' statements. Use '-verify-additional-file @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
59+
// CHECK: TEST_H:1:25: note: in expansion from here
60+
// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here
61+
// CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len"))
62+
// CHECK: note: file '' is not parsed for 'expected' statements. Use '-verify-additional-file ' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
63+
64+
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:1:1: remark: diagnostic produced elsewhere: macro content: |/// This is an auto-generated wrapper for safer interop|
65+
// CHECK: TEST_H:1:25: note: in expansion from here
66+
// CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here
67+
68+
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:2:1: remark: diagnostic produced elsewhere: macro content: |@_alwaysEmitIntoClient @_disfavoredOverload public func foo(_ p: UnsafeMutableBufferPointer<Int32>) {|
69+
// CHECK: TEST_H:1:25: note: in expansion from here
70+
// CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here
71+
72+
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:3:1: remark: diagnostic produced elsewhere: macro content: | let len = Int32(exactly: p.count)!|
73+
// CHECK: TEST_H:1:25: note: in expansion from here
74+
// CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here
75+
76+
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:4:1: remark: diagnostic produced elsewhere: macro content: | return unsafe foo(len, p.baseAddress!)|
77+
// CHECK: TEST_H:1:25: note: in expansion from here
78+
// CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here
79+
80+
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:5:1: remark: diagnostic produced elsewhere: macro content: |}|
81+
// CHECK: TEST_H:1:25: note: in expansion from here
82+
// CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here

0 commit comments

Comments
 (0)