@@ -286,7 +286,7 @@ public final class InitPackage {
286
286
let moduleDir = sources. appending ( component: " \( pkgname) " )
287
287
try makeDirectories ( moduleDir)
288
288
289
- let sourceFileName = ( packageType == . executable ) ? " main.swift " : " \( typeName) .swift "
289
+ let sourceFileName = " \( typeName) .swift "
290
290
let sourceFile = moduleDir. appending ( RelativePath ( sourceFileName) )
291
291
292
292
let content : String
@@ -303,7 +303,14 @@ public final class InitPackage {
303
303
"""
304
304
case . executable:
305
305
content = """
306
- print( " Hello, world! " )
306
+ @main
307
+ public struct \( typeName) {
308
+ public private(set) var text = " Hello, World! "
309
+
310
+ public static func main() {
311
+ print( \( typeName) ().text)
312
+ }
313
+ }
307
314
308
315
"""
309
316
case . systemModule, . empty, . manifest, . `extension`:
@@ -377,50 +384,14 @@ public final class InitPackage {
377
384
try writePackageFile ( path) { stream in
378
385
stream <<< """
379
386
import XCTest
380
- import class Foundation.Bundle
387
+ @testable import \( moduleName )
381
388
382
389
final class \( moduleName) Tests: XCTestCase {
383
390
func testExample() throws {
384
391
// This is an example of a functional test case.
385
392
// Use XCTAssert and related functions to verify your tests produce the correct
386
393
// results.
387
-
388
- // Some of the APIs that we use below are available in macOS 10.13 and above.
389
- guard #available(macOS 10.13, *) else {
390
- return
391
- }
392
-
393
- // Mac Catalyst won't have `Process`, but it is supported for executables.
394
- #if !targetEnvironment(macCatalyst)
395
-
396
- let fooBinary = productsDirectory.appendingPathComponent( " \( pkgname) " )
397
-
398
- let process = Process()
399
- process.executableURL = fooBinary
400
-
401
- let pipe = Pipe()
402
- process.standardOutput = pipe
403
-
404
- try process.run()
405
- process.waitUntilExit()
406
-
407
- let data = pipe.fileHandleForReading.readDataToEndOfFile()
408
- let output = String(data: data, encoding: .utf8)
409
-
410
- XCTAssertEqual(output, " Hello, world! \\ n " )
411
- #endif
412
- }
413
-
414
- /// Returns path to the built products directory.
415
- var productsDirectory: URL {
416
- #if os(macOS)
417
- for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix( " .xctest " ) {
418
- return bundle.bundleURL.deletingLastPathComponent()
419
- }
420
- fatalError( " couldn't find the products directory " )
421
- #else
422
- return Bundle.main.bundleURL
423
- #endif
394
+ XCTAssertEqual( \( typeName) ().text, " Hello, World! " )
424
395
}
425
396
}
426
397
0 commit comments