mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-24 16:40:21 +00:00
Tests: Convert Swift tests to use Testing module where possible
The AK tests can't seem to use it because it crashes the frontend :)
This commit is contained in:
parent
188b3bb9b8
commit
782926601d
Notes:
github-actions[bot]
2024-08-29 03:28:30 +00:00
Author: https://github.com/ADKaster Commit: https://github.com/LadybirdBrowser/ladybird/commit/782926601dc Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1202
5 changed files with 44 additions and 70 deletions
|
@ -93,6 +93,8 @@ endforeach()
|
|||
target_link_libraries(TestString PRIVATE LibUnicode)
|
||||
|
||||
if (ENABLE_SWIFT)
|
||||
|
||||
# FIXME: Convert to use swift-testing after resolving https://github.com/LadybirdBrowser/ladybird/issues/1201
|
||||
add_executable(TestAKBindings TestAKBindings.swift)
|
||||
target_link_libraries(TestAKBindings PRIVATE AK)
|
||||
target_compile_options(TestAKBindings PRIVATE -parse-as-library)
|
||||
|
|
|
@ -16,13 +16,17 @@ endforeach()
|
|||
target_link_libraries(TestFetchURL PRIVATE LibURL)
|
||||
|
||||
if (ENABLE_SWIFT)
|
||||
add_executable(TestLibWebSwiftBindings TestLibWebSwiftBindings.swift)
|
||||
target_link_libraries(TestLibWebSwiftBindings PRIVATE AK LibWeb)
|
||||
target_compile_options(TestLibWebSwiftBindings PRIVATE -parse-as-library)
|
||||
add_test(NAME TestLibWebSwiftBindings COMMAND TestLibWebSwiftBindings)
|
||||
find_package(SwiftTesting REQUIRED)
|
||||
|
||||
add_executable(TestHTMLTokenizerSwift TestHTMLTokenizerSwift.swift)
|
||||
target_link_libraries(TestHTMLTokenizerSwift PRIVATE AK LibWeb)
|
||||
target_compile_options(TestHTMLTokenizerSwift PRIVATE -parse-as-library)
|
||||
add_test(NAME TestHTMLTokenizerSwift COMMAND TestHTMLTokenizerSwift)
|
||||
add_executable(TestLibWebSwift
|
||||
TestLibWebSwiftBindings.swift
|
||||
TestHTMLTokenizerSwift.swift
|
||||
)
|
||||
|
||||
# FIXME: Swift doesn't seem to like object libraries for @main
|
||||
target_sources(TestLibWebSwift PRIVATE ../Resources/SwiftTestMain.swift)
|
||||
|
||||
set_target_properties(TestLibWebSwift PROPERTIES SUFFIX .swift-testing)
|
||||
target_link_libraries(TestLibWebSwift PRIVATE AK LibWeb SwiftTesting::SwiftTesting)
|
||||
add_test(NAME TestLibWebSwift COMMAND TestLibWebSwift)
|
||||
endif()
|
||||
|
|
|
@ -6,54 +6,28 @@
|
|||
|
||||
import AK
|
||||
import Web
|
||||
import Foundation
|
||||
import Testing
|
||||
|
||||
class StandardError: TextOutputStream {
|
||||
func write(_ string: Swift.String) {
|
||||
try! FileHandle.standardError.write(contentsOf: Data(string.utf8))
|
||||
}
|
||||
}
|
||||
|
||||
@main
|
||||
@Suite
|
||||
struct TestHTMLTokenizerSwift {
|
||||
|
||||
static func testTokenTypes() {
|
||||
var standardError = StandardError()
|
||||
print("Testing HTMLToken types...", to: &standardError)
|
||||
|
||||
@Test func tokenTypes() {
|
||||
let default_token = HTMLToken()
|
||||
default_token.type = .Character(codePoint: "a")
|
||||
precondition(default_token.isCharacter())
|
||||
#expect(default_token.isCharacter())
|
||||
|
||||
print("\(default_token)", to: &standardError)
|
||||
|
||||
print("HTMLToken types pass", to: &standardError)
|
||||
#expect("\(default_token)" == "HTMLToken(type: Character(codePoint: a))")
|
||||
}
|
||||
|
||||
static func testParserWhitespace() {
|
||||
var standardError = StandardError()
|
||||
print("Testing HTMLToken parser whitespace...", to: &standardError)
|
||||
|
||||
@Test func parserWhitespace() {
|
||||
for codePoint: Character in ["\t", "\n", "\r", "\u{000C}", " "] {
|
||||
let token = HTMLToken(type: .Character(codePoint: codePoint))
|
||||
precondition(token.isParserWhitespace())
|
||||
#expect(token.isParserWhitespace())
|
||||
}
|
||||
|
||||
for codePoint: Character in ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"] {
|
||||
let token = HTMLToken(type: .Character(codePoint: codePoint))
|
||||
precondition(!token.isParserWhitespace())
|
||||
#expect(!token.isParserWhitespace())
|
||||
}
|
||||
|
||||
print("HTMLToken parser whitespace pass", to: &standardError)
|
||||
}
|
||||
|
||||
static func main() {
|
||||
var standardError = StandardError()
|
||||
print("Starting test suite...", to: &standardError)
|
||||
|
||||
testTokenTypes()
|
||||
testParserWhitespace()
|
||||
|
||||
print("All tests pass", to: &standardError)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,42 +6,20 @@
|
|||
|
||||
import AK
|
||||
import Web
|
||||
import Foundation
|
||||
import Testing
|
||||
|
||||
class StandardError: TextOutputStream {
|
||||
func write(_ string: Swift.String) {
|
||||
try! FileHandle.standardError.write(contentsOf: Data(string.utf8))
|
||||
}
|
||||
}
|
||||
|
||||
@main
|
||||
@Suite
|
||||
struct TestLibWebSwiftBindings {
|
||||
|
||||
static func testEnumsAreBound() {
|
||||
var standardError = StandardError()
|
||||
print("Testing LibWeb enum types...", to: &standardError)
|
||||
@Test func enumsAreBound() {
|
||||
#expect(Web.DOM.NodeType.ELEMENT_NODE.rawValue == 1)
|
||||
|
||||
print("Web.DOM.NodeType.ELEMENT_NODE == \(Web.DOM.NodeType.ELEMENT_NODE)", to: &standardError)
|
||||
precondition(Web.DOM.NodeType.ELEMENT_NODE.rawValue == 1)
|
||||
|
||||
print("Web.Bindings.NavigationType.Push == \(Web.Bindings.NavigationType.Push)", to: &standardError)
|
||||
precondition(Web.Bindings.NavigationType.Push.rawValue == 0)
|
||||
#expect(Web.Bindings.NavigationType.Push.rawValue == 0)
|
||||
|
||||
let end = Web.Bindings.idl_enum_to_string(Web.Bindings.ScrollLogicalPosition.End)
|
||||
let end_view = end.__bytes_as_string_viewUnsafe().bytes();
|
||||
let end_string = Swift.String(bytes: end_view, encoding: .utf8)!
|
||||
|
||||
print("Web.Bindings.idl_enum_to_string(Web.Bindings.ScrollLogicalPosition.End) == \(end_string)", to: &standardError)
|
||||
precondition(end_string == "end")
|
||||
|
||||
print("LibWeb enum types pass", to: &standardError)
|
||||
}
|
||||
|
||||
static func main() {
|
||||
var standardError = StandardError()
|
||||
print("Starting test suite...", to: &standardError)
|
||||
testEnumsAreBound()
|
||||
|
||||
print("All tests pass", to: &standardError)
|
||||
#expect(end_string == "end")
|
||||
}
|
||||
}
|
||||
|
|
16
Tests/Resources/SwiftTestMain.swift
Normal file
16
Tests/Resources/SwiftTestMain.swift
Normal file
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Andrew Kaster <andrew@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
// FIXME: This file is intended to become redundant as swift-testing stabilizes
|
||||
// See https://github.com/swiftlang/swift-testing/blob/133e30231c4583b02ab3ea2a7f678f3d7f4f8a3d/Documentation/CMake.md#add-an-entry-point
|
||||
|
||||
import Testing
|
||||
|
||||
@main struct Runner {
|
||||
static func main() async {
|
||||
await Testing.__swiftPMEntryPoint() as Never
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue