Uploaded image for project: 'Swift'
  1. Swift
  2. SR-307

no code coverage after class definition inside function

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Compiler
    • Labels:

      Description

      When you define a class inside a test function, then if all lines are hit, the XCTAssert calls below that class definition will not be included in the code coverage.

      See for example the function below. All lines will be executed successfully. The code coverage won't be 100% because the 2 XTAssert statements at the bottom will report 0 hits.

          func testEVObjectDescription() {
              let a = EVObjectDescription(forObject: self)
              XCTAssert(a.classPath == [bundle, "EVObjectDescriptionTests"])
              let b = EVObjectDescription(forObject: EVObjectDescriptionTests.SubTest())
              XCTAssert(b.classPath == [bundle, "EVObjectDescriptionTests", "SubTest"], "Pass")
              let c = EVObjectDescription(forObject: EVObjectDescriptionTests.SubTest.SubSubTest())
              XCTAssert(c.classPath == [bundle, "EVObjectDescriptionTests", "SubTest", "SubSubTest"], "Pass")
              
              class FuncSubTest:NSObject {
                  class FuncSubSubTest:NSObject {
                      
                  }
              }
              //Because in a bug of Xcode code coverage whe using an inline class definition, the 2 XCAsserts below will not be registered as covered
              let d = EVObjectDescription(forObject: FuncSubTest())
              XCTAssert(d.classPath == [bundle, "EVObjectDescriptionTests", "testEVObjectDescription", "FuncSubTest"], "Pass")
              let e = EVObjectDescription(forObject: FuncSubTest.FuncSubSubTest())
              XCTAssert(e.classPath == [bundle, "EVObjectDescriptionTests", "testEVObjectDescription", "FuncSubTest", "FuncSubSubTest"], "Pass")
          }
      
      

      Above code snippet is from:
      https://github.com/evermeer/EVReflection/blob/master/EVReflection/EVReflectionTests/EVObjectDescriptionTests.swift#L50

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            evermeer Edwin Vermeer
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: