Fix lint issues.

This commit is contained in:
Brent Simmons
2025-01-22 22:39:38 -08:00
parent b7f82944c7
commit ef4ae1bffe
5 changed files with 64 additions and 81 deletions

View File

@@ -9,14 +9,6 @@
import XCTest
class AppleScriptXCTestCase: XCTestCase {
override func setUp() {
super.setUp()
}
override func tearDown() {
super.tearDown()
}
/*
@function doIndividualScript
@@ -28,39 +20,39 @@ class AppleScriptXCTestCase: XCTestCase {
if the test_result is false or is missing, the test fails
@return the value of script_result, if any
*/
func doIndividualScript(filename:String) -> NSAppleEventDescriptor? {
var errorDict: NSDictionary? = nil
func doIndividualScript(filename: String) -> NSAppleEventDescriptor? {
var errorDict: NSDictionary?
let testBundle = Bundle(for: type(of: self))
let url = testBundle.url(forResource:filename, withExtension:"scpt")
let url = testBundle.url(forResource: filename, withExtension: "scpt")
guard let testScriptUrl = url else {
XCTFail("Failed Getting script URL")
return nil
}
guard let testScript = NSAppleScript(contentsOf: testScriptUrl, error: &errorDict) else {
print ("error is \(String(describing: errorDict))")
print("error is \(String(describing: errorDict))")
XCTFail("Failed initializing NSAppleScript")
return nil
}
let scriptResult = testScript.executeAndReturnError(&errorDict)
if (errorDict != nil) {
print ("error is \(String(describing: errorDict))")
if errorDict != nil {
print("error is \(String(describing: errorDict))")
XCTFail("Failed executing script")
return nil
}
let usrfDictionary = scriptResult.usrfDictionary()
guard let testResult = usrfDictionary["test_result"] else {
XCTFail("test script didn't return test result in usrf")
return nil
}
if (testResult.booleanValue != true) {
if testResult.booleanValue != true {
print("test_result was \(testResult)")
print("script_result was \(String(describing: usrfDictionary["script_result"]))")
}
XCTAssert(testResult.booleanValue == true, "test_result should be true")
return usrfDictionary["script_result"]
}

View File

@@ -17,23 +17,23 @@ import Foundation
returns an analogous Swift dictionary
*/
extension NSAppleEventDescriptor {
public func usrfDictionary() -> [String:NSAppleEventDescriptor] {
public func usrfDictionary() -> [String: NSAppleEventDescriptor] {
guard self.isRecordDescriptor else {
print ("error: usrfDictionary() expected input to be a record")
print("error: usrfDictionary() expected input to be a record")
return [:]
}
guard let usrfList = self.forKeyword("usrf".fourCharCode) else {
print ("error: usrfDictionary() couldn't find usrf")
print("error: usrfDictionary() couldn't find usrf")
return [:]
}
let listCount = usrfList.numberOfItems
guard (listCount%2 == 0) else {
print ("error: usrfDictionary() expected even number of items in usrf")
guard listCount%2 == 0 else {
print("error: usrfDictionary() expected even number of items in usrf")
return [:]
}
var usrfDictionary:[String:NSAppleEventDescriptor] = [:]
var usrfDictionary: [String: NSAppleEventDescriptor] = [:]
var processedItems = 0
while (processedItems < listCount) {
while processedItems < listCount {
processedItems = processedItems + 2
guard let nthlabel = usrfList.atIndex(processedItems-1) else {
print("usrfDictionary() couldn't get item \(processedItems+1) in usrf list")
@@ -49,6 +49,6 @@ extension NSAppleEventDescriptor {
}
usrfDictionary[nthLabelString] = nthvalue
}
return usrfDictionary;
return usrfDictionary
}
}

View File

@@ -10,15 +10,6 @@ import XCTest
class ScriptingTests: AppleScriptXCTestCase {
override func setUp() {
super.setUp()
}
override func tearDown() {
super.tearDown()
}
/*
@function testGenericScript
@brief An example of how a script can be run as part of an XCTest
@@ -31,27 +22,27 @@ class ScriptingTests: AppleScriptXCTestCase {
let scriptResult = doIndividualScript(filename: "testGenericScript")
XCTAssert( scriptResult?.stringValue == "Geoducks!")
}
func testGetUrlScript() {
_ = doIndividualScript(filename: "testGetURL")
}
func testNameAndUrlOfEveryFeedScript() {
_ = doIndividualScript(filename: "testNameAndUrlOfEveryFeed")
}
func testNameOfEveryFolderScript() {
_ = doIndividualScript(filename: "testNameOfEveryFolder")
}
func testNameOfAuthorsScript() {
_ = doIndividualScript(filename: "testNameOfAuthors")
}
func testFeedExists() {
_ = doIndividualScript(filename: "testFeedExists")
}
func testFeedOPML() {
_ = doIndividualScript(filename: "testFeedOPML")
}
@@ -64,14 +55,14 @@ class ScriptingTests: AppleScriptXCTestCase {
// _ = doIndividualScriptWithExpectation(filename: "testIterativeCreateAndDeleteFeed")
// }
func doIndividualScriptWithExpectation(filename:String) {
let queue = DispatchQueue(label:"testQueue")
func doIndividualScriptWithExpectation(filename: String) {
let queue = DispatchQueue(label: "testQueue")
let scriptExpectation = self.expectation(description: filename+"expectation")
queue.async {
_ = self.doIndividualScript(filename:filename)
_ = self.doIndividualScript(filename: filename)
scriptExpectation.fulfill()
}
self.wait(for:[scriptExpectation], timeout:60)
self.wait(for: [scriptExpectation], timeout: 60)
}
/*
@@ -90,7 +81,7 @@ class ScriptingTests: AppleScriptXCTestCase {
this test is disabled.
*/
func disabledTestCurrentArticleScripts() {
doIndividualScriptWithExpectation(filename: "uiScriptingTestSetup")
doIndividualScriptWithExpectation(filename: "establishMainWindowStartingState")
doIndividualScriptWithExpectation(filename: "selectAFeed")