<commit_before>//
//  XCGLoggerTests.swift
//  XCGLogger: https://github.com/DaveWoodCom/XCGLogger
//
//  Created by <NAME> on 2014-06-09.
//  Copyright © 2014 <NAME>, <NAME>.
//  Some rights reserved: https://github.com/DaveWoodCom/XCGLogger/blob/master/LICENSE.txt
//

import XCTest
@testable import XCGLogger

/// Tests
class XCGLoggerTests: XCTestCase {
    /// This file's filename for use in testing expected log messages
    let filename = { return (#file as NSString).lastPathComponent }()

    /// Calculate a base identifier to use for the giving function name.
    ///
    /// - Parameters:
    ///     - functionName: Normally omitted **Default:** *#function*.
    ///
    /// - Returns:  A string to use as the base identifier for objects in the test
    ///
    func functionIdentifier(_ functionName: StaticString = #function) -> String {
        return "\(XCGLogger.Constants.baseIdentifier).\(functionName)"
    }

    /// Set up prior to each test
    override func setUp() {
        super.setUp()
        // Put setup code here. This method is called before the invocation of each test method in the class.
    }

    /// Tear down after each test
    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }

    //    func testExample() {
    //        // This is an example of a functional test case.
    //        XCTAssert(true, "Pass")
    //    }
    //
    //    func testPerformanceExample() {
    //        // This is an example of a performance test case.
    //        self.measureBlock() {
    //            // Put the code you want to measure the time of here.
    //        }
    //    }

    /// Test that if we request the default instance multiple times, we always get the same instance
    func test_00010_DefaultInstance() {
        let defaultInstance1: XCGLogger = XCGLogger.default
        let defaultInstance2: XCGLogger = XCGLogger.default

        XCTAssert(defaultInstance1 === defaultInstance2, "Fail: default is not returning a common instance")
    }

    /// Test that if we request the multiple instances, we get different instances
    func test_00020_DistinctInstances() {
        let instance1: XCGLogger = XCGLogger()
        instance1.identifier = "instance1"

        let instance2: XCGLogger = XCGLogger()
        instance2.identifier = "instance2" // this should not affect instance1

        XCTAssert(instance1.identifier != instance2.identifier, "Fail: same instance is being returned")
    }

    /// Test our default instance starts with the correct default destinations
    func test_00022_DefaultInstanceDestinations() {
        let defaultInstance: XCGLogger = XCGLogger.default

        let consoleDestination: ConsoleDestination? = defaultInstance.destination(withIdentifier: XCGLogger.Constants.baseConsoleDestinationIdentifier) as? ConsoleDestination

        XCTAssert(consoleDestination != nil, "Fail: default console destination not attached to our default instance")
        XCTAssert(defaultInstance.destinations.count == 1, "Fail: Incorrect number of destinations on our default instance")
    }

    /// Test that we can add additonal destinations
    func test_00030_addDestination() {
        let log = XCGLogger(identifier: functionIdentifier())
        let destinationCountAtStart = log.destinations.count

        let additionalConsoleLogger = ConsoleDestination(identifier: log.identifier + ".second.console")

        let additionSuccess = log.add(destination: additionalConsoleLogger)
        let destinationCountAfterAddition = log.destinations.count

        XCTAssert(additionSuccess, "Failed to add additional destination")
        XCTAssert(destinationCountAtStart == (destinationCountAfterAddition - 1), "Failed to add additional destination")
    }

    /// Test we can remove existing destinations
    func test_00040_RemoveDestination() {
        let log: XCGLogger = XCGLogger(identifier: functionIdentifier())
        log.outputLevel = .debug

        let destinationCountAtStart = log.destinations.count

        let removeSuccess = log.remove(destinationWithIdentifier: XCGLogger.Constants.baseConsoleDestinationIdentifier)
        let destinationCountAfterRemoval = log.destinations.count

        XCTAssert(destinationCountAtStart == (destinationCountAfterRemoval + 1), "Failed to remove destination")
        XCTAssert(removeSuccess, "Fail: didn't remove destination")
    }

    /// Test that we can not add a destination with a duplicate identifier
    func test_00050_DenyAdditionOfDestinationWithDuplicateIdentifier() {
        let log: XCGLogger = XCGLogger(identifier: functionIdentifier())
        log.outputLevel = .debug

        let testIdentifier = log.identifier + ".testIdentifier"
        let additionalConsoleLogger = ConsoleDestination(identifier: testIdentifier)
        let additionalConsoleLogger2 = ConsoleDestination(identifier: testIdentifier)

        let additionSuccess = log.add(destination: additionalConsoleLogger)
        let destinationCountAfterAddition = log.destinations.count

        let additionSuccess2 = log.add(destination: additionalConsoleLogger2)
        let destinationCountAfterAddition2 = log.destinations.count

        XCTAssert(additionSuccess, "Failed to add additional destination")
        XCTAssert(!additionSuccess2, "Failed to prevent adding additional destination with a duplicate identifier")
        XCTAssert(destinationCountAfterAddition == destinationCountAfterAddition2, "Failed to prevent adding additional destination with a duplicate identifier")
    }

    /// Test a destination has it's owner set correctly when added to or removed from a logger
    func test_00052_CheckDestinationOwner() {
        let log1: XCGLogger = XCGLogger(identifier: functionIdentifier() + ".1")
        XCTAssert(log1.destinations.count == 1, "Fail: Logger didn't include the correct default destinations")

        let log2: XCGLogger = XCGLogger(identifier: functionIdentifier() + ".2", includeDefaultDestinations: false)<commit_msg>Reworded some test failure messages<commit_after>//
//  XCGLoggerTests.swift
//  XCGLogger: https://github.com/DaveWoodCom/XCGLogger
//
//  Created by <NAME> on 2014-06-09.
//  Copyright © 2014 <NAME>, <NAME>.
//  Some rights reserved: https://github.com/DaveWoodCom/XCGLogger/blob/master/LICENSE.txt
//

import XCTest
@testable import XCGLogger

/// Tests
class XCGLoggerTests: XCTestCase {
    /// This file's filename for use in testing expected log messages
    let filename = { return (#file as NSString).lastPathComponent }()

    /// Calculate a base identifier to use for the giving function name.
    ///
    /// - Parameters:
    ///     - functionName: Normally omitted **Default:** *#function*.
    ///
    /// - Returns:  A string to use as the base identifier for objects in the test
    ///
    func functionIdentifier(_ functionName: StaticString = #function) -> String {
        return "\(XCGLogger.Constants.baseIdentifier).\(functionName)"
    }

    /// Set up prior to each test
    override func setUp() {
        super.setUp()
        // Put setup code here. This method is called before the invocation of each test method in the class.
    }

    /// Tear down after each test
    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }

    //    func testExample() {
    //        // This is an example of a functional test case.
    //        XCTAssert(true, "Pass")
    //    }
    //
    //    func testPerformanceExample() {
    //        // This is an example of a performance test case.
    //        self.measureBlock() {
    //            // Put the code you want to measure the time of here.
    //        }
    //    }

    /// Test that if we request the default instance multiple times, we always get the same instance
    func test_00010_DefaultInstance() {
        let defaultInstance1: XCGLogger = XCGLogger.default
        let defaultInstance2: XCGLogger = XCGLogger.default

        XCTAssert(defaultInstance1 === defaultInstance2, "Fail: default is not returning a common instance")
    }

    /// Test that if we request the multiple instances, we get different instances
    func test_00020_DistinctInstances() {
        let instance1: XCGLogger = XCGLogger()
        instance1.identifier = "instance1"

        let instance2: XCGLogger = XCGLogger()
        instance2.identifier = "instance2" // this should not affect instance1

        XCTAssert(instance1.identifier != instance2.identifier, "Fail: same instance is being returned")
    }

    /// Test our default instance starts with the correct default destinations
    func test_00022_DefaultInstanceDestinations() {
        let defaultInstance: XCGLogger = XCGLogger.default

        let consoleDestination: ConsoleDestination? = defaultInstance.destination(withIdentifier: XCGLogger.Constants.baseConsoleDestinationIdentifier) as? ConsoleDestination

        XCTAssert(consoleDestination != nil, "Fail: default console destination not attached to our default instance")
        XCTAssert(defaultInstance.destinations.count == 1, "Fail: Incorrect number of destinations on our default instance")
    }

    /// Test that we can add additonal destinations
    func test_00030_addDestination() {
        let log = XCGLogger(identifier: functionIdentifier())
        let destinationCountAtStart = log.destinations.count

        let additionalConsoleLogger = ConsoleDestination(identifier: log.identifier + ".second.console")

        let additionSuccess = log.add(destination: additionalConsoleLogger)
        let destinationCountAfterAddition = log.destinations.count

        XCTAssert(additionSuccess, "Fail: didn't add additional destination")
        XCTAssert(destinationCountAtStart == (destinationCountAfterAddition - 1), "Fail: didn't add additional destination")
    }

    /// Test we can remove existing destinations
    func test_00040_RemoveDestination() {
        let log: XCGLogger = XCGLogger(identifier: functionIdentifier())
        log.outputLevel = .debug

        let destinationCountAtStart = log.destinations.count

        let removeSuccess = log.remove(destinationWithIdentifier: XCGLogger.Constants.baseConsoleDestinationIdentifier)
        let destinationCountAfterRemoval = log.destinations.count

        XCTAssert(removeSuccess, "Fail: didn't remove destination")
        XCTAssert(destinationCountAtStart == (destinationCountAfterRemoval + 1), "Fail: didn't remove destination")
    }

    /// Test that we can not add a destination with a duplicate identifier
    func test_00050_DenyAdditionOfDestinationWithDuplicateIdentifier() {
        let log: XCGLogger = XCGLogger(identifier: functionIdentifier())
        log.outputLevel = .debug

        let testIdentifier = log.identifier + ".testIdentifier"
        let additionalConsoleLogger = ConsoleDestination(identifier: testIdentifier)
        let additionalConsoleLogger2 = ConsoleDestination(identifier: testIdentifier)

        let additionSuccess = log.add(destination: additionalConsoleLogger)
        let destinationCountAfterAddition = log.destinations.count

        let additionSuccess2 = log.add(destination: additionalConsoleLogger2)
        let destinationCountAfterAddition2 = log.destinations.count

        XCTAssert(additionSuccess, "Fail: didn't add additional destination")
        XCTAssert(!additionSuccess2, "Fail: didn't prevent adding additional destination with a duplicate identifier")
        XCTAssert(destinationCountAfterAddition == destinationCountAfterAddition2, "Fail: didn't prevent adding additional destination with a duplicate identifier")
    }

    /// Test a destination has it's owner set correctly when added to or removed from a logger
    func test_00052_CheckDestinationOwner() {
        let log1: XCGLogger = XCGLogger(identifier: functionIdentifier() + ".1")
        XCTAssert(log1.destinations.count == 1, "Fail: Logger didn't include the correct default destinations")

        let log2: XCGLogger = XCGLogger(identifier: functionIdentifier() + ".2", includeDefaultDestinations: false)
{'fraction_non_alphanumeric': 0.08323793949304988, 'fraction_numerical': 0.012264922322158627, 'mean_word_length': 3.195883361921098, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4812708', 'n_tokens_mistral': 3140, 'n_tokens_neox': 3079, 'n_words': 985}