diff options
Diffstat (limited to '')
-rw-r--r-- | tests/test/cpp/preprocessor2.scm | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/tests/test/cpp/preprocessor2.scm b/tests/test/cpp/preprocessor2.scm index 1df1a621..7fcaaccb 100644 --- a/tests/test/cpp/preprocessor2.scm +++ b/tests/test/cpp/preprocessor2.scm @@ -6,6 +6,7 @@ :use-module (srfi srfi-88) :use-module ((hnh util) :select (-> unval)) :use-module ((hnh util lens) :select (set)) + :use-module ((hnh util io) :select (call-with-tmpfile)) :use-module (c preprocessor2) :use-module ((c cpp-environment) :select (extend-environment @@ -47,7 +48,7 @@ "Example 3")) ;; TODO # if (and # elif) aren't yet implemented -(test-skip (test-match-group "Conditionals" "if")) +;; (test-skip (test-match-group "Conditionals" "if")) (define apply-macro (@@ (c preprocessor2) apply-macro)) (define build-parameter-map (@@ (c preprocessor2) build-parameter-map)) @@ -82,13 +83,12 @@ (drop-whitespace-both (remove-noexpand tokens)))) (define (call-with-tmp-header string proc) - (let* ((filename (string-copy "/tmp/headerfile-XXXXXXX")) - (port (mkstemp! filename))) - (with-output-to-port port - (lambda () (display string) - )) - (close-port port) - (proc filename))) + (proc + (call-with-tmpfile + (lambda (port filename) + (display string port) + filename) + tmpl: "/tmp/headerfile-XXXXXXX"))) @@ -554,19 +554,6 @@ body: (lex "x * 2")))) (lex "f(10, 20) + 30")))))) -(let ((e (extend-environment - (make-environment) - (list (@ (c preprocessor2) defined-macro))))) - (test-group "defined() macro" - (test-equal "defined(NOT_DEFINED)" - (lex "0") (remove-noexpand ((unval resolve-token-stream 1) e (lex "defined(X)")))) - (test-equal "defined(DEFINED)" - (lex "1") (remove-noexpand ((unval resolve-token-stream 1) - (extend-environment - e (list (object-like-macro identifier: "X" - body: (lex "10")))) - (lex "defined(X)")))))) - (let ((env (resolve-define (make-environment) (lex "f(x) x+1")))) @@ -1243,5 +1230,24 @@ a b #endif")) + + (test-group "defined without parenthesis" + (test-equal "negative" + (lex "b") + (run "#if defined X +a +#else +b +#endif")) + + (test-equal "positive" + (lex "a") + (run "#define X +#if defined X +a +#else +b +#endif"))) + ;; TODO test advanced constant expression )) |