From a52a34c229d4a92121973f65207575ee8152c63a Mon Sep 17 00:00:00 2001 From: Byoungchan Lee Date: Sun, 20 Apr 2025 09:08:38 +0900 Subject: [PATCH 1/4] Fix testPromiseWhenNilBridgesToThenChain to assert nil instead of NSNull --- Tests/PromisesTests/Promise+ThenTests.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/PromisesTests/Promise+ThenTests.swift b/Tests/PromisesTests/Promise+ThenTests.swift index 35eabde..65fcdb9 100644 --- a/Tests/PromisesTests/Promise+ThenTests.swift +++ b/Tests/PromisesTests/Promise+ThenTests.swift @@ -59,20 +59,20 @@ class PromiseThenTests: XCTestCase { XCTAssertNil(postFinalPromise.error) } - func testPromiseWhenNilBridgesToNSNullInThenChain() { + func testPromiseWhenNilBridgesToNilInThenChain() { // Act. let promise = Promise { fulfill, _ in fulfill(nil) }.catch { _ in XCTFail() }.then { value in - XCTAssert(value is NSNull) + XCTAssertNil(value) } // Assert. XCTAssert(waitForPromises(timeout: 10)) XCTAssertTrue(promise.isFulfilled) - XCTAssert(promise.value is NSNull) + XCTAssertNil(promise.value) XCTAssertNil(promise.error) } From 81e52ea0325bf09d8b8239991bf203d986dc2fdc Mon Sep 17 00:00:00 2001 From: Byoungchan Lee Date: Sun, 20 Apr 2025 09:09:51 +0900 Subject: [PATCH 2/4] Update .gitignore to exclude SwiftPM configuration files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 4178c3e..140bca5 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,8 @@ Packages/ .build/ *.resolved +.swiftpm/configuration/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata # Bazel From b434bbfa2c4212ba580457c5f605da43767d441f Mon Sep 17 00:00:00 2001 From: Byoungchan Lee Date: Sun, 20 Apr 2025 09:16:37 +0900 Subject: [PATCH 3/4] Enhance Bazel module support and ignore un-compilable tests Introduce a MODULE.bazel file to enable native support for bzlmod. Update BUILD.bazel to allow the tests to run on macOS as well. Some test cases in Bazel are modified (still enabled in SPM and CocoaPods) due to issues with objc_library and module imports. --- .gitignore | 1 + BUILD.bazel | 38 ++++++++----------- MODULE.bazel | 12 ++++++ .../FBLPromise+CatchInteroperabilityTests.m | 6 +++ .../FBLPromise+ThenInteroperabilityTests.m | 6 +++ 5 files changed, 41 insertions(+), 22 deletions(-) create mode 100644 MODULE.bazel diff --git a/.gitignore b/.gitignore index 140bca5..3510d1c 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ Packages/ .build/ +.swiftpm/ *.resolved .swiftpm/configuration/registries.json .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata diff --git a/BUILD.bazel b/BUILD.bazel index 575ef73..9a19731 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -5,6 +5,7 @@ licenses(["notice"]) # Apache 2.0 exports_files(["LICENSE"]) load("@build_bazel_rules_apple//apple:ios.bzl", "ios_application", "ios_unit_test") +load("@build_bazel_rules_apple//apple:macos.bzl", "macos_unit_test") load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") OBJC_COPTS = [ @@ -81,7 +82,8 @@ objc_library( ios_unit_test( name = "Tests", minimum_os_version = MINIMUM_OS_VERSION, - test_host = ":TestHostApp", + target_compatible_with = ["@platforms//os:ios"], + runner = "@rules_apple//apple/testing/default_runner:ios_xctestrun_ordered_runner", deps = [ ":FBLPromisesInteroperabilityTests", ":FBLPromisesPerformanceTests", @@ -92,30 +94,20 @@ ios_unit_test( ], ) -ios_application( - name = "TestHostApp", - testonly = 1, - bundle_id = "com.google.promises.TestHost", - families = [ - "iphone", - "ipad", - ], - infoplists = [ - "Promises.xcodeproj/TestHost_Info.plist", - ], - minimum_os_version = MINIMUM_OS_VERSION, +macos_unit_test( + name = "Tests_macOS", + minimum_os_version = "10.15", + target_compatible_with = ["@platforms//os:osx"], deps = [ - ":TestHost", + ":FBLPromisesInteroperabilityTests", + ":FBLPromisesPerformanceTests", + ":FBLPromisesTests", + ":PromisesInteroperabilityTests", + ":PromisesPerformanceTests", + ":PromisesTests", ], ) -swift_library( - name = "TestHost", - testonly = 1, - srcs = glob([ - "Tests/TestHost/*.swift", - ]), -) swift_library( name = "PromisesTests", @@ -172,8 +164,10 @@ objc_library( ]), copts = OBJC_COPTS, includes = [ - "../Promises", + "Promises", ], + enable_modules = True, + module_name = "FBLPromisesInteroperabilityTests", deps = [ ":FBLPromisesTestHelpers", ":PromisesTestHelpers", diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 0000000..2d092ab --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,12 @@ +module(name = "promises", version = "2.4.0") + +bazel_dep(name = "rules_cc", version = "0.1.1") +bazel_dep(name = "rules_apple", version = "3.20.1", repo_name = "build_bazel_rules_apple") +bazel_dep(name = "rules_swift", version = "2.7.0", repo_name = "build_bazel_rules_swift") +bazel_dep(name = "platforms", version = "0.0.11") +bazel_dep(name = "apple_support", version = "1.20.0") + +apple_cc_configure = use_extension("@apple_support//crosstool:setup.bzl", "apple_cc_configure_extension") +use_repo(apple_cc_configure, "local_config_apple_cc", "local_config_apple_cc_toolchains") + +register_toolchains("@local_config_apple_cc_toolchains//:all") diff --git a/Tests/FBLPromisesInteroperabilityTests/FBLPromise+CatchInteroperabilityTests.m b/Tests/FBLPromisesInteroperabilityTests/FBLPromise+CatchInteroperabilityTests.m index c2052a3..2bb29e4 100644 --- a/Tests/FBLPromisesInteroperabilityTests/FBLPromise+CatchInteroperabilityTests.m +++ b/Tests/FBLPromisesInteroperabilityTests/FBLPromise+CatchInteroperabilityTests.m @@ -14,6 +14,10 @@ limitations under the License. */ +// Currently this test does not work with Bazel. +// See https://github.com/bazelbuild/rules_apple/issues/2690 for more details. +#if defined(COCOAPODS) || defined(SWIFT_PACKAGE) + #import "FBLPromise+Catch.h" #import @@ -65,3 +69,5 @@ - (void)testPromiseThrow { } @end + +#endif diff --git a/Tests/FBLPromisesInteroperabilityTests/FBLPromise+ThenInteroperabilityTests.m b/Tests/FBLPromisesInteroperabilityTests/FBLPromise+ThenInteroperabilityTests.m index e25d4e4..ebefecc 100644 --- a/Tests/FBLPromisesInteroperabilityTests/FBLPromise+ThenInteroperabilityTests.m +++ b/Tests/FBLPromisesInteroperabilityTests/FBLPromise+ThenInteroperabilityTests.m @@ -14,6 +14,10 @@ limitations under the License. */ +// Currently this test does not work with Bazel. +// See https://github.com/bazelbuild/rules_apple/issues/2690 for more details. +#if defined(COCOAPODS) || defined(SWIFT_PACKAGE) + #import "FBLPromise+Then.h" #import @@ -59,3 +63,5 @@ - (void)testPromiseFulfillNumberNonNil { } @end + +#endif From 73dd28634022e927ce4ed0c3ef23dbee687efbdf Mon Sep 17 00:00:00 2001 From: Byoungchan Lee Date: Sun, 20 Apr 2025 09:20:49 +0900 Subject: [PATCH 4/4] Add Bazel CI configuration for building and testing --- .github/workflows/ci.yaml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f135a9a..6eeaf71 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -17,6 +17,28 @@ jobs: - name: Test run: swift test + bazel: + runs-on: macOS-latest + strategy: + fail-fast: false + matrix: + MODE: [ "dbg", "opt" ] + env: + USE_BAZEL_VERSION: 8.x + steps: + - uses: actions/checkout@v4 + - uses: bazel-contrib/setup-bazel@0.14.0 + with: + bazelisk-cache: true + repository-cache: true + - name: bazel build + run: | + bazelisk build --enable_bzlmod -c "${{ matrix.MODE }}" //... + - name: bazel test + if: ${{ matrix.MODE == 'dbg' }} + run: | + bazelisk test --enable_bzlmod --build_tests_only -c "${{ matrix.MODE }}" --test_output=all --verbose_failures //... + cocoapods: strategy: matrix: