2
0
mirror of https://gitlab.com/ita1024/waf.git synced 2024-11-17 23:46:53 +01:00

re-added the tests from waf 1.5

This commit is contained in:
Thomas Nagy 2012-03-10 09:03:41 +01:00
parent 5aee9e74a8
commit e978907d6b
10 changed files with 186 additions and 0 deletions

1
tests/preproc/src/a.h Normal file
View File

@ -0,0 +1 @@
#warning "a"

0
tests/preproc/src/b.h Normal file
View File

0
tests/preproc/src/c.h Normal file
View File

0
tests/preproc/src/d.h Normal file
View File

1
tests/preproc/src/e.h Normal file
View File

@ -0,0 +1 @@
#warning "e"

0
tests/preproc/src/f.h Normal file
View File

0
tests/preproc/src/g.h Normal file
View File

0
tests/preproc/src/h.h Normal file
View File

42
tests/preproc/src/main.c Normal file
View File

@ -0,0 +1,42 @@
#if A
#if B
#if C
#include "a.h"
#else
#include "b.h"
#endif
#else
#if C
#include "c.h"
#else
#include "d.h"
#endif
#endif
#elif B
#if C
# if 1 - 1
#include "a.h"
# endif
# if 0
#include "a.h"
# endif
#include <e.h>
#else
#include "f.h"
#endif
#elif C
#include "g.h"
#else
#include "h.h"
#endif
/*
#include "a.h"
*/
//#include "a.h"
int main() {
return 0;
}

142
tests/preproc/wscript Normal file
View File

@ -0,0 +1,142 @@
#! /usr/bin/env python
# encoding: utf-8
# Thomas Nagy, 2012 (ita)
VERSION='0.0.1'
APPNAME='preproc_test'
top = '.'
out = 'build'
from waflib import Utils
from waflib.Tools import c_preproc
from waflib.Tools.c_preproc import NUM, OP, IDENT
from waflib.Logs import pprint
def configure(conf):
pass
def trimquotes(s):
if not s: return ''
s = s.rstrip()
if s[0] == "'" and s[-1] == "'": return s[1:-1]
return s
def build(bld):
defs = {
'm1' : "m1 9 + 9",
'fun0' : "fun0(x, y) x y",
'fun1' : "fun1(x, y) x ## y",
'fun2' : "fun2(x) #x",
'fun3' : "fun3(x, y) x * y",
'fun4' : "fun4(x) fun2(x)",
'fun5' : "fun5(x, y, z) x ## y ## z",
'fun6' : "fun6(x, y) <x.y>",
'fun7' : "fun() 7",
}
def test(x, result, fun=c_preproc.reduce_tokens):
toks = c_preproc.tokenize(x)
c_preproc.reduce_tokens(toks, defs, [])
ret = c_preproc.stringize(toks)
if ret == result:
color = "GREEN"
else:
color = "RED"
pprint(color, "%s\t\t%r" % (ret, toks))
test("1 + m1 + 1", "1+9+9+1")
test("1 + fun0(1, +) 1", "1+1+1")
test("fun2(mmm)", "mmm")
test("m1", "9+9")
test("fun2(m1)", "m1")
test("fun4(m1)", "9+9")
test("fun1(m, m)", "mm")
test("fun5(a, b, c)", "abc")
test("fun1(>, =)", ">=")
test("fun1(a, 12)", "a12")
test("fun5(a, _, 12)", "a_12")
test("fun6(math, h)", "<math.h>")
def test(x, result):
ret = c_preproc.extract_include(x, defs)
if ret == result:
color = "GREEN"
else:
color = "RED"
pprint(color, "%s" % (ret))
test("fun6(math, h)", "math.h")
def test(x, result):
toks = c_preproc.tokenize(x)
c_preproc.reduce_tokens(toks, defs, [])
(_, ret) = c_preproc.reduce_eval(toks)
if int(ret) == result:
color = "GREEN"
else:
color = "RED"
pprint(color, "%s\t\t%r" % (ret, toks))
test("1+1", 2)
test("1-1", 0)
test("1?77:0", 77)
test("0?0:88", 88)
test("1+2*3", 7)
test("1*2+3", 5)
test("7*m1*3", 90)
test("m1*3", 36)
test("defined m1", 1)
test("defined(m1)", 1)
test("defined inex", 0)
test("defined(inex)", 0)
test("fun7()", 7)
test("0&&2<3", 0)
test("(5>1)*6", 6)
test("1,2,3*9,9", 9)
test("0x52 > 02", 1)
# lazy evaluation
test("defined(foo) && foo > 2", 0)
test("defined(m1) && m1 > 20", 0)
test("defined(m1) || m1 > 20", 1)
# undefined macros -> 0
test("not_possibly_defined || another", 0)
test("1+2+((3+4)+5)+6==(6*7)/2==1*-1*-1", 1)
def add_defs(a, b, c, expected):
main = bld.path.find_resource('src/main.c')
defs = ['A=%d' % a, 'B=%d' % b, 'C=%d' % c]
bld.env['DEFLINES'] = ["%s %s" %(x[0], trimquotes('='.join(x[1:]))) for x in [y.split('=') for y in defs]]
gruik = c_preproc.c_parser([main.parent])
gruik.start(main, bld.env)
if len(gruik.nodes) == 1 and gruik.nodes[0].name == expected:
color = "GREEN"
else:
color = "RED"
pprint(color, "%r %r %r -> header %s (got %r)" % (a, b, c, expected, gruik.nodes))
add_defs(1, 1, 1, 'a.h')
add_defs(1, 1, 0, 'b.h')
add_defs(1, 0, 1, 'c.h')
add_defs(1, 0, 0, 'd.h')
add_defs(0, 1, 1, 'e.h')
add_defs(0, 1, 0, 'f.h')
add_defs(0, 0, 1, 'g.h')
add_defs(0, 0, 0, 'h.h')
return
test("1?1,(0?5:9):3,4", 0) # <- invalid expression