Skip to content

Commit ac52442

Browse files
authored
feat: visionOS unit tests (#257)
1 parent b73693a commit ac52442

File tree

8 files changed

+119
-62
lines changed

8 files changed

+119
-62
lines changed

NativeScript/NativeScript-Prefix.pch

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef NativeScript_Prefix_pch
22
#define NativeScript_Prefix_pch
33

4-
#define NATIVESCRIPT_VERSION "8.7.2"
4+
#define NATIVESCRIPT_VERSION "8.8.1"
55

66
#ifdef DEBUG
77
#define SIZEOF_OFF_T 8

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ To start diving into the v8 iOS runtime make sure you have Xcode and [Homebrew](
55
# Install CMake
66
brew install cmake
77

8+
# Install jq (for scripting json replacements)
9+
brew install jq
10+
811
# (Optional) Install clang-format to format the code
912
brew install clang-format
1013

TestFixtures/Api/TNSVersions.h

+57-54
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,59 @@
1-
#define generateVersionDeclarations(V1, V2) \
2-
__attribute__((availability(ios, introduced = V1))) \
3-
@interface TNSInterface \
4-
##V2##Plus : NSObject \
5-
@end \
6-
\
7-
@interface TNSInterfaceMembers \
8-
##V2 : NSObject \
9-
@property int property \
10-
__attribute__((availability(ios, introduced = V1))); \
11-
\
12-
+(void)staticMethod \
13-
__attribute__((availability(ios, introduced = V1))); \
14-
\
15-
-(void)instanceMethod \
16-
__attribute__((availability(ios, introduced = V1))); \
17-
@end \
18-
\
19-
__attribute__((availability(ios, introduced = V1))) void TNSFunction##V2##Plus(); \
20-
\
21-
__attribute__((availability(ios, introduced = V1))) extern const int TNSConstant##V2##Plus; \
22-
\
23-
enum TNSEnum##V2##Plus { \
24-
TNSEnum##V2##Member \
25-
} \
26-
__attribute__((availability(ios, introduced = V1)))
1+
#define generateVersionDeclarations(V1, V2) \
2+
__attribute__((availability(ios, introduced = V1))) \
3+
__attribute__((availability(visionos, introduced = V1))) @interface TNSInterface \
4+
##V2##Plus : NSObject @end \
5+
\
6+
@interface TNSInterfaceMembers \
7+
##V2 : NSObject @property int property __attribute__((availability(ios, introduced = V1))) \
8+
__attribute__((availability(visionos, introduced = V1))); \
9+
\
10+
+(void)staticMethod __attribute__((availability(ios, introduced = V1))) \
11+
__attribute__((availability(visionos, introduced = V1))); \
12+
\
13+
-(void)instanceMethod __attribute__((availability(ios, introduced = V1))) \
14+
__attribute__((availability(visionos, introduced = V1))); \
15+
@end \
16+
\
17+
__attribute__((availability(ios, introduced = V1))) \
18+
__attribute__((availability(visionos, introduced = V1))) void TNSFunction##V2##Plus(); \
19+
\
20+
__attribute__((availability(ios, introduced = V1))) __attribute__( \
21+
(availability(visionos, introduced = V1))) extern const int TNSConstant##V2##Plus; \
22+
\
23+
enum TNSEnum##V2##Plus { TNSEnum##V2##Member } \
24+
__attribute__((availability(ios, introduced = V1))) \
25+
__attribute__((availability(visionos, introduced = V1)))
2726

2827
#ifndef generateVersionImpl
29-
#define generateVersion(V1, V2) \
30-
generateVersionDeclarations(V1, V2)
28+
#define generateVersion(V1, V2) generateVersionDeclarations(V1, V2)
3129
#else
32-
#define generateVersion(V1, V2) \
33-
generateVersionDeclarations(V1, V2); \
34-
\
35-
@implementation TNSInterface \
36-
##V2##Plus \
37-
@end \
38-
\
39-
@implementation TNSInterfaceMembers \
40-
##V2 \
41-
+ (void)staticMethod{} \
42-
\
43-
- (void)instanceMethod {} \
44-
@end \
45-
\
46-
void TNSFunction##V2##Plus() {} \
47-
\
48-
const int TNSConstant##V2##Plus = 0
30+
#define generateVersion(V1, V2) \
31+
generateVersionDeclarations(V1, V2); \
32+
\
33+
@implementation TNSInterface \
34+
##V2##Plus @end \
35+
\
36+
@implementation TNSInterfaceMembers \
37+
##V2 + (void)staticMethod{} \
38+
\
39+
- (void)instanceMethod {} \
40+
@end \
41+
\
42+
void TNSFunction##V2##Plus() {} \
43+
\
44+
const int TNSConstant##V2##Plus = 0
4945
#endif
5046

51-
#define generateMinors(MAJOR) \
52-
generateVersion(MAJOR##.0, MAJOR##_0); \
53-
generateVersion(MAJOR##.1, MAJOR##_1); \
54-
generateVersion(MAJOR##.2, MAJOR##_2); \
55-
generateVersion(MAJOR##.3, MAJOR##_3); \
56-
generateVersion(MAJOR##.4, MAJOR##_4); \
57-
generateVersion(MAJOR##.5, MAJOR##_5);
47+
#define generateMinors(MAJOR) \
48+
generateVersion(MAJOR##.0, MAJOR##_0); \
49+
generateVersion(MAJOR##.1, MAJOR##_1); \
50+
generateVersion(MAJOR##.2, MAJOR##_2); \
51+
generateVersion(MAJOR##.3, MAJOR##_3); \
52+
generateVersion(MAJOR##.4, MAJOR##_4); \
53+
generateVersion(MAJOR##.5, MAJOR##_5);
5854

55+
generateMinors(1);
56+
generateMinors(2);
5957
generateMinors(9);
6058
generateMinors(10);
6159
generateMinors(11);
@@ -64,10 +62,12 @@ generateMinors(13);
6462
generateMinors(14);
6563
generateMinors(15);
6664

67-
// max availability version that can be currently represented in the binary metadata is 31.7 (major << 3 | minor) -> uint8_t
65+
// max availability version that can be currently represented in the binary metadata is 31.7 (major
66+
// << 3 | minor) -> uint8_t
6867
#define MAX_AVAILABILITY 31.7
6968

7069
__attribute__((availability(ios, introduced = MAX_AVAILABILITY)))
70+
__attribute__((availability(visionos, introduced = MAX_AVAILABILITY)))
7171
@protocol TNSProtocolNeverAvailable<NSObject>
7272

7373
@property(class, readonly) int staticPropertyFromProtocolNeverAvailable;
@@ -85,6 +85,7 @@ __attribute__((availability(ios, introduced = MAX_AVAILABILITY)))
8585
@end
8686

8787
__attribute__((availability(ios, introduced = 1.0)))
88+
__attribute__((availability(visionos, introduced = 1.0)))
8889
@protocol TNSProtocolAlwaysAvailable<NSObject>
8990

9091
@property(class, readonly) int staticPropertyFromProtocolAlwaysAvailable;
@@ -97,10 +98,12 @@ __attribute__((availability(ios, introduced = 1.0)))
9798

9899
@end
99100

100-
@interface TNSInterfaceAlwaysAvailable : NSObject <TNSProtocolNeverAvailable, TNSProtocolAlwaysAvailable>
101+
@interface TNSInterfaceAlwaysAvailable
102+
: NSObject <TNSProtocolNeverAvailable, TNSProtocolAlwaysAvailable>
101103
@end
102104

103105
__attribute__((availability(ios, introduced = MAX_AVAILABILITY)))
106+
__attribute__((availability(visionos, introduced = MAX_AVAILABILITY)))
104107
@interface TNSInterfaceNeverAvailable : TNSInterfaceAlwaysAvailable
105108
@end
106109

TestFixtures/exported-symbols.txt

+9
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ _functionWithUShortPtr
5858
_TNSIsConfigurationDebug
5959
_TNSClearOutput
6060
_TNSConstant
61+
_TNSConstant1_0Plus
62+
_TNSConstant1_1Plus
63+
_TNSConstant1_2Plus
6164
_TNSConstant10_0Plus
6265
_TNSConstant10_1Plus
6366
_TNSConstant10_2Plus
@@ -94,12 +97,18 @@ _TNSConstant15_2Plus
9497
_TNSConstant15_3Plus
9598
_TNSConstant15_4Plus
9699
_TNSConstant15_5Plus
100+
_TNSConstant1_0Plus
101+
_TNSConstant1_1Plus
102+
_TNSConstant1_2Plus
97103
_TNSConstant9_0Plus
98104
_TNSConstant9_1Plus
99105
_TNSConstant9_2Plus
100106
_TNSConstant9_3Plus
101107
_TNSConstant9_4Plus
102108
_TNSConstant9_5Plus
109+
_TNSFunction1_0Plus
110+
_TNSFunction1_1Plus
111+
_TNSFunction1_2Plus
103112
_TNSFunction9_0Plus
104113
_TNSFunction9_1Plus
105114
_TNSFunction9_2Plus

TestRunner/app/tests/Infrastructure/simulator.js

+6
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ function isSimulator() {
77
}
88

99
global.isSimulator = isSimulator();
10+
11+
function isVision() {
12+
return UIDevice.currentDevice.model.toLowerCase().includes('vision');
13+
}
14+
15+
global.isVision = isVision();

TestRunner/app/tests/MetadataTests.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ describe("Metadata", function () {
1010
const swiftLikeObj = TNSSwiftLikeFactory.create();
1111
expect(swiftLikeObj.constructor).toBe(global.TNSSwiftLike);
1212
expect(swiftLikeObj.constructor.name).toBe("_TtC17NativeScriptTests12TNSSwiftLike");
13-
var expectedName = NSProcessInfo.processInfo.isOperatingSystemAtLeastVersion({ majorVersion: 13, minorVersion: 4, patchVersion: 0 })
13+
let majorVersion = 13;
14+
let minorVersion = 4;
15+
if (isVision) {
16+
majorVersion = 1;
17+
minorVersion = 0;
18+
}
19+
var expectedName = NSProcessInfo.processInfo.isOperatingSystemAtLeastVersion({ majorVersion: majorVersion, minorVersion: minorVersion, patchVersion: 0 })
1420
? "_TtC17NativeScriptTests12TNSSwiftLike"
1521
: "NativeScriptTests.TNSSwiftLike";
1622
expect(NSString.stringWithUTF8String(class_getName(swiftLikeObj.constructor)).toString()).toBe(expectedName);

TestRunner/app/tests/VersionDiffTests.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,16 @@ describe(module.id, function() {
1717
}
1818

1919
function forEachVersion(action) {
20-
for (var major = 9; major <= 15; major++) {
21-
for (var minor = 0; minor <= 5; minor++) {
20+
let majorMinVersion = 9;
21+
let majorMaxVersion = 15;
22+
let minorMaxVersion = 5;
23+
if (isVision) {
24+
majorMinVersion = 1;
25+
majorMaxVersion = 1;
26+
minorMaxVersion = 2;
27+
}
28+
for (var major = majorMinVersion; major <= majorMaxVersion; major++) {
29+
for (var minor = 0; minor <= minorMaxVersion; minor++) {
2230
action(major, minor);
2331
}
2432
}
@@ -74,6 +82,10 @@ describe(module.id, function() {
7482
});
7583

7684
it("Base class which is unavailable should be skipped", function() {
85+
if (isVision) {
86+
pending();
87+
return;
88+
}
7789
// Test case inspired from MTLArrayType(8.0) : MTLType(11.0) : NSObject
7890
// TNSInterfaceNeverAvailableDescendant : TNSInterfaceNeverAvailable(API31.7 - skipped) : TNSInterfaceAlwaysAvailable
7991
expect(Object.getPrototypeOf(TNSInterfaceNeverAvailableDescendant).toString()).toBe(TNSInterfaceAlwaysAvailable.toString(), "TNSInterfaceNeverAvailable base class should be skipped as it is unavailable");

v8ios.xcodeproj/project.pbxproj

+22-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
2B5088A62BBEB92300F6EB68 /* metadata-arm64.bin in Resources */ = {isa = PBXBuildFile; fileRef = 2BFE21ED2AC1AC3100307752 /* metadata-arm64.bin */; };
1110
2B5088A72BBEC1BC00F6EB68 /* TNSWidgets.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = C20525A72577D86600C12A5C /* TNSWidgets.xcframework */; };
12-
2B5088A82BBEC1BC00F6EB68 /* TNSWidgets.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C20525A72577D86600C12A5C /* TNSWidgets.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
1311
2B7EA6AF2353477000E5184E /* NativeScriptException.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2B7EA6AD2353476F00E5184E /* NativeScriptException.mm */; };
1412
2B7EA6B02353477000E5184E /* NativeScriptException.h in Headers */ = {isa = PBXBuildFile; fileRef = 2B7EA6AE2353477000E5184E /* NativeScriptException.h */; };
1513
2BFE22062AC1C93100307752 /* metadata-arm64.bin in Resources */ = {isa = PBXBuildFile; fileRef = 2BFE22052AC1C93100307752 /* metadata-arm64.bin */; };
@@ -1843,7 +1841,6 @@
18431841
files = (
18441842
C27E5DB522F3206B00498ED0 /* app in Resources */,
18451843
C27E5DBA22F324C200498ED0 /* [email protected] in Resources */,
1846-
2B5088A62BBEB92300F6EB68 /* metadata-arm64.bin in Resources */,
18471844
);
18481845
runOnlyForDeploymentPostprocessing = 0;
18491846
};
@@ -2282,7 +2279,6 @@
22822279
};
22832280
C293752B229FC4740075CB16 /* PBXTargetDependency */ = {
22842281
isa = PBXTargetDependency;
2285-
platformFilter = ios;
22862282
target = C29374E1229FC0F60075CB16 /* TestFixtures */;
22872283
targetProxy = C293752A229FC4740075CB16 /* PBXContainerItemProxy */;
22882284
};
@@ -2376,6 +2372,7 @@
23762372
C23992CE236C2D6E00D2F720 /* Debug */ = {
23772373
isa = XCBuildConfiguration;
23782374
buildSettings = {
2375+
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
23792376
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = NO;
23802377
CLANG_ENABLE_MODULES = NO;
23812378
CODE_SIGN_STYLE = Automatic;
@@ -2391,6 +2388,8 @@
23912388
);
23922389
PRODUCT_BUNDLE_IDENTIFIER = org.nativescript.TestRunnerTests;
23932390
PRODUCT_NAME = "$(TARGET_NAME)";
2391+
SUPPORTED_PLATFORMS = "xrsimulator xros iphonesimulator iphoneos";
2392+
SUPPORTS_MACCATALYST = YES;
23942393
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
23952394
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
23962395
SWIFT_VERSION = 5.0;
@@ -2402,6 +2401,7 @@
24022401
C23992CF236C2D6E00D2F720 /* Release */ = {
24032402
isa = XCBuildConfiguration;
24042403
buildSettings = {
2404+
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
24052405
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = NO;
24062406
CLANG_ENABLE_MODULES = NO;
24072407
CODE_SIGN_STYLE = Automatic;
@@ -2417,6 +2417,8 @@
24172417
);
24182418
PRODUCT_BUNDLE_IDENTIFIER = org.nativescript.TestRunnerTests;
24192419
PRODUCT_NAME = "$(TARGET_NAME)";
2420+
SUPPORTED_PLATFORMS = "xrsimulator xros iphonesimulator iphoneos";
2421+
SUPPORTS_MACCATALYST = YES;
24202422
SWIFT_COMPILATION_MODE = wholemodule;
24212423
SWIFT_OPTIMIZATION_LEVEL = "-O";
24222424
SWIFT_VERSION = 5.0;
@@ -2549,6 +2551,7 @@
25492551
C27E5D9F22F31CCC00498ED0 /* Debug */ = {
25502552
isa = XCBuildConfiguration;
25512553
buildSettings = {
2554+
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
25522555
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
25532556
CLANG_CXX_LANGUAGE_STANDARD = "compiler-default";
25542557
CLANG_CXX_LIBRARY = "compiler-default";
@@ -2580,13 +2583,16 @@
25802583
);
25812584
PRODUCT_BUNDLE_IDENTIFIER = org.nativescript.AppWithModules;
25822585
PRODUCT_NAME = "$(TARGET_NAME)";
2586+
SUPPORTED_PLATFORMS = "xrsimulator xros iphonesimulator iphoneos";
2587+
SUPPORTS_MACCATALYST = YES;
25832588
TARGETED_DEVICE_FAMILY = 1;
25842589
};
25852590
name = Debug;
25862591
};
25872592
C27E5DA022F31CCC00498ED0 /* Release */ = {
25882593
isa = XCBuildConfiguration;
25892594
buildSettings = {
2595+
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
25902596
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
25912597
CLANG_CXX_LANGUAGE_STANDARD = "compiler-default";
25922598
CLANG_CXX_LIBRARY = "compiler-default";
@@ -2618,13 +2624,16 @@
26182624
);
26192625
PRODUCT_BUNDLE_IDENTIFIER = org.nativescript.AppWithModules;
26202626
PRODUCT_NAME = "$(TARGET_NAME)";
2627+
SUPPORTED_PLATFORMS = "xrsimulator xros iphonesimulator iphoneos";
2628+
SUPPORTS_MACCATALYST = YES;
26212629
TARGETED_DEVICE_FAMILY = 1;
26222630
};
26232631
name = Release;
26242632
};
26252633
C29374E9229FC0F60075CB16 /* Debug */ = {
26262634
isa = XCBuildConfiguration;
26272635
buildSettings = {
2636+
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
26282637
CLANG_ENABLE_MODULES = NO;
26292638
CLANG_WARN_STRICT_PROTOTYPES = NO;
26302639
DEFINES_MODULE = YES;
@@ -2633,7 +2642,10 @@
26332642
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
26342643
OTHER_LDFLAGS = "-ObjC";
26352644
PRODUCT_NAME = "$(TARGET_NAME)";
2645+
SDKROOT = iphoneos;
26362646
SKIP_INSTALL = YES;
2647+
SUPPORTED_PLATFORMS = "xrsimulator xros iphonesimulator iphoneos";
2648+
SUPPORTS_MACCATALYST = YES;
26372649
SYMROOT = build;
26382650
TARGETED_DEVICE_FAMILY = "1,2";
26392651
};
@@ -2642,6 +2654,7 @@
26422654
C29374EA229FC0F60075CB16 /* Release */ = {
26432655
isa = XCBuildConfiguration;
26442656
buildSettings = {
2657+
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
26452658
CLANG_ENABLE_MODULES = NO;
26462659
CLANG_WARN_STRICT_PROTOTYPES = NO;
26472660
DEFINES_MODULE = YES;
@@ -2651,7 +2664,10 @@
26512664
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
26522665
OTHER_LDFLAGS = "-ObjC";
26532666
PRODUCT_NAME = "$(TARGET_NAME)";
2667+
SDKROOT = iphoneos;
26542668
SKIP_INSTALL = YES;
2669+
SUPPORTED_PLATFORMS = "xrsimulator xros iphonesimulator iphoneos";
2670+
SUPPORTS_MACCATALYST = YES;
26552671
SYMROOT = build;
26562672
TARGETED_DEVICE_FAMILY = "1,2";
26572673
};
@@ -2839,6 +2855,7 @@
28392855
__DATA,
28402856
__TNSMetadata,
28412857
"\"$(SRCROOT)/NativeScript/metadata-arm64.bin\"",
2858+
"-w",
28422859
);
28432860
PRODUCT_BUNDLE_IDENTIFIER = org.nativescript.NativeScript;
28442861
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
@@ -2931,6 +2948,7 @@
29312948
__DATA,
29322949
__TNSMetadata,
29332950
"\"$(SRCROOT)/NativeScript/metadata-arm64.bin\"",
2951+
"-w",
29342952
);
29352953
PRODUCT_BUNDLE_IDENTIFIER = org.nativescript.NativeScript;
29362954
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";

0 commit comments

Comments
 (0)