Skip to content

Commit 97b09fa

Browse files
[InteropTests] Create test framework (#1817)
Motivation: We can’t use XCTest for the interoperability tests because we need to be able to run them as an executable target. However, we need to be able to write tests which assert various things. Modifications: Implemented an AssertionFailure struct and a function that checks if the result of an expression is true. From this function we can build up any other assertion functions depending on what we will need for the interop tests. Result: We will have a basic test framework for the interp tests.
1 parent 160b1f8 commit 97b09fa

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2024, gRPC Authors All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/// Failure assertion for interoperability testing.
18+
///
19+
/// This is required because the tests must be able to run without XCTest.
20+
public struct AssertionFailure: Error {
21+
public var message: String
22+
public var file: String
23+
public var line: Int
24+
}
25+
26+
/// Asserts that the value of an expression is `true`.
27+
public func assertTrue(
28+
_ expression: @autoclosure () throws -> Bool,
29+
_ message: String = "The statement is not true.",
30+
file: String = #fileID,
31+
line: Int = #line
32+
) throws {
33+
guard try expression() else {
34+
throw AssertionFailure(message: message, file: file, line: line)
35+
}
36+
}

0 commit comments

Comments
 (0)