# Supporting relative paths: XCTest failures in Xcode

DevFeed: [Supporting relative paths: XCTest failures in Xcode](<https://devfeed.tech/articles/supporting-relative-paths-xctest-failures-in-xcode-25402.md>)

Original publisher: [Read original article](<https://smileykeith.com/2021/03/04/supporting-relative-paths/>)

Author: Keith Smiley

Published: 2021-03-05T04:48:00Z

Content type: tutorial

Language: en

Sources: [Keith Smiley](<https://devfeed.tech/sources/keith-smiley.md>)

Topics: [Xcode](<https://devfeed.tech/topics/xcode.md>), [Swift](<https://devfeed.tech/topics/swift.md>), [iOS](<https://devfeed.tech/topics/ios.md>), [debugging](<https://devfeed.tech/topics/debugging.md>)

Tags: [debugger](<https://devfeed.tech/tags/debugger.md>), [ios](<https://devfeed.tech/tags/ios.md>), [swift](<https://devfeed.tech/tags/swift.md>), [xcode](<https://devfeed.tech/tags/xcode.md>)

## AI overview

This article explains how relative source paths from the Bazel build system can cause XCTest failures in Xcode to reference relative paths, preventing the issue navigator from jumping to the failed test. It traces the behavior to Swift compiler path handling and discusses swizzling an initializer as a possible fix.

## Source excerpt

If you build your iOS app with an alternate build system such as bazel, it's likely that you use relative paths, instead of absolute paths, for compilation. Specifically, when building swift code, Xcode calls the compiler with something like: swiftc [ARGS] /path/to/srcroot/path/to/file1.swift /path/to/srcroot/path/to/file2.swift Where bazel will call the compiler with something like: swiftc [ARGS] path/to/file1.swift path/to/file2.swift Normally, this difference is inconsequential, both compilations will result in a similar enough output. So, the question is: Why would you pick one over the other? For bazel, the answer lies in its core feature of "hermeticity". In bazel's case, being hermetic means that given the same inputs you always produce the same outputs. This means that regardless of what machine you're building on, or what directory your source is cloned in, the results should be the same. Because, those details aren't considered important inputs in the build. Unfortunately, in a few places, Xcode relies on paths being absolute. Today, we'll look at how Xcode reports test failures in the UI. Specifically the underlying XCTIssue that XCTest creates is expected to be instantiated with an absolute path. This absolute path is populated from the #filePath (previously #file) keyword which is supposed to reference the absolute path of the current source file. The first question is: How does the Swift compiler know what the absolute path of the current file is? It's easy when Xcode passes an absolute path to the compiler. But, what if you pass a relative path? In this case, the Swift compiler uses the directory passed with the -working-directory argument to make the path absolute. It turns out if you don't pass this argument, the compiler has no choice but to use the relative path. This means the #filePath keyword ends up translating to a relative path, which means the XCTIssue is created with a relative path. With relative paths when you run your tests in Xcode and