Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to test an executable target on Windows #6083

Open
svanimpe opened this issue Sep 23, 2022 · 6 comments
Open

Unable to test an executable target on Windows #6083

svanimpe opened this issue Sep 23, 2022 · 6 comments
Labels
bug swift build Changes impacting `swift build` swift test Changes impacting `swift test` tool windows

Comments

@svanimpe
Copy link

Steps To Reproduce

In an empty directory named hello:

swift package init --type executable
swift build --build-tests

This outputs:

Building for debugging...
error: emit-module command failed with exit code 1 (use -v to see invocationC:\Users\steve\Developer\hello\Tests\helloTests\helloTests.swift:2:18: error: no such module 'hello'
@testable import hello
                 ^
C:\Users\steve\Developer\hello\Tests\helloTests\helloTests.swift:2:18: error: no such module 'hello'
@testable import hello
                 ^
note: module 'hello' is the main module of an executable, and cannot be imported by tests and other targets
note: module 'hello' is the main module of an executable, and cannot be imported by tests and other targets

This is with Swift 5.7 on Windows 11.

This does work on macOS.

@svanimpe svanimpe added the bug label Sep 23, 2022
@compnerd compnerd transferred this issue from swiftlang/swift Jan 30, 2023
@Baneeishaque
Copy link

same issue.

@agrozyme
Copy link

I use this way to setting Package.swift

// swift-tools-version: 5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
  name: "test-swift",
  products: [
      // Products define the executables and libraries a package produces, and make them visible to other packages.
    .library(name: "library-test-swift", targets: ["library-test-swift"]),
  ],
  dependencies: [
    // Dependencies declare other packages that this package depends on.
    // .package(url: /* package url */, from: "1.0.0"),
    .package(url: "https://github.com/apple/swift-crypto.git", from: "2.2.4")
  ],
  targets: [
    // Targets are the basic building blocks of a package. A target can define a module or a test suite.
    // Targets can depend on other targets in this package, and on products in packages this package depends on.
    .target(name: "library-test-swift", dependencies: [.product(name: "Crypto", package: "swift-crypto")]),

    .executableTarget(name: "test-swift", dependencies: ["library-test-swift"]),

    .testTarget(name: "test-swiftTests", dependencies: [
      "library-test-swift",
      // "test-swift"
    ]),
  ]
)

@Baneeishaque
Copy link

Baneeishaque commented Feb 19, 2023

I use this way to setting Package.swift

// swift-tools-version: 5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
  name: "test-swift",
  products: [
      // Products define the executables and libraries a package produces, and make them visible to other packages.
    .library(name: "library-test-swift", targets: ["library-test-swift"]),
  ],
  dependencies: [
    // Dependencies declare other packages that this package depends on.
    // .package(url: /* package url */, from: "1.0.0"),
    .package(url: "https://github.com/apple/swift-crypto.git", from: "2.2.4")
  ],
  targets: [
    // Targets are the basic building blocks of a package. A target can define a module or a test suite.
    // Targets can depend on other targets in this package, and on products in packages this package depends on.
    .target(name: "library-test-swift", dependencies: [.product(name: "Crypto", package: "swift-crypto")]),

    .executableTarget(name: "test-swift", dependencies: ["library-test-swift"]),

    .testTarget(name: "test-swiftTests", dependencies: [
      "library-test-swift",
      // "test-swift"
    ]),
  ]
)

is there any working example repository? @agrozyme

@agrozyme
Copy link

is there any working example repository? @agrozyme

I don't have Mac device, and I only use Windows 10 for work.
You can put all logic function in "library" and write some nomal test case for test "library".
in "executableTarget" only put simple flow logic, use this way we can do unit testing, but can't do integration testing.

I have some screen shot but I don't know how to put them in this replay.

@Baneeishaque
Copy link

is there any working example repository? @agrozyme

I don't have Mac device, and I only use Windows 10 for work.

Same here...

I have some screen shot but I don't know how to put them in this replay.

Just drag & drop the files to the writing area, it will automatically upload & attached to the comment.

@agrozyme
Copy link

agrozyme commented Mar 1, 2023

2023-03-01 19 33 18

@grynspan grynspan added swift test Changes impacting `swift test` tool swift build Changes impacting `swift build` labels Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug swift build Changes impacting `swift build` swift test Changes impacting `swift test` tool windows
Projects
None yet
Development

No branches or pull requests

5 participants