Skip to content

Commit

Permalink
Update the test generation script to allow for deprecated tests (#223)
Browse files Browse the repository at this point in the history
Motivation:

To test deprecated functionality without a bunch of warnings, tests must
be marked as deprecated. This also needs to be bubbled up to anywhere
calling that test, such as in the generated linux test manifests.

Our script to generate the manifests currently doesn't support this and
as part of #214 we'll need to deprecate a few things while keeping their
tests.

Modifications:

- Pull in the latest version of the `generate_linux_tests.rb` script
  from SwiftNIO.
- Re-run the script, since it includes some formatting changes too.

Result:

- When we deprecate functionality, we can deprecate the tests without
  the generate manifests emitting warnings.
  • Loading branch information
glbrntt committed Jul 30, 2020
1 parent cde820e commit 48082ee
Show file tree
Hide file tree
Showing 23 changed files with 70 additions and 26 deletions.
57 changes: 34 additions & 23 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,38 @@ import XCTest
@testable import NIOHPACKTests
@testable import NIOHTTP2Tests

XCTMain([
testCase(CompoundOutboundBufferTest.allTests),
testCase(ConcurrentStreamBufferTests.allTests),
testCase(ConfiguringPipelineTests.allTests),
testCase(ConnectionStateMachineTests.allTests),
testCase(ControlFrameBufferTests.allTests),
testCase(HPACKCodingTests.allTests),
testCase(HPACKIntegrationTests.allTests),
testCase(HPACKRegressionTests.allTests),
testCase(HTTP2FrameConvertibleTests.allTests),
testCase(HTTP2FrameParserTests.allTests),
testCase(HTTP2StreamMultiplexerTests.allTests),
testCase(HTTP2ToHTTP1CodecTests.allTests),
testCase(HeaderTableTests.allTests),
testCase(HuffmanCodingTests.allTests),
testCase(InboundWindowManagerTests.allTests),
testCase(IntegerCodingTests.allTests),
testCase(OutboundFlowControlBufferTests.allTests),
testCase(ReentrancyTests.allTests),
testCase(SimpleClientServerTests.allTests),
testCase(StreamChannelFlowControllerTests.allTests),
testCase(StreamIDTests.allTests),
])
// This protocol is necessary to we can call the 'run' method (on an existential of this protocol)
// without the compiler noticing that we're calling a deprecated function.
// This hack exists so we can deprecate individual tests which test deprecated functionality without
// getting a compiler warning...
protocol LinuxMainRunner { func run() }
class LinuxMainRunnerImpl: LinuxMainRunner {
@available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")
func run() {
XCTMain([
testCase(CompoundOutboundBufferTest.allTests),
testCase(ConcurrentStreamBufferTests.allTests),
testCase(ConfiguringPipelineTests.allTests),
testCase(ConnectionStateMachineTests.allTests),
testCase(ControlFrameBufferTests.allTests),
testCase(HPACKCodingTests.allTests),
testCase(HPACKIntegrationTests.allTests),
testCase(HPACKRegressionTests.allTests),
testCase(HTTP2FrameConvertibleTests.allTests),
testCase(HTTP2FrameParserTests.allTests),
testCase(HTTP2StreamMultiplexerTests.allTests),
testCase(HTTP2ToHTTP1CodecTests.allTests),
testCase(HeaderTableTests.allTests),
testCase(HuffmanCodingTests.allTests),
testCase(InboundWindowManagerTests.allTests),
testCase(IntegerCodingTests.allTests),
testCase(OutboundFlowControlBufferTests.allTests),
testCase(ReentrancyTests.allTests),
testCase(SimpleClientServerTests.allTests),
testCase(StreamChannelFlowControllerTests.allTests),
testCase(StreamIDTests.allTests),
])
}
}
(LinuxMainRunnerImpl() as LinuxMainRunner).run()
#endif
1 change: 1 addition & 0 deletions Tests/NIOHPACKTests/HPACKCodingTests+XCTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import XCTest

extension HPACKCodingTests {

@available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")
static var allTests : [(String, (HPACKCodingTests) -> () throws -> Void)] {
return [
("testRequestHeadersWithoutHuffmanCoding", testRequestHeadersWithoutHuffmanCoding),
Expand Down
1 change: 1 addition & 0 deletions Tests/NIOHPACKTests/HPACKIntegrationTests+XCTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import XCTest

extension HPACKIntegrationTests {

@available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")
static var allTests : [(String, (HPACKIntegrationTests) -> () throws -> Void)] {
return [
("testAAEncoderWithoutHuffmanCoding", testAAEncoderWithoutHuffmanCoding),
Expand Down
1 change: 1 addition & 0 deletions Tests/NIOHPACKTests/HPACKRegressionTests+XCTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import XCTest

extension HPACKRegressionTests {

@available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")
static var allTests : [(String, (HPACKRegressionTests) -> () throws -> Void)] {
return [
("testWikipediaHeaders", testWikipediaHeaders),
Expand Down
1 change: 1 addition & 0 deletions Tests/NIOHPACKTests/HeaderTableTests+XCTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import XCTest

extension HeaderTableTests {

@available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")
static var allTests : [(String, (HeaderTableTests) -> () throws -> Void)] {
return [
("testStaticHeaderTable", testStaticHeaderTable),
Expand Down
1 change: 1 addition & 0 deletions Tests/NIOHPACKTests/HuffmanCodingTests+XCTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import XCTest

extension HuffmanCodingTests {

@available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")
static var allTests : [(String, (HuffmanCodingTests) -> () throws -> Void)] {
return [
("testBasicCoding", testBasicCoding),
Expand Down
1 change: 1 addition & 0 deletions Tests/NIOHPACKTests/IntegerCodingTests+XCTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import XCTest

extension IntegerCodingTests {

@available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")
static var allTests : [(String, (IntegerCodingTests) -> () throws -> Void)] {
return [
("testIntegerEncoding", testIntegerEncoding),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import XCTest

extension CompoundOutboundBufferTest {

@available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")
static var allTests : [(String, (CompoundOutboundBufferTest) -> () throws -> Void)] {
return [
("testSimpleControlFramePassthrough", testSimpleControlFramePassthrough),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import XCTest

extension ConcurrentStreamBufferTests {

@available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")
static var allTests : [(String, (ConcurrentStreamBufferTests) -> () throws -> Void)] {
return [
("testBasicFunctionality", testBasicFunctionality),
Expand Down
1 change: 1 addition & 0 deletions Tests/NIOHTTP2Tests/ConfiguringPipelineTests+XCTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import XCTest

extension ConfiguringPipelineTests {

@available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")
static var allTests : [(String, (ConfiguringPipelineTests) -> () throws -> Void)] {
return [
("testBasicPipelineCommunicates", testBasicPipelineCommunicates),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import XCTest

extension ConnectionStateMachineTests {

@available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")
static var allTests : [(String, (ConnectionStateMachineTests) -> () throws -> Void)] {
return [
("testSimpleRequestResponseFlow", testSimpleRequestResponseFlow),
Expand Down
1 change: 1 addition & 0 deletions Tests/NIOHTTP2Tests/ControlFrameBufferTests+XCTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import XCTest

extension ControlFrameBufferTests {

@available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")
static var allTests : [(String, (ControlFrameBufferTests) -> () throws -> Void)] {
return [
("testByDefaultAllFramesPassThroughWhenChannelIsWritable", testByDefaultAllFramesPassThroughWhenChannelIsWritable),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import XCTest

extension HTTP2FrameConvertibleTests {

@available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")
static var allTests : [(String, (HTTP2FrameConvertibleTests) -> () throws -> Void)] {
return [
("testHTTP2FrameConvertible", testHTTP2FrameConvertible),
Expand Down
1 change: 1 addition & 0 deletions Tests/NIOHTTP2Tests/HTTP2FrameParserTests+XCTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import XCTest

extension HTTP2FrameParserTests {

@available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")
static var allTests : [(String, (HTTP2FrameParserTests) -> () throws -> Void)] {
return [
("testPaddingIsNotAllowedByEncoder", testPaddingIsNotAllowedByEncoder),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import XCTest

extension HTTP2StreamMultiplexerTests {

@available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")
static var allTests : [(String, (HTTP2StreamMultiplexerTests) -> () throws -> Void)] {
return [
("testMultiplexerIgnoresFramesOnStream0", testMultiplexerIgnoresFramesOnStream0),
Expand Down
1 change: 1 addition & 0 deletions Tests/NIOHTTP2Tests/HTTP2ToHTTP1CodecTests+XCTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import XCTest

extension HTTP2ToHTTP1CodecTests {

@available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")
static var allTests : [(String, (HTTP2ToHTTP1CodecTests) -> () throws -> Void)] {
return [
("testBasicRequestServerSide", testBasicRequestServerSide),
Expand Down
1 change: 1 addition & 0 deletions Tests/NIOHTTP2Tests/InboundWindowManagerTests+XCTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import XCTest

extension InboundWindowManagerTests {

@available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")
static var allTests : [(String, (InboundWindowManagerTests) -> () throws -> Void)] {
return [
("testNewWindowSizeWhenNewSizeIsAtOrAboveTarget", testNewWindowSizeWhenNewSizeIsAtOrAboveTarget),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import XCTest

extension OutboundFlowControlBufferTests {

@available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")
static var allTests : [(String, (OutboundFlowControlBufferTests) -> () throws -> Void)] {
return [
("testJustLettingDataThrough", testJustLettingDataThrough),
Expand Down
1 change: 1 addition & 0 deletions Tests/NIOHTTP2Tests/ReentrancyTests+XCTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import XCTest

extension ReentrancyTests {

@available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")
static var allTests : [(String, (ReentrancyTests) -> () throws -> Void)] {
return [
("testReEnterReadOnRead", testReEnterReadOnRead),
Expand Down
1 change: 1 addition & 0 deletions Tests/NIOHTTP2Tests/SimpleClientServerTests+XCTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import XCTest

extension SimpleClientServerTests {

@available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")
static var allTests : [(String, (SimpleClientServerTests) -> () throws -> Void)] {
return [
("testBasicRequestResponse", testBasicRequestResponse),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import XCTest

extension StreamChannelFlowControllerTests {

@available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")
static var allTests : [(String, (StreamChannelFlowControllerTests) -> () throws -> Void)] {
return [
("testChannelWritabilityChangesFromFlowControl", testChannelWritabilityChangesFromFlowControl),
Expand Down
1 change: 1 addition & 0 deletions Tests/NIOHTTP2Tests/StreamIDTests+XCTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import XCTest

extension StreamIDTests {

@available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")
static var allTests : [(String, (StreamIDTests) -> () throws -> Void)] {
return [
("testStreamIDsAreStrideable", testStreamIDsAreStrideable),
Expand Down
18 changes: 15 additions & 3 deletions scripts/generate_linux_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def createExtensionFile(fileName, classes)

for classArray in classes
file.write 'extension ' + classArray[0] + " {\n\n"
file.write ' @available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")' +"\n"
file.write ' static var allTests : [(String, (' + classArray[0] + ") -> () throws -> Void)] {\n"
file.write " return [\n"

Expand Down Expand Up @@ -99,7 +100,15 @@ def createLinuxMain(testsDirectory, allTestSubDirectories, files)
file.write ' @testable import ' + testSubDirectory + "\n"
end
file.write "\n"
file.write " XCTMain([\n"
file.write "// This protocol is necessary to we can call the 'run' method (on an existential of this protocol)\n"
file.write "// without the compiler noticing that we're calling a deprecated function.\n"
file.write "// This hack exists so we can deprecate individual tests which test deprecated functionality without\n"
file.write "// getting a compiler warning...\n"
file.write "protocol LinuxMainRunner { func run() }\n"
file.write "class LinuxMainRunnerImpl: LinuxMainRunner {\n"
file.write ' @available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")' + "\n"
file.write " func run() {\n"
file.write " XCTMain([\n"

testCases = []
for classes in files
Expand All @@ -109,9 +118,12 @@ def createLinuxMain(testsDirectory, allTestSubDirectories, files)
end

for testCase in testCases.sort { |x, y| x <=> y }
file.write ' testCase(' + testCase + ".allTests),\n"
file.write ' testCase(' + testCase + ".allTests),\n"
end
file.write " ])\n"
file.write " ])\n"
file.write " }\n"
file.write "}\n"
file.write "(LinuxMainRunnerImpl() as LinuxMainRunner).run()\n"
file.write "#endif\n"
end
end
Expand Down

0 comments on commit 48082ee

Please sign in to comment.