-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4796c57
commit b3b138a
Showing
2 changed files
with
72 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
// swift-tools-version:5.3 | ||
// swift-tools-version:6.0 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "LogLines", | ||
products: [ | ||
// Products define the executables and libraries a package produces, and make them visible to other packages. | ||
.library( | ||
name: "LogLines", | ||
targets: ["LogLines"]), | ||
], | ||
dependencies: [ | ||
// Dependencies declare other packages that this package depends on. | ||
// .package(url: /* package url */, from: "1.0.0"), | ||
], | ||
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: "LogLines", | ||
dependencies: []), | ||
.testTarget( | ||
name: "LogLinesTests", | ||
dependencies: ["LogLines"]), | ||
] | ||
name: "LogLines", | ||
products: [ | ||
// Products define the executables and libraries a package produces, and make them visible to other packages. | ||
.library( | ||
name: "LogLines", | ||
targets: ["LogLines"]) | ||
], | ||
dependencies: [ | ||
// Dependencies declare other packages that this package depends on. | ||
// .package(url: /* package url */, from: "1.0.0"), | ||
], | ||
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: "LogLines", | ||
dependencies: []), | ||
.testTarget( | ||
name: "LogLinesTests", | ||
dependencies: ["LogLines"]), | ||
] | ||
) |
98 changes: 50 additions & 48 deletions
98
exercises/concept/log-lines/Tests/LogLinesTests/LogLinesTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,100 @@ | ||
import XCTest | ||
import Foundation | ||
import Testing | ||
|
||
@testable import LogLines | ||
|
||
final class LogLinesTests: XCTestCase { | ||
let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false | ||
let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false | ||
|
||
@Suite struct LogLinesTests { | ||
@Test("init trace") | ||
func testInitTrace() { | ||
let line = "[TRC]: Line 84 - Console.WriteLine('Hello World');" | ||
XCTAssertEqual(LogLevel(line), LogLevel.trace) | ||
#expect(LogLevel(line) == LogLevel.trace) | ||
} | ||
|
||
func testInitDebug() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("init debug", .enabled(if: RUNALL)) | ||
func testInitDebug() { | ||
let line = "[DBG]: ; expected" | ||
XCTAssertEqual(LogLevel(line), LogLevel.debug) | ||
#expect(LogLevel(line) == LogLevel.debug) | ||
} | ||
|
||
func testInitInfo() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("init info", .enabled(if: RUNALL)) | ||
func testInitInfo() { | ||
let line = "[INF]: Timezone changed" | ||
XCTAssertEqual(LogLevel(line), LogLevel.info) | ||
#expect(LogLevel(line) == LogLevel.info) | ||
} | ||
|
||
func testInitWarning() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("init warning", .enabled(if: RUNALL)) | ||
func testInitWarning() { | ||
let line = "[WRN]: Timezone not set" | ||
XCTAssertEqual(LogLevel(line), LogLevel.warning) | ||
#expect(LogLevel(line) == LogLevel.warning) | ||
} | ||
|
||
func testInitError() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("init error", .enabled(if: RUNALL)) | ||
func testInitError() { | ||
let line = "[ERR]: Disk full" | ||
XCTAssertEqual(LogLevel(line), LogLevel.error) | ||
#expect(LogLevel(line) == LogLevel.error) | ||
} | ||
|
||
func testInitFatal() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("init fatal", .enabled(if: RUNALL)) | ||
func testInitFatal() { | ||
let line = "[FTL]: Not enough memory" | ||
XCTAssertEqual(LogLevel(line), LogLevel.fatal) | ||
#expect(LogLevel(line) == LogLevel.fatal) | ||
} | ||
|
||
func testInitUnknownEmpty() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("init unknown empty", .enabled(if: RUNALL)) | ||
func testInitUnknownEmpty() { | ||
let line = "Something terrible has happened!" | ||
XCTAssertEqual(LogLevel(line), LogLevel.unknown) | ||
#expect(LogLevel(line) == LogLevel.unknown) | ||
} | ||
|
||
func testInitUnknownNonStandard() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("init unknown non-standard", .enabled(if: RUNALL)) | ||
func testInitUnknownNonStandard() { | ||
let line = "[XYZ]: Gibberish message.. beep boop.." | ||
XCTAssertEqual(LogLevel(line), LogLevel.unknown) | ||
#expect(LogLevel(line) == LogLevel.unknown) | ||
} | ||
|
||
func testShortTrace() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("short trace", .enabled(if: RUNALL)) | ||
func testShortTrace() { | ||
let message = "Line 13 - int myNum = 42;" | ||
XCTAssertEqual(LogLevel.trace.shortFormat(message: message), "0:Line 13 - int myNum = 42;") | ||
#expect(LogLevel.trace.shortFormat(message: message) == "0:Line 13 - int myNum = 42;") | ||
} | ||
|
||
func testShortDebug() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("short debug", .enabled(if: RUNALL)) | ||
func testShortDebug() { | ||
let message = "The name 'LogLevel' does not exist in the current context" | ||
XCTAssertEqual( | ||
LogLevel.debug.shortFormat(message: message), | ||
"1:The name 'LogLevel' does not exist in the current context") | ||
#expect( | ||
LogLevel.debug.shortFormat(message: message) | ||
== "1:The name 'LogLevel' does not exist in the current context") | ||
} | ||
|
||
func testShortInfo() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("short info", .enabled(if: RUNALL)) | ||
func testShortInfo() { | ||
let message = "File moved" | ||
XCTAssertEqual(LogLevel.info.shortFormat(message: message), "4:File moved") | ||
#expect(LogLevel.info.shortFormat(message: message) == "4:File moved") | ||
} | ||
|
||
func testShortWarning() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("short warning", .enabled(if: RUNALL)) | ||
func testShortWarning() { | ||
let message = "Unsafe password" | ||
XCTAssertEqual(LogLevel.warning.shortFormat(message: message), "5:Unsafe password") | ||
#expect(LogLevel.warning.shortFormat(message: message) == "5:Unsafe password") | ||
} | ||
|
||
func testShortError() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("short error", .enabled(if: RUNALL)) | ||
func testShortError() { | ||
let message = "Stack overflow" | ||
XCTAssertEqual(LogLevel.error.shortFormat(message: message), "6:Stack overflow") | ||
#expect(LogLevel.error.shortFormat(message: message) == "6:Stack overflow") | ||
} | ||
|
||
func testShortFatal() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("short fatal", .enabled(if: RUNALL)) | ||
func testShortFatal() { | ||
let message = "Dumping all files" | ||
XCTAssertEqual(LogLevel.fatal.shortFormat(message: message), "7:Dumping all files") | ||
#expect(LogLevel.fatal.shortFormat(message: message) == "7:Dumping all files") | ||
} | ||
|
||
func testShortUnknownEmpty() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("short unknown empty", .enabled(if: RUNALL)) | ||
func testShortUnknownEmpty() { | ||
let message = "Wha happon?" | ||
XCTAssertEqual(LogLevel.unknown.shortFormat(message: message), "42:Wha happon?") | ||
#expect(LogLevel.unknown.shortFormat(message: message) == "42:Wha happon?") | ||
} | ||
} |