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:
Andrew Kaster 2024-08-17 12:53:39 -06:00 committed by Andrew Kaster
parent 7f0044a721
commit 315a666e53
Notes: github-actions[bot] 2024-08-17 23:45:25 +00:00
3 changed files with 58 additions and 1 deletions

View file

@ -149,7 +149,8 @@ jobs:
- name: Enable the AppKit chrome with Swift files - name: Enable the AppKit chrome with Swift files
if: ${{ inputs.os_name == 'macOS' && inputs.fuzzer == 'NO_FUZZ' }} if: ${{ inputs.os_name == 'macOS' && inputs.fuzzer == 'NO_FUZZ' }}
working-directory: ${{ github.workspace }} 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 - name: Build the AppKit chrome with Swift files
if: ${{ inputs.os_name == 'macOS' && inputs.fuzzer == 'NO_FUZZ' }} if: ${{ inputs.os_name == 'macOS' && inputs.fuzzer == 'NO_FUZZ' }}

View file

@ -91,3 +91,10 @@ foreach(source IN LISTS AK_TEST_SOURCES)
endforeach() endforeach()
target_link_libraries(TestString PRIVATE LibUnicode) 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()

View 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)
}
}