Skip to content

SourceKitLSPTests: remove many cases of forced unwrapping #603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Tests/SourceKitLSPTests/BuildSystemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ final class BuildSystemTests: XCTestCase {
}
}

func testMainFilesChanged() {
let ws = try! mutableSourceKitTibsTestWorkspace(name: "MainFiles")!
func testMainFilesChanged() throws {
let ws = try mutableSourceKitTibsTestWorkspace(name: "MainFiles")!
let unique_h = ws.testLoc("unique").docIdentifier.uri

ws.testServer.client.allowUnexpectedNotification = false
Expand All @@ -406,7 +406,7 @@ final class BuildSystemTests: XCTestCase {
expectation.fulfill()
}

try! ws.openDocument(unique_h.fileURL!, language: .cpp)
try ws.openDocument(unique_h.fileURL!, language: .cpp)
wait(for: [expectation], timeout: defaultTimeout)

let use_d = self.expectation(description: "update settings to d.cpp")
Expand All @@ -419,7 +419,7 @@ final class BuildSystemTests: XCTestCase {
use_d.fulfill()
}

try! ws.buildAndIndex()
try ws.buildAndIndex()
wait(for: [use_d], timeout: defaultTimeout)

let use_c = self.expectation(description: "update settings to c.cpp")
Expand All @@ -432,7 +432,7 @@ final class BuildSystemTests: XCTestCase {
use_c.fulfill()
}

try! ws.edit(rebuild: true) { (changes, _) in
try ws.edit(rebuild: true) { (changes, _) in
changes.write("""
// empty
""", to: ws.testLoc("d_func").url)
Expand Down
26 changes: 13 additions & 13 deletions Tests/SourceKitLSPTests/LocalSwiftTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ final class LocalSwiftTests: XCTestCase {
XCTAssertEqual("Remove 'foo ='", CodeAction.fixitTitle(replace: "foo =", with: ""))
}

func testFixitsAreReturnedFromCodeActions() {
func testFixitsAreReturnedFromCodeActions() throws {
let url = URL(fileURLWithPath: "/\(#function)/a.swift")
let uri = DocumentURI(url)

Expand All @@ -626,7 +626,7 @@ final class LocalSwiftTests: XCTestCase {
context: CodeActionContext(diagnostics: [diagnostic], only: nil),
textDocument: TextDocumentIdentifier(uri)
)
let response = try! sk.sendSync(request)
let response = try sk.sendSync(request)

XCTAssertNotNil(response)
guard case .codeActions(let codeActions) = response else {
Expand All @@ -651,7 +651,7 @@ final class LocalSwiftTests: XCTestCase {
command: nil))
}

func testFixitsAreReturnedFromCodeActionsNotes() {
func testFixitsAreReturnedFromCodeActionsNotes() throws {
let url = URL(fileURLWithPath: "/\(#function)/a.swift")
let uri = DocumentURI(url)

Expand All @@ -676,7 +676,7 @@ final class LocalSwiftTests: XCTestCase {
context: CodeActionContext(diagnostics: [diagnostic], only: nil),
textDocument: TextDocumentIdentifier(uri)
)
let response = try! sk.sendSync(request)
let response = try sk.sendSync(request)

XCTAssertNotNil(response)
guard case .codeActions(let codeActions) = response else {
Expand Down Expand Up @@ -706,7 +706,7 @@ final class LocalSwiftTests: XCTestCase {
}
}

func testMuliEditFixitCodeActionPrimary() {
func testMuliEditFixitCodeActionPrimary() throws {
let url = URL(fileURLWithPath: "/\(#function)/a.swift")
let uri = DocumentURI(url)

Expand All @@ -730,7 +730,7 @@ final class LocalSwiftTests: XCTestCase {
context: CodeActionContext(diagnostics: [diagnostic], only: nil),
textDocument: TextDocumentIdentifier(uri)
)
let response = try! sk.sendSync(request)
let response = try sk.sendSync(request)

XCTAssertNotNil(response)
guard case .codeActions(let codeActions) = response else {
Expand All @@ -749,7 +749,7 @@ final class LocalSwiftTests: XCTestCase {
])
}

func testMuliEditFixitCodeActionNote() {
func testMuliEditFixitCodeActionNote() throws {
let url = URL(fileURLWithPath: "/\(#function)/a.swift")
let uri = DocumentURI(url)

Expand All @@ -776,7 +776,7 @@ final class LocalSwiftTests: XCTestCase {
context: CodeActionContext(diagnostics: [diagnostic], only: nil),
textDocument: TextDocumentIdentifier(uri)
)
let response = try! sk.sendSync(request)
let response = try sk.sendSync(request)

XCTAssertNotNil(response)
guard case .codeActions(let codeActions) = response else {
Expand Down Expand Up @@ -1273,7 +1273,7 @@ final class LocalSwiftTests: XCTestCase {
}
}

func testDocumentSymbolHighlight() {
func testDocumentSymbolHighlight() throws {
let url = URL(fileURLWithPath: "/\(#function)/a.swift")
let uri = DocumentURI(url)

Expand All @@ -1292,14 +1292,14 @@ final class LocalSwiftTests: XCTestCase {
""")))

do {
let resp = try! sk.sendSync(DocumentHighlightRequest(
let resp = try sk.sendSync(DocumentHighlightRequest(
textDocument: TextDocumentIdentifier(url),
position: Position(line: 0, utf16index: 0)))
XCTAssertEqual(resp?.count, 0)
}

do {
let resp = try! sk.sendSync(DocumentHighlightRequest(
let resp = try sk.sendSync(DocumentHighlightRequest(
textDocument: TextDocumentIdentifier(url),
position: Position(line: 1, utf16index: 6)))
XCTAssertEqual(resp?.count, 1)
Expand All @@ -1312,7 +1312,7 @@ final class LocalSwiftTests: XCTestCase {
}

do {
let resp = try! sk.sendSync(DocumentHighlightRequest(
let resp = try sk.sendSync(DocumentHighlightRequest(
textDocument: TextDocumentIdentifier(url),
position: Position(line: 2, utf16index: 6)))
XCTAssertEqual(resp?.count, 2)
Expand All @@ -1331,7 +1331,7 @@ final class LocalSwiftTests: XCTestCase {
}

do {
let resp = try! sk.sendSync(DocumentHighlightRequest(
let resp = try sk.sendSync(DocumentHighlightRequest(
textDocument: TextDocumentIdentifier(url),
position: Position(line: 3, utf16index: 6)))
XCTAssertEqual(resp?.count, 3)
Expand Down
8 changes: 4 additions & 4 deletions Tests/SourceKitLSPTests/MainFilesProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import XCTest

final class MainFilesProviderTests: XCTestCase {

func testMainFilesChanged() {
func testMainFilesChanged() throws {
let ws = try! mutableSourceKitTibsTestWorkspace(name: "MainFiles")!
let indexDelegate = SourceKitIndexDelegate()
ws.tibsWorkspace.delegate = indexDelegate
Expand Down Expand Up @@ -52,7 +52,7 @@ final class MainFilesProviderTests: XCTestCase {
XCTAssertEqual(ws.index.mainFilesContainingFile(shared_h), [])
XCTAssertEqual(ws.index.mainFilesContainingFile(bridging), [])

try! ws.buildAndIndex()
try ws.buildAndIndex()

XCTAssertEqual(ws.index.mainFilesContainingFile(a), [a])
XCTAssertEqual(ws.index.mainFilesContainingFile(b), [b])
Expand All @@ -64,7 +64,7 @@ final class MainFilesProviderTests: XCTestCase {

wait(for: [mainFilesDelegate.expectation], timeout: defaultTimeout)

try! ws.edit { changes, _ in
try ws.edit { changes, _ in
changes.write("""
#include "bridging.h"
void d_new(void) { bridging(); }
Expand All @@ -77,7 +77,7 @@ final class MainFilesProviderTests: XCTestCase {
}

mainFilesDelegate.expectation = expectation(description: "main files changed after edit")
try! ws.buildAndIndex()
try ws.buildAndIndex()

XCTAssertEqual(ws.index.mainFilesContainingFile(unique_h), [c])
XCTAssertEqual(ws.index.mainFilesContainingFile(shared_h), [])
Expand Down
Loading