Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler directive else is ignored #263

Open
kaanbiryol opened this issue Sep 30, 2024 · 0 comments
Open

Compiler directive else is ignored #263

kaanbiryol opened this issue Sep 30, 2024 · 0 comments

Comments

@kaanbiryol
Copy link

I saw the issue #83 was implemented however I had some observations.

Given a source file source.swift;

#if DEBUG
import X
#elseif RELEASE
import Y
#endif

/// @mockable
protocol SwiftTest {}

mockolo -srcs source.swift -d Mock.swift && cat Mock.swift outputs;

#if DEBUG
import X
#endif
#if RELEASE
import Y
#endif

which is reflected correctly.

However;

#if DEBUG
import X
#else
import Y
#endif

/// @mockable
protocol SwiftTest {}

outputs;

import X
import Y
#if DEBUG
import X
#endif

which is incorrect. import Y should only be there for #else case.

Another observation (I don't know if this is supported or not) I had was compiler directives are not working inside the protocol definitions.

/// @mockable
protocol SwiftCompilerTest {
    #if compiler(<4.0)
    func swiftLessThan4()
    #else
    func swift()
    #endif
}

outputs;

class SwiftCompilerTestMock: SwiftCompilerTest {
    init() { }

    #if compiler(<4.0)

    private(set) var swiftLessThan4CallCount = 0
    var swiftLessThan4Handler: (() -> ())?
    func swiftLessThan4()  {
        swiftLessThan4CallCount += 1
        if let swiftLessThan4Handler = swiftLessThan4Handler {
            swiftLessThan4Handler()
        }

    }
    #endif
}

func swift() seems to be completely ignored in this case.

  • mockolo version : 2.1.1
  • swift version: swift: swiftlang-6.0.0.9.10 clang-1600.0.26.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant