0

I am new to the Kitura and Xcode and facing some issues when adding test files. It seems to be related to the @testing directive. I have setup the same as shown on Kitura website. When I invoke in the console swift build then swift test I get following error:

Compile Swift Module 'testTests' (1 sources)
Linking ./.build/debug/testPackageTests.xctest/Contents/MacOS/testPackageTests
Undefined symbols for architecture x86_64:
  "__TFC4test3OkoCfT_S0_", referenced from:
      __TFC9testTests8OkoTests8test_addfT_T_ in OkoTests.swift.o
  "__TMaC4test3Oko", referenced from:
      __TFC9testTests8OkoTests8test_addfT_T_ in OkoTests.swift.o
ld: symbol(s) not found for architecture x86_64
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: build had 1 command failures
error: exit(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/*user*/Projects/Kitura/test/.build/debug.yaml test

However when I comment out line @testable import test and type swift build then swift test then I get following error:

Compile Swift Module 'testTests' (1 sources)
/Users/*user*/Projects/Kitura/test/Tests/testTests/OkoTests.swift:6:17: error: use of unresolved identifier 'Oko'
        let o = Oko()
                ^~~
<unknown>:0: warning: 'cacheParamsComputed' is deprecated
<unknown>:0: warning: 'cacheAlphaComputed' is deprecated
<unknown>:0: warning: 'keepCacheWindow' is deprecated
<unknown>:0: error: 'memoryless' is unavailable
Metal.MTLCommandBufferError:19:14: note: 'memoryless' has been explicitly marked unavailable here
        case memoryless
             ^
<unknown>:0: error: build had 1 command failures
error: exit(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/*user*/Projects/Kitura/test/.build/debug.yaml test

When I try to test it from Xcode generated project instead (swift package generate-xcodeproj) then I get compile error:

Xcode build error

Without Testing files, everything works properly. Below I present project structure:

Xcode Project structure

Community
  • 1
  • 1
kkris1983
  • 471
  • 1
  • 7
  • 15
  • Can you share your project? A link to a GitHub repo would suffice. From the first error, my guess is that a folder is not named correctly (what is testPackageTests?) – Youming Lin Feb 07 '17 at 22:44
  • @YoumingLin: here it is [link](https://github.com/kkris1983/first.git) – kkris1983 Feb 08 '17 at 07:02

1 Answers1

3

I believe the issue is that Swift is not able to compile unit tests for modules that contain a main.swift file (i.e., modules that are meant to be compiled into executables as opposed to libraries for use in other projects). I cloned your repo and was able to compile and run unit tests after 1) removing main.swift and 2) uncommenting the testable import statement.

Youming Lin
  • 334
  • 2
  • 4
  • doesn't it seem to be odd ? I confirm that tests pass when `main.swift` is removed. Hovewer when You generate xcode project for it **swift package generate-xcodeproj** and build it in Xcode, then You get warning of missing main.swift. – kkris1983 Feb 08 '17 at 17:50
  • From my experience, Swift is **REALLY** picky about file/folder names and folder structure. I don't know what is going on with Xcode in this specific project setup, but none of the libraries I contribute to ever complained about a missing `main.swift` file. You can generate a new Swift project via `swift package init` (default type is library) or `swift package init --type executable` (for executables). Unfortunately, it may be easier to generate a new Swift project this way and then copy code over instead of to try to figure out what parts of your project setup Swift doesn't like. – Youming Lin Feb 08 '17 at 19:22
  • BTW Swift is not "picky about file/folder names and folder structure". Unfortunately currently the Swift Package Manager (SPM) it is. But to having this configurable is on the Swift 4 Package Manager roadmap. https://lists.swift.org/pipermail/swift-evolution-announce/2017-January/000307.html – Ugo Arangino Feb 23 '17 at 14:34