summaryrefslogtreecommitdiffstats
path: root/tests/preprocessor
diff options
context:
space:
mode:
Diffstat (limited to 'tests/preprocessor')
-rw-r--r--tests/preprocessor/pragma-once-a.h6
-rw-r--r--tests/preprocessor/pragma-once-b.h5
-rw-r--r--tests/preprocessor/pragma-once.slang42
3 files changed, 53 insertions, 0 deletions
diff --git a/tests/preprocessor/pragma-once-a.h b/tests/preprocessor/pragma-once-a.h
new file mode 100644
index 000000000..6601919e4
--- /dev/null
+++ b/tests/preprocessor/pragma-once-a.h
@@ -0,0 +1,6 @@
+// pragma-once-a.h
+#pragma once
+
+// Used by the `pragma-once.slang` test
+
+float foo(float x) { return x; }
diff --git a/tests/preprocessor/pragma-once-b.h b/tests/preprocessor/pragma-once-b.h
new file mode 100644
index 000000000..3bb45bd44
--- /dev/null
+++ b/tests/preprocessor/pragma-once-b.h
@@ -0,0 +1,5 @@
+// pragma-once-b.h
+
+// Used by the `pragma-once.slang` test
+
+#define BAR foo
diff --git a/tests/preprocessor/pragma-once.slang b/tests/preprocessor/pragma-once.slang
new file mode 100644
index 000000000..fe805f82f
--- /dev/null
+++ b/tests/preprocessor/pragma-once.slang
@@ -0,0 +1,42 @@
+//TEST(smoke):SIMPLE:
+
+// Test support for `#pragma once`
+
+// We will include two header files:
+// one that uses `#pragma once`, and
+// one that doesn't.
+//
+// The first file defines a function `foo()`,
+// and the second defines a macro `BAR`
+//
+#include "pragma-once-a.h"
+#include "pragma-once-b.h"
+
+// We will include the files again, and
+// before we do so we need to undefine
+// the macro from the second file so
+// that it doesn't get a redefinition diagnostic.
+//
+#undef BAR
+//
+// We don't do anything about the function
+// in the first file, because we expect
+// the `#pragma once` to cause it to be
+// ignored on this second time.
+//
+#include "pragma-once-a.h"
+#include "pragma-once-b.h"
+
+// Now let's use both the function and the
+// macro, to confirm that they are both
+// defined as expected.
+//
+// Note: if we accidentally include file
+// `a.h` more than once, we'd expect to
+// get an error here, because the two
+// function definitions conflict.
+//
+float test(float x)
+{
+ return foo(x) + BAR(x);
+}