<commit_before>//
//  LoggingTests.swift
//  Cleanroom Project
//
//  Created by <NAME> on 8/24/16.
//  Copyright © 2016 Gilt Groupe. All rights reserved.
//

import XCTest
import Foundation
import CleanroomASL
import CleanroomLogger

class LoggingTests: XCTestCase
{
    func testLoggingToASL()
    {
        let startTime = NSDate()

        Log.enable(debugMode: true, verboseDebugMode: true)

        Log.error?.message("Logging an error message")
        Log.warning?.message("Logging a warning message")
        Log.info?.message("Logging an info message")
        Log.debug?.message("Logging a debug message")
        Log.verbose?.message("Logging a verbose message")

        let client = ASLClient()

        let query = ASLQueryObject()
        query.setQuery(key: .facility, value: "com.gilt.CleanroomLogger", operation: .equalTo, modifiers: .none)
        query.setQuery(key: .message, value: nil, operation: .keyExists, modifiers: .none)
        query.setQuery(key: .time, value: Int(startTime.timeIntervalSince1970), operation: .greaterThanOrEqualTo, modifiers: .none)

        let signal = NSCondition()

        signal.lock()
        signal.wait(until: Date(timeIntervalSinceNow: 1))
        signal.unlock()

        var gotFinalResult = false

        var remainingToFind = Set<String>([
            "|   ERROR | LoggingTests.swift:22 - Logging an error message",
            "| WARNING | LoggingTests.swift:23 - Logging a warning message",
            "|    INFO | LoggingTests.swift:24 - Logging an info message",
            "|   DEBUG | LoggingTests.swift:25 - Logging a debug message",
            "| VERBOSE | LoggingTests.swift:26 - Logging a verbose message"])

        client.search(query) { result in

            if let result = result {
                print("")
                for key in result.attributes.keys.sorted() {
                    print("\t\(key): \(result.attributes[key] ?? "(nil)")")
                }

                let find = (result.message as NSString).substring(from: 28)

                remainingToFind.remove(find)
            }

            signal.lock()
            gotFinalResult = result == nil
            if gotFinalResult {
                signal.signal()
            }
            signal.unlock()

            return true
        }

        signal.lock()
        while !gotFinalResult {
            signal.wait()
        }
        signal.unlock()
        
        if #available(macOS 10.12, iOS 999999, tvOS 999999, *) {
            print("Now that the ASL is deprecated, system log querying is no longer possible on newer OSes; we'll just have to assume/hope that writing to the log succeeded 😬")
            return
        }
        XCTAssert(remainingToFind.isEmpty)
    }
}
<commit_msg>need new way to handle tests now that ASL is dead<commit_after>//
//  LoggingTests.swift
//  Cleanroom Project
//
//  Created by <NAME> on 8/24/16.
//  Copyright © 2016 Gilt Groupe. All rights reserved.
//

import XCTest
import Foundation
import CleanroomLogger

class LoggingTests: XCTestCase
{
    func testLogging()
    {
        Log.enable(debugMode: true, verboseDebugMode: true)

        Log.error?.message("Logging an error message")
        Log.warning?.message("Logging a warning message")
        Log.info?.message("Logging an info message")
        Log.debug?.message("Logging a debug message")
        Log.verbose?.message("Logging a verbose message")
    }
}

{'fraction_non_alphanumeric': 0.10656934306569343, 'fraction_numerical': 0.01489051094890511, 'mean_word_length': 2.181058495821727, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, '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': '5182341', 'n_tokens_mistral': 1021, 'n_tokens_neox': 943, 'n_words': 267}