aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-07-13 12:46:52 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2022-07-13 12:46:52 +0200
commitf0ee448af4b2a49a178be89ea4ddaa1eb71a548a (patch)
treedf7717b8ed78b1fd50e9793434240d3a4392c034
parentClearen conditional status predicates. (diff)
downloadcalp-f0ee448af4b2a49a178be89ea4ddaa1eb71a548a.tar.gz
calp-f0ee448af4b2a49a178be89ea4ddaa1eb71a548a.tar.xz
Misc tests.
-rw-r--r--tests/test/cpp/preprocessor2.scm110
1 files changed, 106 insertions, 4 deletions
diff --git a/tests/test/cpp/preprocessor2.scm b/tests/test/cpp/preprocessor2.scm
index b4825907..9f308c9e 100644
--- a/tests/test/cpp/preprocessor2.scm
+++ b/tests/test/cpp/preprocessor2.scm
@@ -46,6 +46,9 @@
"6.10.3.5 Scope of macro definitions"
"Example 3"))
+;; TODO # if (and # elif) aren't yet implemented
+(test-skip (test-match-group "Conditionals" "if"))
+
(define apply-macro (@@ (c preprocessor2) apply-macro))
(define build-parameter-map (@@ (c preprocessor2) build-parameter-map))
(define expand# (@@ (c preprocessor2) expand#))
@@ -760,6 +763,10 @@ X
'cpp-error-directive
(run "#error anything goes here"))
+(test-error "#error without body"
+ 'cpp-error-directive
+ (run "#error"))
+
(test-group "Pragma"
(test-group "#pragma"
(test-equal "#Pragma STDC FP_CONTRACT ON"
@@ -979,6 +986,19 @@ report(x>y, \"x is %d but y is %d\", x, y);
"))))
+(test-group "Misc"
+ (test-equal "Null directive"
+ (lex "1\n2")
+ (run "
+1
+#
+2"))
+
+ (test-error "Invalid directive"
+ 'cpp-error
+ (run "# invalid"))
+ )
+
(test-group "Conditionals"
(test-group "ifdef"
@@ -1033,8 +1053,90 @@ x
2
#endif")))
-;; TODO
-;; if
-;; elif
+ (test-assert "Pre-processing directives are ignored in non-active paths"
+ (run "
+#ifdef X
+#error
+#endif"))
- )
+ ;; Should hold for all tokens, but _Pragma is the only one with observable
+ ;; side effects
+ (test-equal "Tokens aren't expanded in non-active paths"
+ ""
+ (with-output-to-string
+ (lambda ()
+ (run "
+#ifdef X
+_Pragma(\"not-called\")
+#endif"))))
+
+
+ (test-group "Nested conditions"
+ 'TODO)
+
+ (test-group "Unexpected if ends"
+ (test-error "#else outside if"
+ 'cpp-error (run "#else"))
+ (test-error "#endif outside if"
+ 'cpp-error (run "#endif"))
+ (test-error "#elif outside if"
+ 'cpp-error (run "#elif")))
+
+ (test-group "if"
+ (test-equal "Simple positive if"
+ (lex "x")
+ (run "
+#if 1
+x
+#endif"))
+
+ (test-equal "Simple negative if"
+ (lex "")
+ (run "
+#if 0
+x
+#endif"))
+
+ (test-equal "Elif isn't run when if is true"
+ (lex "a")
+ (run "
+#if 1
+a
+#elif 1
+b
+#endif"))
+
+ (test-equal "elif is run when if is false"
+ (lex "b")
+ (run "
+#if 0
+a
+#elif 1
+b
+#endif"))
+
+ ;; Note that defined is automatically added to the environment when
+ ;; evaluating #if.
+
+ (test-equal "#if with defined"
+ (lex "a")
+ (run "
+#define X
+#if defined(X)
+a
+#else
+b
+#endif")
+ )
+
+ (test-equal "#if with negative defined"
+ (lex "b")
+ (run "
+#if defined(X)
+a
+#else
+b
+#endif"))
+
+ ;; TODO test advanced constant expression
+ ))