Skip to content

An error message is generated in certain cases when running swift test --filter. #6856

Open
@fibrechannelscsi

Description

@fibrechannelscsi

Description

The code shown below generates an error message (error: malformed) when attempting to run swift test --filter.
The argument passed to --filter does not appear to matter: invoking swift test --filter a is sufficient to reproduce the error.

Expected behavior

The unit test should complete successfully.

Actual behavior

The compilation process succeeds, but an error message saying error: malformed is generated, without the unit test actually running.

Steps to reproduce

This reproducer requires the following files; one of these is a Package.swift file. It requires one public imprort, swift-log.

The directory listing looks like this:

./Sources/main.swift
./Package.swift
./Tests/newPackage2Tests/a.swift

Note that ./Sources/main.swift can be empty, or set to its default contents after running a variation of swift package init.

Listing for Package.swift:

// swift-tools-version: 5.9
import PackageDescription
let package = Package(
    name: "newPackage",
    dependencies: [.package(url: "https://github.com/apple/swift-log.git", "1.4.0" ..< "2.0.0")],
    targets: [.testTarget(name: "newPackageTests", dependencies: [.product(name: "Logging", package: "swift-log")])])

Listing for ./Tests/newPackage2Tests/a.swift:

import Foundation; import XCTest; import Logging
let c = L(n: "")
class A
{
    public static func m() -> any X {var v = SystemRandomNumberGenerator(); let w = B.m(g: v.next())
        c.error("\(w)")
        return w
    }
}
final class Z: XCTestCase {var d = A.m(); func testV() throws {}}
public struct J: X {public init(e: UInt64) {}}
public protocol X {init(e: UInt64)}
public enum B {case m; public func callAsFunction(g: UInt64? = nil) -> any X {var a = SystemRandomNumberGenerator(); return self.y().init(e: a.next())}; public func y() -> any X.Type {return J.self}}
public func L(n: String) -> Logging.Logger {return Logging.Logger(label: n)}

Note that commenting out the line containing c.error causes the test to run successfully.

I have attached a log file (log0824.txt) that is based on the instructions recommended here:
https://forums.swift.org/t/swift-test-sometimes-fails-with-error-malformed/66866/3
We create a script containing:

echo "$@" >> /tmp/log.txt
swiftc "$@"

and then run:
SWIFT_EXEC=/path/to/script swift test
log0824.txt

Swift Package Manager version/commit hash

2961cafb053b11d

Swift & OS version (output of swift --version ; uname -a)

Swift version 5.9-dev (LLVM f8c4926c34d7084, Swift 2961cafb053b11d)
Target: aarch64-unknown-linux-gnu
Linux 81ecb818bdf0 5.15.49-linuxkit-pr #1 SMP PREEMPT Thu May 25 07:27:39 UTC 2023 aarch64 aarch64 aarch64 GNU/Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugswift testChanges impacting `swift test` tool

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions