GithubHelp home page GithubHelp logo

jrtibbetts / structup Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 18 KB

Demonstrates a Swift compiler bug where static properties from one module can't be changed in a UI testing module

Swift 100.00%

structup's Introduction

StructUp

Demonstrates a Swift compiler error (bug?) where static properties from one module can't be changed in a UI testing module.

I have a protocol in my main target that I'm calling Foo:

public protocol Foo {
    func function()
}

I want two implementations of Foo (say, one for regular use, and one for testing):

public struct RealFoo: Foo { 
    public init() { }
    
    public func function() {
        print("RealFoo.function()")
    }
}

public struct MockFoo: Foo {
    public init() { }
    
    public func function() {
        print("MockFoo.function()")
    }
}

There should be only one instance of a Foo in the lifetime of my app, but instead of creating a global variable for it, I have a FooManager with a static property for the Foo instance:

public struct FooManager {    
    public static var foo: Foo = RealFoo()   
}

So far, so good. In my main target, I set it to use the RealFoo:

FooManager.foo = RealFoo()

In the unit test target, it's the mock one:

    override func setUp() {
        FooManager.foo = MockFoo()
    }

HOWEVER, in the UI test target, all hell breaks loose:

Undefined symbols for architecture x86_64:
  "StructUp.MockFoo.init() -> StructUp.MockFoo", referenced from:
      StructUpUITests.StructUpUITests.setUp() -> () in StructUpUITests.o
  "StructUp.FooManager.foo.unsafeMutableAddressor : StructUp.Foo", referenced from:
      StructUpUITests.StructUpUITests.setUp() -> () in StructUpUITests.o
  "type metadata for StructUp.MockFoo", referenced from:
      StructUpUITests.StructUpUITests.setUp() -> () in StructUpUITests.o
  "protocol witness table for StructUp.MockFoo : StructUp.Foo in StructUp", referenced from:
      StructUpUITests.StructUpUITests.setUp() -> () in StructUpUITests.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Googling "protocol witness table for" doesn't yield much beyond updating the framework search paths. Why would this work in unit tests, but not UI tests?

I've tried a number of different things:

  • Changing RealFoo and MockFoo to classes makes no difference.
  • Changing FooManager to a class adds an additional Undefined symbol: type metadata accessor for StructUp.FooManager.
  • Taking foo out of the FooManager and making it a global variable makes no difference.

structup's People

Contributors

jrtibbetts avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.