|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: %target-build-swift-dylib(%t/%target-library-name(TestDidWillSet)) -module-name TestDidWillSet -emit-module -emit-module-path %t/TestDidWillSet.swiftmodule -swift-version 5 %S/Inputs/dynamic_replacement_property_observer_orig.swift -Xfrontend -enable-private-imports -Xfrontend -enable-implicit-dynamic |
| 3 | +// RUN: %target-build-swift-dylib(%t/%target-library-name(TestDidWillSet2)) -I%t -L%t -lTestDidWillSet %target-rpath(%t) -module-name TestDidWillSet2 -swift-version 5 %S/Inputs/dynamic_replacement_property_observer_repl.swift |
| 4 | +// RUN: %target-build-swift -I%t -L%t -lTestDidWillSet -o %t/main %target-rpath(%t) %s -swift-version 5 |
| 5 | +// RUN: %target-codesign %t/main %t/%target-library-name(TestDidWillSet) %t/%target-library-name(TestDidWillSet2) |
| 6 | +// RUN: %target-run %t/main %t/%target-library-name(TestDidWillSet) %t/%target-library-name(TestDidWillSet) |
| 7 | + |
| 8 | +// REQUIRES: executable_test |
| 9 | + |
| 10 | +@_private(sourceFile: "dynamic_replacement_property_observer_orig.swift") import TestDidWillSet |
| 11 | + |
| 12 | +#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) |
| 13 | + import Darwin |
| 14 | +#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) |
| 15 | + import Glibc |
| 16 | +#elseif os(Windows) |
| 17 | + import MSVCRT |
| 18 | + import WinSDK |
| 19 | +#else |
| 20 | +#error("Unsupported platform") |
| 21 | +#endif |
| 22 | + |
| 23 | +private func target_library_name(_ name: String) -> String { |
| 24 | +#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS) |
| 25 | + return "lib\(name).dylib" |
| 26 | +#elseif os(Windows) |
| 27 | + return "\(name).dll" |
| 28 | +#else |
| 29 | + return "lib\(name).so" |
| 30 | +#endif |
| 31 | +} |
| 32 | + |
| 33 | +var s = Stored(i: 5, y: 5, z: 5) |
| 34 | +var h = HeapStored() |
| 35 | + |
| 36 | +// CHECK: Stored.i.didSet from 5 to 10 original |
| 37 | +s.i = 10 |
| 38 | +// CHECK: Stored.y.willSet from 5 to 11 original |
| 39 | +s.y = 11 |
| 40 | +// CHECK: Stored.z.willSet from 5 to 12 original |
| 41 | +// CHECK: Stored.z.didSet from 5 to 12 original |
| 42 | +s.z = 12 |
| 43 | + |
| 44 | +// CHECK: HeapStored.z.willSet from 5 to 16 original |
| 45 | +// CHECK: HeapStored.z.didSet from 5 to 16 original |
| 46 | +h.z = 16 |
| 47 | + |
| 48 | +// CHECK: myglobal.didSet from 1 to 13 original |
| 49 | +myglobal = 13 |
| 50 | +// CHECK: myglobal2.willSet from 1 to 14 original |
| 51 | +myglobal2 = 14 |
| 52 | +// CHECK: myglobal3.willSet from 1 to 15 original |
| 53 | +// CHECK: myglobal3.didSet from 1 to 15 original |
| 54 | +myglobal3 = 15 |
| 55 | + |
| 56 | +var executablePath = CommandLine.arguments[0] |
| 57 | +executablePath.removeLast(4) |
| 58 | + |
| 59 | +// Now, test with the module containing the replacements. |
| 60 | + |
| 61 | +#if os(Linux) |
| 62 | + _ = dlopen(target_library_name("Module2"), RTLD_NOW) |
| 63 | +#elseif os(Windows) |
| 64 | + _ = LoadLibraryA(target_library_name("Module2")) |
| 65 | +#else |
| 66 | + _ = dlopen(executablePath+target_library_name("Module2"), RTLD_NOW) |
| 67 | +#endif |
| 68 | + |
| 69 | +// CHECK: Stored.i.didSet from 5 to 10 replacement |
| 70 | +s.i = 10 |
| 71 | +// CHECK: Stored.y.willSet from 5 to 11 replacement |
| 72 | +s.y = 11 |
| 73 | +// CHECK: Stored.z.willSet from 5 to 12 replacement |
| 74 | +// CHECK: Stored.z.didSet from 5 to 12 replacement |
| 75 | +s.z = 12 |
| 76 | + |
| 77 | +// CHECK: HeapStored.z.willSet from 5 to 16 replacement |
| 78 | +// CHECK: HeapStored.z.didSet from 5 to 16 replacement |
| 79 | +h.z = 16 |
| 80 | + |
| 81 | +// CHECK: myglobal.didSet from 1 to 13 replacement |
| 82 | +myglobal = 13 |
| 83 | +// CHECK: myglobal2.willSet from 1 to 14 replacement |
| 84 | +myglobal2 = 14 |
| 85 | +// CHECK: myglobal3.willSet from 1 to 15 replacement |
| 86 | +// CHECK: myglobal3.didSet from 1 to 15 replacement |
| 87 | +myglobal3 = 15 |
0 commit comments