Skip to content

Compiler directive else is ignored #263

Open
@kaanbiryol

Description

@kaanbiryol

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions