From a5a3f5018e0ebe3c20b8fab3d23fd0f7efa0e3f7 Mon Sep 17 00:00:00 2001 From: Ben Leggiero Date: Wed, 29 Jul 2020 21:18:57 -0600 Subject: [PATCH] 20: Added test to guard against issue #20 --- .../GitHubIssue20Tests.swift | 37 +++++++++++++++++++ .../LazyContainersTests/XCTestManifests.swift | 1 + Tests/LinuxMain.swift | 7 +++- 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 Tests/LazyContainersTests/GitHubIssue20Tests.swift diff --git a/Tests/LazyContainersTests/GitHubIssue20Tests.swift b/Tests/LazyContainersTests/GitHubIssue20Tests.swift new file mode 100644 index 0000000..b8bbdc0 --- /dev/null +++ b/Tests/LazyContainersTests/GitHubIssue20Tests.swift @@ -0,0 +1,37 @@ +// +// GitHubIssue20Tests.swift +// LazyContainersTests +// +// Created by Ben Leggiero on 2020-07-29. +// + +import XCTest +@testable import LazyContainers + + + +var shouldNotRun = false + +class ShouldNotInit { + init() { + shouldNotRun = true + } +} + + + +/// Guards against issue #20 +/// https://github.com/RougeWare/Swift-Lazy-Patterns/issues/20 +final class GitHubIssue20Tests: XCTestCase { + + @Lazy + var lazyShouldNotRun = ShouldNotInit() + + func testLazyInitWithPropertyWrapper() { + XCTAssertFalse(shouldNotRun) + } + + static var allTests = [ + ("testLazyInitWithPropertyWrapper", testLazyInitWithPropertyWrapper) + ] +} diff --git a/Tests/LazyContainersTests/XCTestManifests.swift b/Tests/LazyContainersTests/XCTestManifests.swift index e5fcf95..b0edac9 100644 --- a/Tests/LazyContainersTests/XCTestManifests.swift +++ b/Tests/LazyContainersTests/XCTestManifests.swift @@ -4,6 +4,7 @@ import XCTest public func allTests() -> [XCTestCaseEntry] { return [ testCase(LazyContainersTests.allTests), + testCase(GitHubIssue20Tests.allTests), ] } #endif diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift index 82f8567..fa64405 100644 --- a/Tests/LinuxMain.swift +++ b/Tests/LinuxMain.swift @@ -2,6 +2,9 @@ import XCTest import LazyContainersTests -var tests = [XCTestCaseEntry]() -tests += LazyContainersTests.allTests() +let tests: [XCTestCaseEntry] = [ + LazyContainersTests.allTests, + GitHubIssue20Tests.allTests, +] + XCTMain(tests)