Skip to content

Commit a9b276c

Browse files
committed
Sema: Use -verify for Codable tests instead of FileCheck
1 parent 99051b5 commit a9b276c

File tree

2 files changed

+63
-103
lines changed

2 files changed

+63
-103
lines changed
Lines changed: 33 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,102 @@
1-
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -swift-version 4 %s 2>&1 | %FileCheck %s
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -swift-version 4 %s -verify
22

33
// Codable class with non-Codable property.
44
class C1 : Codable {
5+
// expected-error@-1 {{type 'C1' does not conform to protocol 'Decodable'}}
6+
// expected-error@-2 {{type 'C1' does not conform to protocol 'Encodable'}}
7+
58
class Nested {}
69
var a: String = ""
710
var b: Int = 0
811
var c: Nested = Nested()
9-
10-
// CHECK: error: type 'C1' does not conform to protocol 'Decodable'
11-
// CHECK: note: protocol requires initializer 'init(from:)' with type 'Decodable'
12-
// CHECK: note: cannot automatically synthesize 'Decodable' because 'C1.Nested' does not conform to 'Decodable'
13-
14-
// CHECK: error: type 'C1' does not conform to protocol 'Encodable'
15-
// CHECK: note: protocol requires function 'encode(to:)' with type 'Encodable'
16-
// CHECK: note: cannot automatically synthesize 'Encodable' because 'C1.Nested' does not conform to 'Encodable'
12+
// expected-note@-1 {{cannot automatically synthesize 'Decodable' because 'C1.Nested' does not conform to 'Decodable'}}
13+
// expected-note@-2 {{cannot automatically synthesize 'Encodable' because 'C1.Nested' does not conform to 'Encodable'}}
1714
}
1815

1916
// Codable class with non-enum CodingKeys.
2017
class C2 : Codable {
18+
// expected-error@-1 {{type 'C2' does not conform to protocol 'Decodable'}}
19+
// expected-error@-2 {{type 'C2' does not conform to protocol 'Encodable'}}
20+
2121
var a: String = ""
2222
var b: Int = 0
2323
var c: Double?
2424

2525
struct CodingKeys : CodingKey {
26+
// expected-note@-1 {{cannot automatically synthesize 'Decodable' because 'CodingKeys' is not an enum}}
27+
// expected-note@-2 {{cannot automatically synthesize 'Encodable' because 'CodingKeys' is not an enum}}
2628
var stringValue = ""
2729
var intValue = nil
30+
// expected-error@-1 {{'nil' requires a contextual type}}
2831
init?(stringValue: String) {}
2932
init?(intValue: Int) {}
3033
}
31-
32-
// CHECK: error: type 'C2' does not conform to protocol 'Decodable'
33-
// CHECK: note: protocol requires initializer 'init(from:)' with type 'Decodable'
34-
// CHECK: note: cannot automatically synthesize 'Decodable' because 'CodingKeys' is not an enum
35-
36-
// CHECK: error: type 'C2' does not conform to protocol 'Encodable'
37-
// CHECK: note: protocol requires function 'encode(to:)' with type 'Encodable'
38-
// CHECK: note: cannot automatically synthesize 'Encodable' because 'CodingKeys' is not an enum
3934
}
4035

4136
// Codable class with CodingKeys not conforming to CodingKey.
4237
class C3 : Codable {
38+
// expected-error@-1 {{type 'C3' does not conform to protocol 'Decodable'}}
39+
// expected-error@-2 {{type 'C3' does not conform to protocol 'Encodable'}}
40+
4341
var a: String = ""
4442
var b: Int = 0
4543
var c: Double?
4644

4745
enum CodingKeys : String {
46+
// expected-note@-1 {{cannot automatically synthesize 'Decodable' because 'CodingKeys' does not conform to CodingKey}}
47+
// expected-note@-2 {{cannot automatically synthesize 'Encodable' because 'CodingKeys' does not conform to CodingKey}}
4848
case a
4949
case b
5050
case c
5151
}
52-
53-
// CHECK: error: type 'C3' does not conform to protocol 'Decodable'
54-
// CHECK: note: protocol requires initializer 'init(from:)' with type 'Decodable'
55-
// CHECK: note: cannot automatically synthesize 'Decodable' because 'CodingKeys' does not conform to CodingKey
56-
57-
// CHECK: error: type 'C3' does not conform to protocol 'Encodable'
58-
// CHECK: note: protocol requires function 'encode(to:)' with type 'Encodable'
59-
// CHECK: note: cannot automatically synthesize 'Encodable' because 'CodingKeys' does not conform to CodingKey
6052
}
6153

6254
// Codable class with extraneous CodingKeys
6355
class C4 : Codable {
56+
// expected-error@-1 {{type 'C4' does not conform to protocol 'Decodable'}}
57+
// expected-error@-2 {{type 'C4' does not conform to protocol 'Encodable'}}
58+
6459
var a: String = ""
6560
var b: Int = 0
6661
var c: Double?
6762

6863
enum CodingKeys : String, CodingKey {
6964
case a
7065
case a2
66+
// expected-note@-1 2{{CodingKey case 'a2' does not match any stored properties}}
7167
case b
7268
case b2
69+
// expected-note@-1 2{{CodingKey case 'b2' does not match any stored properties}}
7370
case c
7471
case c2
72+
// expected-note@-1 2{{CodingKey case 'c2' does not match any stored properties}}
7573
}
76-
77-
// CHECK: error: type 'C4' does not conform to protocol 'Decodable'
78-
// CHECK: note: protocol requires initializer 'init(from:)' with type 'Decodable'
79-
// CHECK: note: CodingKey case 'a2' does not match any stored properties
80-
// CHECK: note: CodingKey case 'b2' does not match any stored properties
81-
// CHECK: note: CodingKey case 'c2' does not match any stored properties
82-
83-
// CHECK: error: type 'C4' does not conform to protocol 'Encodable'
84-
// CHECK: note: protocol requires function 'encode(to:)' with type 'Encodable'
85-
// CHECK: note: CodingKey case 'a2' does not match any stored properties
86-
// CHECK: note: CodingKey case 'b2' does not match any stored properties
87-
// CHECK: note: CodingKey case 'c2' does not match any stored properties
8874
}
8975

9076
// Codable class with non-decoded property (which has no default value).
9177
class C5 : Codable {
78+
// expected-error@-1 {{type 'C5' does not conform to protocol 'Decodable'}}
79+
// expected-error@-2 {{class 'C5' has no initializers}}
80+
9281
var a: String = ""
9382
var b: Int
83+
// expected-note@-1 {{cannot automatically synthesize 'Decodable' because 'b' does not have a matching CodingKey and does not have a default value}}
84+
// expected-note@-2 {{stored property 'b' without initial value prevents synthesized initializers}}
9485
var c: Double?
9586

9687
enum CodingKeys : String, CodingKey {
9788
case a
9889
case c
9990
}
100-
101-
// CHECK: error: type 'C5' does not conform to protocol 'Decodable'
102-
// CHECK: note: protocol requires initializer 'init(from:)' with type 'Decodable'
103-
// CHECK: note: cannot automatically synthesize 'Decodable' because 'b' does not have a matching CodingKey and does not have a default value
104-
105-
// CHECK: error: class 'C5' has no initializers
106-
// CHECK: note: stored property 'b' without initial value prevents synthesized initializers
10791
}
10892

10993
// Codable class with non-decoded property (which has no default value).
11094
class C6 : Codable {
95+
// expected-error@-1 {{type 'C6' does not conform to protocol 'Decodable'}}
96+
11197
var a: String = ""
11298
var b: Int
99+
// expected-note@-1 {{cannot automatically synthesize 'Decodable' because 'b' does not have a matching CodingKey and does not have a default value}}
113100
var c: Double?
114101

115102
enum CodingKeys : String, CodingKey {
@@ -120,14 +107,10 @@ class C6 : Codable {
120107
init() {
121108
b = 5
122109
}
123-
124-
// CHECK: error: type 'C6' does not conform to protocol 'Decodable'
125-
// CHECK: note: protocol requires initializer 'init(from:)' with type 'Decodable'
126-
// CHECK: note: cannot automatically synthesize 'Decodable' because 'b' does not have a matching CodingKey and does not have a default value
127110
}
128111

129112
// Classes cannot yet synthesize Encodable or Decodable in extensions.
130113
class C7 {}
131114
extension C7 : Codable {}
132-
// CHECK: error: implementation of 'Decodable' cannot be automatically synthesized in an extension
133-
// CHECK: error: implementation of 'Encodable' cannot be automatically synthesized in an extension
115+
// expected-error@-1 {{implementation of 'Decodable' cannot be automatically synthesized in an extension}}
116+
// expected-error@-2 {{implementation of 'Encodable' cannot be automatically synthesized in an extension}}
Lines changed: 30 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
1-
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -swift-version 4 %s 2>&1 | %FileCheck %s
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -swift-version 4 %s -verify
22

33
// Codable struct with non-Codable property.
44
struct S1 : Codable {
5+
// expected-error@-1 {{type 'S1' does not conform to protocol 'Decodable'}}
6+
// expected-error@-2 {{type 'S1' does not conform to protocol 'Encodable'}}
7+
58
struct Nested {}
69
var a: String = ""
710
var b: Int = 0
811
var c: Nested = Nested()
12+
// expected-note@-1 {{cannot automatically synthesize 'Decodable' because 'S1.Nested' does not conform to 'Decodable'}}
13+
// expected-note@-2 {{cannot automatically synthesize 'Encodable' because 'S1.Nested' does not conform to 'Encodable'}}
914
}
1015

1116
// Codable struct with non-enum CodingKeys.
1217
struct S2 : Codable {
18+
// expected-error@-1 {{type 'S2' does not conform to protocol 'Decodable'}}
19+
// expected-error@-2 {{type 'S2' does not conform to protocol 'Encodable'}}
20+
1321
var a: String = ""
1422
var b: Int = 0
1523
var c: Double?
1624

1725
struct CodingKeys : CodingKey {
26+
// expected-note@-1 {{cannot automatically synthesize 'Decodable' because 'CodingKeys' is not an enum}}
27+
// expected-note@-2 {{cannot automatically synthesize 'Encodable' because 'CodingKeys' is not an enum}}
1828
var stringValue: String = ""
1929
var intValue: Int? = nil
2030
init?(stringValue: String) {}
@@ -24,11 +34,16 @@ struct S2 : Codable {
2434

2535
// Codable struct with CodingKeys not conforming to CodingKey.
2636
struct S3 : Codable {
37+
// expected-error@-1 {{type 'S3' does not conform to protocol 'Decodable'}}
38+
// expected-error@-2 {{type 'S3' does not conform to protocol 'Encodable'}}
39+
2740
var a: String = ""
2841
var b: Int = 0
2942
var c: Double?
3043

3144
enum CodingKeys : String {
45+
// expected-note@-1 {{cannot automatically synthesize 'Decodable' because 'CodingKeys' does not conform to CodingKey}}
46+
// expected-note@-2 {{cannot automatically synthesize 'Encodable' because 'CodingKeys' does not conform to CodingKey}}
3247
case a
3348
case b
3449
case c
@@ -37,24 +52,36 @@ struct S3 : Codable {
3752

3853
// Codable struct with extraneous CodingKeys
3954
struct S4 : Codable {
55+
// expected-error@-1 {{type 'S4' does not conform to protocol 'Decodable'}}
56+
// expected-error@-2 {{type 'S4' does not conform to protocol 'Encodable'}}
57+
4058
var a: String = ""
4159
var b: Int = 0
4260
var c: Double?
4361

4462
enum CodingKeys : String, CodingKey {
4563
case a
4664
case a2
65+
// expected-note@-1 {{CodingKey case 'a2' does not match any stored properties}}
66+
// expected-note@-2 {{CodingKey case 'a2' does not match any stored properties}}
4767
case b
4868
case b2
69+
// expected-note@-1 {{CodingKey case 'b2' does not match any stored properties}}
70+
// expected-note@-2 {{CodingKey case 'b2' does not match any stored properties}}
4971
case c
5072
case c2
73+
// expected-note@-1 {{CodingKey case 'c2' does not match any stored properties}}
74+
// expected-note@-2 {{CodingKey case 'c2' does not match any stored properties}}
5175
}
5276
}
5377

5478
// Codable struct with non-decoded property (which has no default value).
5579
struct S5 : Codable {
80+
// expected-error@-1 {{type 'S5' does not conform to protocol 'Decodable'}}
81+
5682
var a: String = ""
5783
var b: Int
84+
// expected-note@-1 {{cannot automatically synthesize 'Decodable' because 'b' does not have a matching CodingKey and does not have a default value}}
5885
var c: Double?
5986

6087
enum CodingKeys : String, CodingKey {
@@ -66,55 +93,5 @@ struct S5 : Codable {
6693
// Structs cannot yet synthesize Encodable or Decodable in extensions.
6794
struct S6 {}
6895
extension S6 : Codable {}
69-
70-
// Decodable diagnostics are output first here {
71-
72-
// CHECK: error: type 'S1' does not conform to protocol 'Decodable'
73-
// CHECK: note: protocol requires initializer 'init(from:)' with type 'Decodable'
74-
// CHECK: note: cannot automatically synthesize 'Decodable' because 'S1.Nested' does not conform to 'Decodable'
75-
76-
// CHECK: error: type 'S2' does not conform to protocol 'Decodable'
77-
// CHECK: note: protocol requires initializer 'init(from:)' with type 'Decodable'
78-
// CHECK: note: cannot automatically synthesize 'Decodable' because 'CodingKeys' is not an enum
79-
80-
// CHECK: error: type 'S3' does not conform to protocol 'Decodable'
81-
// CHECK: note: protocol requires initializer 'init(from:)' with type 'Decodable'
82-
// CHECK: note: cannot automatically synthesize 'Decodable' because 'CodingKeys' does not conform to CodingKey
83-
84-
// CHECK: error: type 'S4' does not conform to protocol 'Decodable'
85-
// CHECK: note: protocol requires initializer 'init(from:)' with type 'Decodable'
86-
// CHECK: note: CodingKey case 'a2' does not match any stored properties
87-
// CHECK: note: CodingKey case 'b2' does not match any stored properties
88-
// CHECK: note: CodingKey case 'c2' does not match any stored properties
89-
90-
// CHECK: error: type 'S5' does not conform to protocol 'Decodable'
91-
// CHECK: note: protocol requires initializer 'init(from:)' with type 'Decodable'
92-
// CHECK: note: cannot automatically synthesize 'Decodable' because 'b' does not have a matching CodingKey and does not have a default value
93-
94-
// CHECK: error: implementation of 'Decodable' cannot be automatically synthesized in an extension
95-
96-
// }
97-
98-
// Encodable {
99-
100-
// CHECK: error: type 'S1' does not conform to protocol 'Encodable'
101-
// CHECK: note: protocol requires function 'encode(to:)' with type 'Encodable'
102-
// CHECK: note: cannot automatically synthesize 'Encodable' because 'S1.Nested' does not conform to 'Encodable'
103-
104-
// CHECK: error: type 'S2' does not conform to protocol 'Encodable'
105-
// CHECK: note: protocol requires function 'encode(to:)' with type 'Encodable'
106-
// CHECK: note: cannot automatically synthesize 'Encodable' because 'CodingKeys' is not an enum
107-
108-
// CHECK: error: type 'S3' does not conform to protocol 'Encodable'
109-
// CHECK: note: protocol requires function 'encode(to:)' with type 'Encodable'
110-
// CHECK: note: cannot automatically synthesize 'Encodable' because 'CodingKeys' does not conform to CodingKey
111-
112-
// CHECK: error: type 'S4' does not conform to protocol 'Encodable'
113-
// CHECK: note: protocol requires function 'encode(to:)' with type 'Encodable'
114-
// CHECK: note: CodingKey case 'a2' does not match any stored properties
115-
// CHECK: note: CodingKey case 'b2' does not match any stored properties
116-
// CHECK: note: CodingKey case 'c2' does not match any stored properties
117-
118-
// CHECK: error: implementation of 'Encodable' cannot be automatically synthesized in an extension
119-
120-
// }
96+
// expected-error@-1 {{implementation of 'Decodable' cannot be automatically synthesized in an extension}}
97+
// expected-error@-2 {{implementation of 'Encodable' cannot be automatically synthesized in an extension}}

0 commit comments

Comments
 (0)