aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/standalone.zig4
-rw-r--r--test/standalone/objc/Foo.h7
-rw-r--r--test/standalone/objc/Foo.m11
-rw-r--r--test/standalone/objc/build.zig22
-rw-r--r--test/standalone/objc/test.m12
5 files changed, 56 insertions, 0 deletions
diff --git a/test/standalone.zig b/test/standalone.zig
index a483097f4a..52fba31828 100644
--- a/test/standalone.zig
+++ b/test/standalone.zig
@@ -37,6 +37,10 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
if (std.Target.current.os.tag == .linux) {
cases.addBuildFile("test/standalone/pie/build.zig", .{});
}
+ // Try to build and run an Objective-C executable.
+ if (std.Target.current.os.tag == .macos) {
+ cases.addBuildFile("test/standalone/objc/build.zig", .{ .build_modes = true });
+ }
// Ensure the development tools are buildable.
cases.add("tools/gen_spirv_spec.zig");
diff --git a/test/standalone/objc/Foo.h b/test/standalone/objc/Foo.h
new file mode 100644
index 0000000000..05cb7df39b
--- /dev/null
+++ b/test/standalone/objc/Foo.h
@@ -0,0 +1,7 @@
+#import <Foundation/Foundation.h>
+
+@interface Foo : NSObject
+
+- (NSString *)name;
+
+@end
diff --git a/test/standalone/objc/Foo.m b/test/standalone/objc/Foo.m
new file mode 100644
index 0000000000..6fc9b1edf0
--- /dev/null
+++ b/test/standalone/objc/Foo.m
@@ -0,0 +1,11 @@
+#import "Foo.h"
+
+@implementation Foo
+
+- (NSString *)name
+{
+ NSString *str = [[NSString alloc] initWithFormat:@"Zig"];
+ return str;
+}
+
+@end
diff --git a/test/standalone/objc/build.zig b/test/standalone/objc/build.zig
new file mode 100644
index 0000000000..30becd398c
--- /dev/null
+++ b/test/standalone/objc/build.zig
@@ -0,0 +1,22 @@
+const std = @import("std");
+const Builder = std.build.Builder;
+
+pub fn build(b: *Builder) void {
+ const mode = b.standardReleaseOptions();
+ const target = b.standardTargetOptions(.{});
+
+ const test_step = b.step("test", "Test the program");
+
+ const exe = b.addExecutable("test", null);
+ b.default_step.dependOn(&exe.step);
+ exe.addIncludeDir(".");
+ exe.addCSourceFile("Foo.m", &[0][]const u8{});
+ exe.addCSourceFile("test.m", &[0][]const u8{});
+ exe.setBuildMode(mode);
+ exe.setTarget(target);
+ exe.linkLibC();
+ exe.linkFramework("Foundation");
+
+ const run_cmd = exe.run();
+ test_step.dependOn(&run_cmd.step);
+}
diff --git a/test/standalone/objc/test.m b/test/standalone/objc/test.m
new file mode 100644
index 0000000000..3c81316788
--- /dev/null
+++ b/test/standalone/objc/test.m
@@ -0,0 +1,12 @@
+#import "Foo.h"
+#import <assert.h>
+
+int main(int argc, char *argv[])
+{
+ @autoreleasepool {
+ Foo *foo = [[Foo alloc] init];
+ NSString *result = [foo name];
+ assert([result isEqualToString:@"Zig"]);
+ return 0;
+ }
+}