mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 15:10:19 +00:00
Tests: Add test to verify CxxSequence protocol conformance of containers
Building the test in debug mode currently crashes the swift frontend, so we'll need to build this in release mode until that's fixed.
This commit is contained in:
parent
7f0044a721
commit
315a666e53
Notes:
github-actions[bot]
2024-08-17 23:45:25 +00:00
Author: https://github.com/ADKaster Commit: https://github.com/LadybirdBrowser/ladybird/commit/315a666e533 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/986
3 changed files with 58 additions and 1 deletions
3
.github/workflows/lagom-template.yml
vendored
3
.github/workflows/lagom-template.yml
vendored
|
@ -149,7 +149,8 @@ jobs:
|
|||
- name: Enable the AppKit chrome with Swift files
|
||||
if: ${{ inputs.os_name == 'macOS' && inputs.fuzzer == 'NO_FUZZ' }}
|
||||
working-directory: ${{ github.workspace }}
|
||||
run: cmake -B Build -DENABLE_QT=OFF -DENABLE_SWIFT=ON
|
||||
# FIXME: Don't force release build after https://github.com/LadybirdBrowser/ladybird/issues/1101 is fixed
|
||||
run: cmake -B Build -DENABLE_QT=OFF -DENABLE_SWIFT=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo
|
||||
|
||||
- name: Build the AppKit chrome with Swift files
|
||||
if: ${{ inputs.os_name == 'macOS' && inputs.fuzzer == 'NO_FUZZ' }}
|
||||
|
|
|
@ -91,3 +91,10 @@ foreach(source IN LISTS AK_TEST_SOURCES)
|
|||
endforeach()
|
||||
|
||||
target_link_libraries(TestString PRIVATE LibUnicode)
|
||||
|
||||
if (ENABLE_SWIFT)
|
||||
add_executable(TestAKBindings TestAKBindings.swift)
|
||||
target_link_libraries(TestAKBindings PRIVATE AK)
|
||||
target_compile_options(TestAKBindings PRIVATE -parse-as-library)
|
||||
add_test(NAME TestAKBindings COMMAND TestAKBindings)
|
||||
endif()
|
||||
|
|
49
Tests/AK/TestAKBindings.swift
Normal file
49
Tests/AK/TestAKBindings.swift
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Andrew Kaster <andrew@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
import AK
|
||||
import Foundation
|
||||
|
||||
protocol ConformanceMarker {}
|
||||
enum CxxSequenceMarker<T: ~Copyable> {}
|
||||
extension CxxSequenceMarker: ConformanceMarker where T: CxxSequence {}
|
||||
private func isCxxSequenceType<T: ~Copyable>(_ type: borrowing T.Type) -> Bool {
|
||||
return CxxSequenceMarker<T>.self is ConformanceMarker.Type
|
||||
}
|
||||
|
||||
class StandardError: TextOutputStream {
|
||||
func write(_ string: Swift.String) {
|
||||
try! FileHandle.standardError.write(contentsOf: Data(string.utf8))
|
||||
}
|
||||
}
|
||||
|
||||
@main
|
||||
struct TestAKBindings {
|
||||
static func testSequenceTypesAreBound() {
|
||||
var standardError = StandardError()
|
||||
print("Testing CxxSequence types...", to: &standardError)
|
||||
|
||||
precondition(isCxxSequenceType(AK.StringView.self))
|
||||
precondition(isCxxSequenceType(AK.Bytes.self))
|
||||
precondition(isCxxSequenceType(AK.ReadonlyBytes.self))
|
||||
precondition(isCxxSequenceType(AK.Utf16Data.self))
|
||||
|
||||
precondition(!isCxxSequenceType(AK.Utf16View.self))
|
||||
precondition(!isCxxSequenceType(AK.String.self))
|
||||
|
||||
precondition(!isCxxSequenceType(AK.Error.self))
|
||||
|
||||
print("CxxSequence types pass", to: &standardError)
|
||||
}
|
||||
|
||||
static func main() {
|
||||
var standardError = StandardError()
|
||||
print("Starting test suite...", to: &standardError)
|
||||
testSequenceTypesAreBound()
|
||||
|
||||
print("All tests pass", to: &standardError)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue