about summary refs log tree commit diff
path: root/tests/run-make/return-non-c-like-enum-from-c
diff options
context:
space:
mode:
authorJoshua Nelson <github@jyn.dev>2023-03-30 07:34:55 -0500
committerJoshua Nelson <github@jyn.dev>2023-03-30 07:34:55 -0500
commit433da1fc047bb39a263eefca4bdb2b1972f1d2ce (patch)
tree28540e78fdd5fdf158267e67495121ac64f0866a /tests/run-make/return-non-c-like-enum-from-c
parentf2d9a3d0771504f1ae776226a5799dcb4408a91a (diff)
downloadrust-433da1fc047bb39a263eefca4bdb2b1972f1d2ce.tar.gz
rust-433da1fc047bb39a263eefca4bdb2b1972f1d2ce.zip
Move almost all run-make-fulldeps to run-make
They pass fine.
Diffstat (limited to 'tests/run-make/return-non-c-like-enum-from-c')
-rw-r--r--tests/run-make/return-non-c-like-enum-from-c/Makefile5
-rw-r--r--tests/run-make/return-non-c-like-enum-from-c/nonclike.rs31
-rw-r--r--tests/run-make/return-non-c-like-enum-from-c/test.c61
3 files changed, 97 insertions, 0 deletions
diff --git a/tests/run-make/return-non-c-like-enum-from-c/Makefile b/tests/run-make/return-non-c-like-enum-from-c/Makefile
new file mode 100644
index 00000000000..42d3c977f75
--- /dev/null
+++ b/tests/run-make/return-non-c-like-enum-from-c/Makefile
@@ -0,0 +1,5 @@
+include ../tools.mk
+
+all: $(call NATIVE_STATICLIB,test)
+	$(RUSTC) nonclike.rs -L$(TMPDIR) -ltest
+	$(call RUN,nonclike)
diff --git a/tests/run-make/return-non-c-like-enum-from-c/nonclike.rs b/tests/run-make/return-non-c-like-enum-from-c/nonclike.rs
new file mode 100644
index 00000000000..ea22a2a56e0
--- /dev/null
+++ b/tests/run-make/return-non-c-like-enum-from-c/nonclike.rs
@@ -0,0 +1,31 @@
+#[repr(C, u8)]
+pub enum TT {
+    AA(u64, u64),
+    BB,
+}
+
+#[repr(C,u8)]
+pub enum T {
+    A(u64),
+    B,
+}
+
+extern "C" {
+    pub fn t_new(a: u64) -> T;
+    pub fn tt_new(a: u64, b: u64) -> TT;
+}
+
+fn main() {
+    if let TT::AA(a, b) = unsafe { tt_new(10, 11) } {
+        assert_eq!(10, a);
+        assert_eq!(11, b);
+    } else {
+        panic!("expected TT::AA");
+    }
+
+    if let T::A(a) = unsafe { t_new(10) } {
+        assert_eq!(10, a);
+    } else {
+        panic!("expected T::A");
+    }
+}
diff --git a/tests/run-make/return-non-c-like-enum-from-c/test.c b/tests/run-make/return-non-c-like-enum-from-c/test.c
new file mode 100644
index 00000000000..3ad135bab4a
--- /dev/null
+++ b/tests/run-make/return-non-c-like-enum-from-c/test.c
@@ -0,0 +1,61 @@
+#include <stdint.h>
+
+/* This is the code generated by cbindgen 0.12.1 for the `enum TT`
+ * type in nonclike.rs . */
+enum TT_Tag {
+  AA,
+  BB,
+};
+typedef uint8_t TT_Tag;
+
+typedef struct {
+  uint64_t _0;
+  uint64_t _1;
+} AA_Body;
+
+typedef struct {
+  TT_Tag tag;
+  union {
+    AA_Body aa;
+  };
+} TT;
+
+/* This is the code generated by cbindgen 0.12.1 for the `enum T` type
+ * in nonclike.rs . */
+enum T_Tag {
+  A,
+  B,
+};
+typedef uint8_t T_Tag;
+
+typedef struct {
+  uint64_t _0;
+} A_Body;
+
+typedef struct {
+  T_Tag tag;
+  union {
+    A_Body a;
+  };
+} T;
+
+TT tt_new(uint64_t a, uint64_t b) {
+  TT tt = {
+    .tag = AA,
+    .aa = {
+      ._0 = a,
+      ._1 = b,
+    },
+  };
+  return tt;
+}
+
+T t_new(uint64_t a) {
+  T t = {
+    .tag = A,
+    .a = {
+      ._0 = a,
+    },
+  };
+  return t;
+}