Compiler directive else is ignored
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 886
- Forks
- 102
- Avg merge
- 6h 36m
- Merged PRs (30d)
- 2
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing both examples with mockolo 2.1.1 using source.swift and inspect the generated Mock.swift output. Trace how top-level #else directives and directives inside protocol definitions are parsed and emitted; done means each branch is preserved with the expected conditional behavior and both examples generate the correct mock.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100