|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2025 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See http://swift.org/LICENSE.txt for license information |
| 9 | +// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +import Basics |
| 14 | +import SPMBuildCore |
| 15 | +import Testing |
| 16 | +import _InternalTestSupport |
| 17 | + |
| 18 | +@Suite |
| 19 | +struct TaskBacktraceTests { |
| 20 | + @Test( |
| 21 | + .tags(.TestSize.large, .Feature.TaskBacktraces) |
| 22 | + ) |
| 23 | + func taskBacktraces() async throws { |
| 24 | + try await fixture(name: "Miscellaneous/Simple") { fixturePath in |
| 25 | + let (stdout, _) = try await executeSwiftBuild( |
| 26 | + fixturePath, |
| 27 | + extraArgs: ["--experimental-task-backtraces", "--verbose"], |
| 28 | + buildSystem: .swiftbuild |
| 29 | + ) |
| 30 | + #expect(stdout.contains("Build complete!")) |
| 31 | + |
| 32 | + // Wait to ensure file timestamps are different on filesystems with low precision |
| 33 | + try await Task.sleep(for: .milliseconds(250)) |
| 34 | + |
| 35 | + try localFileSystem.writeFileContents( |
| 36 | + fixturePath.appending(components: "Foo.swift"), |
| 37 | + bytes: "public func bar() {}" |
| 38 | + ) |
| 39 | + |
| 40 | + let (incrementalStdout, incrementalStderr) = try await executeSwiftBuild( |
| 41 | + fixturePath, |
| 42 | + extraArgs: ["--experimental-task-backtraces", "--verbose"], |
| 43 | + buildSystem: .swiftbuild |
| 44 | + ) |
| 45 | + // Add a basic check that we produce backtrace output. The specifc formatting is tested by Swift Build. |
| 46 | + #expect(incrementalStderr.contains("Task backtrace:")) |
| 47 | + #expect(incrementalStderr.split(separator: "\n").contains(where: { |
| 48 | + $0.contains("Foo.swift' changed") |
| 49 | + })) |
| 50 | + #expect(incrementalStdout.contains("Build complete!")) |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + @Test( |
| 55 | + .tags(.TestSize.large, .Feature.TaskBacktraces) |
| 56 | + ) |
| 57 | + func taskBacktracesWarnsWithoutVerboseOutput() async throws { |
| 58 | + try await fixture(name: "Miscellaneous/Simple") { fixturePath in |
| 59 | + let (_, stderr) = try await executeSwiftBuild( |
| 60 | + fixturePath, |
| 61 | + extraArgs: ["--experimental-task-backtraces"], |
| 62 | + buildSystem: .swiftbuild, |
| 63 | + throwIfCommandFails: false |
| 64 | + ) |
| 65 | + #expect(stderr.contains("'--experimental-task-backtraces' requires '--verbose' or '--very-verbose'")) |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + @Test( |
| 70 | + .tags(.TestSize.large, .Feature.TaskBacktraces) |
| 71 | + ) |
| 72 | + func taskBacktracesWarnsWithNonSwiftBuildSystem() async throws { |
| 73 | + try await fixture(name: "Miscellaneous/Simple") { fixturePath in |
| 74 | + let (_, stderr) = try await executeSwiftBuild( |
| 75 | + fixturePath, |
| 76 | + extraArgs: ["--experimental-task-backtraces", "--verbose"], |
| 77 | + buildSystem: .native, |
| 78 | + throwIfCommandFails: false |
| 79 | + ) |
| 80 | + #expect(stderr.contains("'--experimental-task-backtraces' is only supported when using '--build-system swiftbuild'")) |
| 81 | + } |
| 82 | + } |
| 83 | +} |
0 commit comments