Browse Source

Add tests for constructors and destructors

Tibor Nagy 6 years ago
parent
commit
aee3f68117

+ 2 - 0
tests/Makefile

@@ -3,7 +3,9 @@ EXPECT_BINS=\
 	args \
 	arpainet \
 	assert \
+	constructor \
 	ctype \
+	destructor \
 	dirent/scandir \
 	error \
 	fcntl/create \

+ 21 - 0
tests/constructor.c

@@ -0,0 +1,21 @@
+#include <stdio.h>
+
+__attribute__((constructor))
+void constructor_no_priority(void) {
+    puts("constructor (no priority)");
+}
+
+#define TEST(__priority)                           \
+    __attribute__((constructor(__priority)))       \
+    void constructor_priority_##__priority(void) { \
+        puts("constructor ("#__priority")");       \
+    }
+
+TEST(101);
+TEST(102);
+TEST(103);
+TEST(104);
+
+int main(int argc, char *argv[]) {
+    puts("main");
+}

+ 21 - 0
tests/destructor.c

@@ -0,0 +1,21 @@
+#include <stdio.h>
+
+__attribute__((destructor))
+void destructor_no_priority(void) {
+    puts("destructor (no priority)");
+}
+
+#define TEST(__priority)                          \
+    __attribute__((destructor(__priority)))       \
+    void destructor_priority_##__priority(void) { \
+        puts("destructor ("#__priority")");       \
+    }
+
+TEST(101);
+TEST(102);
+TEST(103);
+TEST(104);
+
+int main(int argc, char *argv[]) {
+    puts("main");
+}

+ 0 - 0
tests/expected/constructor.stderr


+ 6 - 0
tests/expected/constructor.stdout

@@ -0,0 +1,6 @@
+constructor (101)
+constructor (102)
+constructor (103)
+constructor (104)
+constructor (no priority)
+main

+ 0 - 0
tests/expected/destructor.stderr


+ 6 - 0
tests/expected/destructor.stdout

@@ -0,0 +1,6 @@
+main
+destructor (no priority)
+destructor (104)
+destructor (103)
+destructor (102)
+destructor (101)