shithub: regress

Download patch

ref: 95f77d6b8b48c25f079e8cb2686409896c478cb9
parent: 814dce91ef582a850d1bdc5464cebe1091559b55
author: Ori Bernstein <[email protected]>
date: Fri Jun 19 23:16:43 EDT 2020

Add tests for c preprocessor

diff: cannot open b/cmd/cpp//null: file does not exist: 'b/cmd/cpp//null'
--- /dev/null
+++ b/cmd/cpp/cat.test
@@ -1,0 +1,13 @@
+#define NOP(x) x
+#define CAT(a, b) a ## b
+#define EOF	(-1)
+x NOP(CAT(foo, EOF)) y
+x NOP(CAT(EOF, foo)) y
+x CAT(, EOF) y
+y CAT(foo,) x
+x CAT(,foo) y
+X NOP(CAT(,)) y
+
+#define BAR	3
+#define FOO	CAT(BAR, 3)
+FOO
--- /dev/null
+++ b/cmd/cpp/cat.test.expected
@@ -1,0 +1,14 @@
+#line 1 "/usr/ori/src/regress/cmd/cpp/cat.test"
+
+
+
+x fooEOF y
+x EOFfoo y
+x(-1) y
+y foo x
+x foo y
+X y
+
+
+
+ 33
--- /dev/null
+++ b/cmd/cpp/cpp.rc
@@ -1,0 +1,11 @@
+#!/bin/rc
+
+for(f in *.test){
+	cpp $f > $f.out
+	if(! cmp $f.out $f.expected){
+		>[2=1] echo fail: $f
+		>[2=1] ape/diff $f.out $f.expected
+		exit fail
+	}
+}
+exit ''
--- /dev/null
+++ b/cmd/cpp/smoke.test
@@ -1,0 +1,38 @@
+/*
+ * CURRENTLY BROKEN:
+ *     __VA_ARGS__ requires at least one item.
+ *     It should accept an empty list.
+#define xprint(a, ...)	print(a, __VA_ARGS__)
+xprint("hi", "there")
+xprint("hi")
+*/
+
+#define C	a,b
+#define X(a)	a
+#define Y	X(C)
+Y
+
+#define    x          3
+#define    f(a)       f(x * (a))
+#undef     x
+#define    x          2
+#define    g          f
+#define    z          z[0]
+#define    h          g(~
+#define    m(a)       a(w)
+#define    w          0,1
+#define    t(a)       a
+#define    p()        int
+#define    q(x)       x
+#define    r(x,y)     x ## y
+#define    str(x)     # x
+f(y+1) + f(f(z)) % t(t(g)(0) + t)(1);
+g(x+(3,4)-w) | h 5) & m
+(f)^m(m);
+/*
+ * CURRENTLY BROKEN:
+ *     mac() needs at least one argument.
+ *     It should treat no args as a single empty arg list.
+p() i[q()] = { q(1), r(2,3), r(4,), r(,5), r(,) };
+char c[2][6] = { str(hello), str() };
+*/
--- /dev/null
+++ b/cmd/cpp/smoke.test.expected
@@ -1,0 +1,28 @@
+#line 1 "/usr/ori/src/regress/cmd/cpp/smoke.test"
+
+#line 9 "/usr/ori/src/regress/cmd/cpp/smoke.test"
+
+
+
+
+ a,b
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1);
+ f(2 * (2 +(3,4)- 0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^ m(0,1);
+#line 32 "/usr/ori/src/regress/cmd/cpp/smoke.test"
+
+#line 39 "/usr/ori/src/regress/cmd/cpp/smoke.test"