Skip to content
This repository was archived by the owner on Oct 28, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ let package = Package(
dependencies: ["CBacktrace"]),
.target(name: "CBacktrace",
dependencies: []),
.target(name: "Sample",
dependencies: ["Backtrace"]),
.testTarget(name: "BacktraceTests",
dependencies: ["Backtrace"]),
]
Expand Down
19 changes: 19 additions & 0 deletions Sources/Sample/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftLinuxBacktrace open source project
//
// Copyright (c) 2019-2020 Apple Inc. and the SwiftLinuxBacktrace project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftLinuxBacktrace project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import Backtrace

let reason = CommandLine.arguments.count == 2 ? CommandLine.arguments[1] : "unknown"
Backtrace.install()
fatalError(reason)
4 changes: 2 additions & 2 deletions Tests/BacktraceTests/BacktraceTests+XCTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import XCTest
///

extension BacktraceTests {
static var allTests: [(String, (BacktraceTests) -> () throws -> Void)] {
public static var allTests: [(String, (BacktraceTests) -> () throws -> Void)] {
return [
("testExample", testExample),
("testBacktrace", testBacktrace),
]
}
}
25 changes: 18 additions & 7 deletions Tests/BacktraceTests/BacktraceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,25 @@
//
//===----------------------------------------------------------------------===//

@testable import Backtrace
import XCTest

final class BacktraceTests: XCTestCase {
func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct
// results.
XCTAssert(true)
public final class BacktraceTests: XCTestCase {
func testBacktrace() {
#if os(Linux)
let expectedError = UUID().uuidString
let pipe = Pipe()
let process = Process()
process.executableURL = URL(fileURLWithPath: "/usr/bin/swift")
process.arguments = ["run", "Sample", expectedError]
process.standardError = pipe
XCTAssertNoThrow(try process.run())
if process.isRunning {
process.waitUntilExit()
}
let stderr = String(data: pipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8) ?? ""
print(stderr)
XCTAssert(stderr.contains("Current stack trace:"), "expected stanard error to include backtrace")
XCTAssert(stderr.contains("Fatal error: \(expectedError)"), "expected stanard error to include error information")
#endif
}
}
2 changes: 1 addition & 1 deletion Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import XCTest
///

#if os(Linux) || os(FreeBSD)
@testable import BacktraceTests
import BacktraceTests

XCTMain([
testCase(BacktraceTests.allTests),
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ services:

test:
<<: *common
command: /bin/bash -cl "swift test -Xswiftc -warnings-as-errors $${SANITIZER_ARG-}"
command: /bin/bash -cl "swift test -c release -Xswiftc -g -Xswiftc -warnings-as-errors $${SANITIZER_ARG-}"

# util

Expand Down
4 changes: 2 additions & 2 deletions scripts/generate_linux_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def createExtensionFile(fileName, classes)

for classArray in classes
file.write 'extension ' + classArray[0] + " {\n"
file.write ' static var allTests: [(String, (' + classArray[0] + ") -> () throws -> Void)] {\n"
file.write ' public static var allTests: [(String, (' + classArray[0] + ") -> () throws -> Void)] {\n"
file.write " return [\n"

for funcName in classArray[1]
Expand All @@ -96,7 +96,7 @@ def createLinuxMain(testsDirectory, allTestSubDirectories, files)

file.write "#if os(Linux) || os(FreeBSD)\n"
for testSubDirectory in allTestSubDirectories.sort { |x, y| x <=> y }
file.write '@testable import ' + testSubDirectory + "\n"
file.write 'import ' + testSubDirectory + "\n"
end
file.write "\n"
file.write "XCTMain([\n"
Expand Down