Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kdawgwilk committed Sep 6, 2017
1 parent 220343a commit 8e4eaca
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 6 deletions.
55 changes: 55 additions & 0 deletions Tests/WoodyTests/TestDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// TestDelegate.swift
// Woody
//
// Created by Kaden Wilkinson on 9/5/17.
// Copyright © 2017 Vivint.SmartHome. All rights reserved.
//

import Woody


struct Log: Equatable {
let message: String
let filepath: String
let function: String
let line: Int

static func ==(lhs: Log, rhs: Log) -> Bool {
return lhs.message == rhs.message &&
lhs.filepath == rhs.filepath &&
lhs.function == rhs.function &&
lhs.line == rhs.line
}
}


class TestDelegate: WoodyDelegate {

var verboseLogs = [Log]()
var debugLogs = [Log]()
var infoLogs = [Log]()
var warningLogs = [Log]()
var errorLogs = [Log]()


func verbose(_ msg: String, filepath: String, function: String, line: Int) {
verboseLogs.append(Log(message: msg, filepath: filepath, function: function, line: line))
}

func debug(_ msg: String, filepath: String, function: String, line: Int) {
debugLogs.append(Log(message: msg, filepath: filepath, function: function, line: line))
}

func info(_ msg: String, filepath: String, function: String, line: Int) {
infoLogs.append(Log(message: msg, filepath: filepath, function: function, line: line))
}

func warning(_ msg: String, filepath: String, function: String, line: Int) {
warningLogs.append(Log(message: msg, filepath: filepath, function: function, line: line))
}

func error(_ msg: String, filepath: String, function: String, line: Int) {
errorLogs.append(Log(message: msg, filepath: filepath, function: function, line: line))
}
}
78 changes: 72 additions & 6 deletions Tests/WoodyTests/WoodyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,82 @@

import Foundation
import XCTest
import Woody
@testable import Woody

class WoodyTests: 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.
//// XCTAssertEqual(Woody().text, "Hello, World!")
var testDelegate: TestDelegate!

override func setUp() {
super.setUp()
testDelegate = TestDelegate()
Woody.delegate = testDelegate
}

override func tearDown() {
testDelegate = nil
super.tearDown()
}

func testVerboseLog() {
Woody.verbose("Verbose")

let log = Log(message: "Verbose", filepath: "\(currentDir())/WoodyTests.swift", function: "testVerboseLog()", line: 28)

XCTAssert(testDelegate.verboseLogs.count == 1)
XCTAssert(testDelegate.verboseLogs[0] == log)
}

func testDebugLog() {
Woody.debug("Debug")

let log = Log(message: "Debug", filepath: "\(currentDir())/WoodyTests.swift", function: "testDebugLog()", line: 37)

XCTAssert(testDelegate.debugLogs.count == 1)
XCTAssert(testDelegate.debugLogs[0] == log)
}

func testInfoLog() {
Woody.info("Info")

let log = Log(message: "Info", filepath: "\(currentDir())/WoodyTests.swift", function: "testInfoLog()", line: 46)

XCTAssert(testDelegate.infoLogs.count == 1)
XCTAssert(testDelegate.infoLogs[0] == log)
}

func testWarningLog() {
Woody.warning("Warning")

let log = Log(message: "Warning", filepath: "\(currentDir())/WoodyTests.swift", function: "testWarningLog()", line: 55)

XCTAssert(testDelegate.warningLogs.count == 1)
XCTAssert(testDelegate.warningLogs[0] == log)
}

func testErrorLog() {
Woody.error("Error")

let log = Log(message: "Error", filepath: "\(currentDir())/WoodyTests.swift", function: "testErrorLog()", line: 64)

XCTAssert(testDelegate.errorLogs.count == 1)
XCTAssert(testDelegate.errorLogs[0] == log)
}

static var allTests = [
("testExample", testExample),
("testVerboseLog", testVerboseLog),
("testDebugLog", testDebugLog),
("testInfoLog", testInfoLog),
("testWarningLog", testWarningLog),
("testErrorLog", testErrorLog),
]
}

private func stripFilename(from filepath: String) -> String {
var paths = filepath.components(separatedBy: "/")
paths.removeLast()
return paths.joined(separator: "/")
}

private func currentDir() -> String {
return stripFilename(from: #file)
}
8 changes: 8 additions & 0 deletions Woody.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
6E456F3E1F5A20CD00C966A2 /* Woody.h in Headers */ = {isa = PBXBuildFile; fileRef = 6E1AB8091F5A07A30050050C /* Woody.h */; settings = {ATTRIBUTES = (Public, ); }; };
6E456F3F1F5A20F900C966A2 /* Woody.h in Headers */ = {isa = PBXBuildFile; fileRef = 6E1AB8091F5A07A30050050C /* Woody.h */; settings = {ATTRIBUTES = (Public, ); }; };
6E456F401F5A210000C966A2 /* Woody.h in Headers */ = {isa = PBXBuildFile; fileRef = 6E1AB8091F5A07A30050050C /* Woody.h */; settings = {ATTRIBUTES = (Public, ); }; };
6EA99BE51F5F137500DDB66A /* TestDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EA99BE41F5F137500DDB66A /* TestDelegate.swift */; };
6EA99BE61F5F137500DDB66A /* TestDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EA99BE41F5F137500DDB66A /* TestDelegate.swift */; };
6EA99BE71F5F137500DDB66A /* TestDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EA99BE41F5F137500DDB66A /* TestDelegate.swift */; };
8933C7851EB5B820000D00A4 /* Woody.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8933C7841EB5B820000D00A4 /* Woody.swift */; };
8933C7861EB5B820000D00A4 /* Woody.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8933C7841EB5B820000D00A4 /* Woody.swift */; };
8933C7871EB5B820000D00A4 /* Woody.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8933C7841EB5B820000D00A4 /* Woody.swift */; };
Expand Down Expand Up @@ -54,6 +57,7 @@
52D6D9F01BEFFFBE002C0205 /* Woody.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Woody.framework; sourceTree = BUILT_PRODUCTS_DIR; };
52D6DA0F1BF000BD002C0205 /* Woody.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Woody.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6E1AB8091F5A07A30050050C /* Woody.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Woody.h; sourceTree = "<group>"; };
6EA99BE41F5F137500DDB66A /* TestDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestDelegate.swift; sourceTree = "<group>"; };
8933C7841EB5B820000D00A4 /* Woody.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Woody.swift; sourceTree = "<group>"; };
8933C7891EB5B82A000D00A4 /* WoodyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WoodyTests.swift; sourceTree = "<group>"; };
AD2FAA261CD0B6D800659CF4 /* Woody.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Woody.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -164,6 +168,7 @@
isa = PBXGroup;
children = (
8933C7891EB5B82A000D00A4 /* WoodyTests.swift */,
6EA99BE41F5F137500DDB66A /* TestDelegate.swift */,
);
name = Tests;
path = Tests/WoodyTests;
Expand Down Expand Up @@ -477,6 +482,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
6EA99BE51F5F137500DDB66A /* TestDelegate.swift in Sources */,
8933C7901EB5B82D000D00A4 /* WoodyTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -509,6 +515,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
6EA99BE61F5F137500DDB66A /* TestDelegate.swift in Sources */,
8933C78F1EB5B82C000D00A4 /* WoodyTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -517,6 +524,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
6EA99BE71F5F137500DDB66A /* TestDelegate.swift in Sources */,
8933C78E1EB5B82C000D00A4 /* WoodyTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down

0 comments on commit 8e4eaca

Please sign in to comment.