Skip to content

feat: visionOS unit tests (#257) #271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ To start diving into the v8 iOS runtime make sure you have Xcode and [Homebrew](
# Install CMake
brew install cmake

# Install jq (for scripting json replacements)
brew install jq

# (Optional) Install clang-format to format the code
brew install clang-format

Expand Down
51 changes: 32 additions & 19 deletions TestFixtures/Api/TNSVersions.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
#define generateVersionDeclarations(V1, V2) \
__attribute__((availability(ios, introduced = V1))) @interface TNSInterface \
##V2##Plus : NSObject @end \
\
@interface TNSInterfaceMembers \
##V2 : NSObject @property int property __attribute__((availability(ios, introduced = V1))); \
\
+(void)staticMethod __attribute__((availability(ios, introduced = V1))); \
\
-(void)instanceMethod __attribute__((availability(ios, introduced = V1))); \
@end \
\
__attribute__((availability(ios, introduced = V1))) void TNSFunction##V2##Plus(); \
\
__attribute__((availability(ios, introduced = V1))) extern const int TNSConstant##V2##Plus; \
\
enum TNSEnum##V2##Plus { TNSEnum##V2##Member } \
__attribute__((availability(ios, introduced = V1)))
#define generateVersionDeclarations(V1, V2) \
__attribute__((availability(ios, introduced = V1))) \
__attribute__((availability(visionos, introduced = V1))) @interface TNSInterface \
##V2##Plus : NSObject @end \
\
@interface TNSInterfaceMembers \
##V2 : NSObject @property int property __attribute__((availability(ios, introduced = V1))) \
__attribute__((availability(visionos, introduced = V1))); \
\
+(void)staticMethod __attribute__((availability(ios, introduced = V1))) \
__attribute__((availability(visionos, introduced = V1))); \
\
-(void)instanceMethod __attribute__((availability(ios, introduced = V1))) \
__attribute__((availability(visionos, introduced = V1))); \
@end \
\
__attribute__((availability(ios, introduced = V1))) \
__attribute__((availability(visionos, introduced = V1))) void TNSFunction##V2##Plus(); \
\
__attribute__((availability(ios, introduced = V1))) __attribute__( \
(availability(visionos, introduced = V1))) extern const int TNSConstant##V2##Plus; \
\
enum TNSEnum##V2##Plus { TNSEnum##V2##Member } \
__attribute__((availability(ios, introduced = V1))) \
__attribute__((availability(visionos, introduced = V1)))

#ifndef generateVersionImpl
#define generateVersion(V1, V2) generateVersionDeclarations(V1, V2)
Expand Down Expand Up @@ -45,6 +52,8 @@
generateVersion(MAJOR##.4, MAJOR##_4); \
generateVersion(MAJOR##.5, MAJOR##_5);

generateMinors(1);
generateMinors(2);
generateMinors(9);
generateMinors(10);
generateMinors(11);
Expand All @@ -58,6 +67,7 @@ generateMinors(15);
#define MAX_AVAILABILITY 31.7

__attribute__((availability(ios, introduced = MAX_AVAILABILITY)))
__attribute__((availability(visionos, introduced = MAX_AVAILABILITY)))
@protocol TNSProtocolNeverAvailable<NSObject>

@property(class, readonly) int staticPropertyFromProtocolNeverAvailable;
Expand All @@ -74,7 +84,9 @@ __attribute__((availability(ios, introduced = MAX_AVAILABILITY)))

@end

__attribute__((availability(ios, introduced = 1.0))) @protocol TNSProtocolAlwaysAvailable<NSObject>
__attribute__((availability(ios, introduced = 1.0)))
__attribute__((availability(visionos, introduced = 1.0)))
@protocol TNSProtocolAlwaysAvailable<NSObject>

@property(class, readonly) int staticPropertyFromProtocolAlwaysAvailable;

Expand All @@ -91,6 +103,7 @@ __attribute__((availability(ios, introduced = 1.0))) @protocol TNSProtocolAlways
@end

__attribute__((availability(ios, introduced = MAX_AVAILABILITY)))
__attribute__((availability(visionos, introduced = MAX_AVAILABILITY)))
@interface TNSInterfaceNeverAvailable : TNSInterfaceAlwaysAvailable
@end

Expand Down
9 changes: 9 additions & 0 deletions TestFixtures/exported-symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ _functionWithUShortPtr
_TNSIsConfigurationDebug
_TNSClearOutput
_TNSConstant
_TNSConstant1_0Plus
_TNSConstant1_1Plus
_TNSConstant1_2Plus
_TNSConstant10_0Plus
_TNSConstant10_1Plus
_TNSConstant10_2Plus
Expand Down Expand Up @@ -94,12 +97,18 @@ _TNSConstant15_2Plus
_TNSConstant15_3Plus
_TNSConstant15_4Plus
_TNSConstant15_5Plus
_TNSConstant1_0Plus
_TNSConstant1_1Plus
_TNSConstant1_2Plus
_TNSConstant9_0Plus
_TNSConstant9_1Plus
_TNSConstant9_2Plus
_TNSConstant9_3Plus
_TNSConstant9_4Plus
_TNSConstant9_5Plus
_TNSFunction1_0Plus
_TNSFunction1_1Plus
_TNSFunction1_2Plus
_TNSFunction9_0Plus
_TNSFunction9_1Plus
_TNSFunction9_2Plus
Expand Down
6 changes: 6 additions & 0 deletions TestRunner/app/tests/Infrastructure/simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ function isSimulator() {
}

global.isSimulator = isSimulator();

function isVision() {
return UIDevice.currentDevice.model.toLowerCase().includes('vision');
}

global.isVision = isVision();
8 changes: 7 additions & 1 deletion TestRunner/app/tests/MetadataTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ describe("Metadata", function () {
const swiftLikeObj = TNSSwiftLikeFactory.create();
expect(swiftLikeObj.constructor).toBe(global.TNSSwiftLike);
expect(swiftLikeObj.constructor.name).toBe("_TtC17NativeScriptTests12TNSSwiftLike");
var expectedName = NSProcessInfo.processInfo.isOperatingSystemAtLeastVersion({ majorVersion: 13, minorVersion: 4, patchVersion: 0 })
let majorVersion = 13;
let minorVersion = 4;
if (isVision) {
majorVersion = 1;
minorVersion = 0;
}
var expectedName = NSProcessInfo.processInfo.isOperatingSystemAtLeastVersion({ majorVersion: majorVersion, minorVersion: minorVersion, patchVersion: 0 })
? "_TtC17NativeScriptTests12TNSSwiftLike"
: "NativeScriptTests.TNSSwiftLike";
expect(NSString.stringWithUTF8String(class_getName(swiftLikeObj.constructor)).toString()).toBe(expectedName);
Expand Down
16 changes: 14 additions & 2 deletions TestRunner/app/tests/VersionDiffTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ describe(module.id, function() {
}

function forEachVersion(action) {
for (var major = 9; major <= 15; major++) {
for (var minor = 0; minor <= 5; minor++) {
let majorMinVersion = 9;
let majorMaxVersion = 15;
let minorMaxVersion = 5;
if (isVision) {
majorMinVersion = 1;
majorMaxVersion = 1;
minorMaxVersion = 2;
}
for (var major = majorMinVersion; major <= majorMaxVersion; major++) {
for (var minor = 0; minor <= minorMaxVersion; minor++) {
action(major, minor);
}
}
Expand Down Expand Up @@ -74,6 +82,10 @@ describe(module.id, function() {
});

it("Base class which is unavailable should be skipped", function() {
if (isVision) {
pending();
return;
}
// Test case inspired from MTLArrayType(8.0) : MTLType(11.0) : NSObject
// TNSInterfaceNeverAvailableDescendant : TNSInterfaceNeverAvailable(API31.7 - skipped) : TNSInterfaceAlwaysAvailable
expect(Object.getPrototypeOf(TNSInterfaceNeverAvailableDescendant).toString()).toBe(TNSInterfaceAlwaysAvailable.toString(), "TNSInterfaceNeverAvailable base class should be skipped as it is unavailable");
Expand Down
26 changes: 22 additions & 4 deletions v8ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
2B5088A62BBEB92300F6EB68 /* metadata-arm64.bin in Resources */ = {isa = PBXBuildFile; fileRef = 2BFE21ED2AC1AC3100307752 /* metadata-arm64.bin */; };
2B5088A72BBEC1BC00F6EB68 /* TNSWidgets.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = C20525A72577D86600C12A5C /* TNSWidgets.xcframework */; };
2B5088A82BBEC1BC00F6EB68 /* TNSWidgets.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C20525A72577D86600C12A5C /* TNSWidgets.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
2B7EA6AF2353477000E5184E /* NativeScriptException.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2B7EA6AD2353476F00E5184E /* NativeScriptException.mm */; };
2B7EA6B02353477000E5184E /* NativeScriptException.h in Headers */ = {isa = PBXBuildFile; fileRef = 2B7EA6AE2353477000E5184E /* NativeScriptException.h */; };
2BFE22062AC1C93100307752 /* metadata-arm64.bin in Resources */ = {isa = PBXBuildFile; fileRef = 2BFE22052AC1C93100307752 /* metadata-arm64.bin */; };
Expand Down Expand Up @@ -1850,7 +1848,6 @@
files = (
C27E5DB522F3206B00498ED0 /* app in Resources */,
C27E5DBA22F324C200498ED0 /* [email protected] in Resources */,
2B5088A62BBEB92300F6EB68 /* metadata-arm64.bin in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -2290,7 +2287,6 @@
};
C293752B229FC4740075CB16 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
platformFilter = ios;
target = C29374E1229FC0F60075CB16 /* TestFixtures */;
targetProxy = C293752A229FC4740075CB16 /* PBXContainerItemProxy */;
};
Expand Down Expand Up @@ -2384,6 +2380,7 @@
C23992CE236C2D6E00D2F720 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = NO;
CLANG_ENABLE_MODULES = NO;
CODE_SIGN_STYLE = Automatic;
Expand All @@ -2399,6 +2396,8 @@
);
PRODUCT_BUNDLE_IDENTIFIER = org.nativescript.TestRunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "xrsimulator xros iphonesimulator iphoneos";
SUPPORTS_MACCATALYST = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
Expand All @@ -2410,6 +2409,7 @@
C23992CF236C2D6E00D2F720 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = NO;
CLANG_ENABLE_MODULES = NO;
CODE_SIGN_STYLE = Automatic;
Expand All @@ -2425,6 +2425,8 @@
);
PRODUCT_BUNDLE_IDENTIFIER = org.nativescript.TestRunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "xrsimulator xros iphonesimulator iphoneos";
SUPPORTS_MACCATALYST = YES;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_VERSION = 5.0;
Expand Down Expand Up @@ -2557,6 +2559,7 @@
C27E5D9F22F31CCC00498ED0 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_CXX_LANGUAGE_STANDARD = "compiler-default";
CLANG_CXX_LIBRARY = "compiler-default";
Expand Down Expand Up @@ -2588,13 +2591,16 @@
);
PRODUCT_BUNDLE_IDENTIFIER = org.nativescript.AppWithModules;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "xrsimulator xros iphonesimulator iphoneos";
SUPPORTS_MACCATALYST = YES;
TARGETED_DEVICE_FAMILY = 1;
};
name = Debug;
};
C27E5DA022F31CCC00498ED0 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_CXX_LANGUAGE_STANDARD = "compiler-default";
CLANG_CXX_LIBRARY = "compiler-default";
Expand Down Expand Up @@ -2626,13 +2632,16 @@
);
PRODUCT_BUNDLE_IDENTIFIER = org.nativescript.AppWithModules;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "xrsimulator xros iphonesimulator iphoneos";
SUPPORTS_MACCATALYST = YES;
TARGETED_DEVICE_FAMILY = 1;
};
name = Release;
};
C29374E9229FC0F60075CB16 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
CLANG_ENABLE_MODULES = NO;
CLANG_WARN_STRICT_PROTOTYPES = NO;
DEFINES_MODULE = YES;
Expand All @@ -2641,7 +2650,10 @@
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "xrsimulator xros iphonesimulator iphoneos";
SUPPORTS_MACCATALYST = YES;
SYMROOT = build;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand All @@ -2650,6 +2662,7 @@
C29374EA229FC0F60075CB16 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
CLANG_ENABLE_MODULES = NO;
CLANG_WARN_STRICT_PROTOTYPES = NO;
DEFINES_MODULE = YES;
Expand All @@ -2659,7 +2672,10 @@
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "xrsimulator xros iphonesimulator iphoneos";
SUPPORTS_MACCATALYST = YES;
SYMROOT = build;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down Expand Up @@ -2847,6 +2863,7 @@
__DATA,
__TNSMetadata,
"\"$(SRCROOT)/NativeScript/metadata-arm64.bin\"",
"-w",
);
PRODUCT_BUNDLE_IDENTIFIER = org.nativescript.NativeScript;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
Expand Down Expand Up @@ -2939,6 +2956,7 @@
__DATA,
__TNSMetadata,
"\"$(SRCROOT)/NativeScript/metadata-arm64.bin\"",
"-w",
);
PRODUCT_BUNDLE_IDENTIFIER = org.nativescript.NativeScript;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
Expand Down
Loading