File: test013.py

package info (click to toggle)
aap 1.072-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,980 kB
  • ctags: 2,160
  • sloc: python: 15,113; makefile: 61; sh: 31
file content (82 lines) | stat: -rw-r--r-- 1,782 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Part of the A-A-P recipe executive: Testing of :produce

# Copyright (C) 2002-2003 Stichting NLnet Labs
# Permission to copy and use this file is specified in the file COPYING.
# If this file is missing you can find it here: http://www.a-a-p.org/COPYING

#
# Note: this requires a working C compiler
#

import sys, os, shutil, glob

def runaap(args):
    return os.system("%s ..%sMain.py %s" % (sys.argv[1], os.sep, args))

os.chdir("rectest")

# Create a recipe with a different filetype for the target, so that a different
# build action will be used.
# Check that the right action is used.
rec = "rectest.aap"
inp = "rectest.c"
prog = "rectestprog"
myprog = "myrectestprog.exe"
out = "rectest.out"

msg = "Building %s done." % myprog

def cleanup():
    for file in [ rec, inp, prog, out, myprog ]:
	try:
	    os.remove(file)
	except:
	    pass
    try:
	for dir in glob.glob('build-*'):
	    shutil.rmtree(dir)
    except:
	pass

cleanup()

f = open(rec, "w")
f.write("""
targetattr = {targetsuffix = .exe} {targetprefix = my}
                    {buildaction = dobuild}
:produce myproggy {objectsuffix = $OBJSUF} {objecttype = object}
    $targetattr %s : %s
:action dobuild myproggy object
    :do build {filetype = program} $source
    :print Building $-target done.
""" % (prog, inp))
f.close()

f = open(inp, "w")
f.write("""
#include <stdio.h>
int main() { printf("Hello World!\\n"); return 0;}
""")
f.close()

def doit(text):
    res = runaap("-f %s" % rec)
    f = open("AAPDIR/log")
    actual = f.read()
    f.close()

    import string
    if string.find(actual, text) < 0:
	res = 1
        print 'Did not find remark in log file: "%s"' % text
    return res

# Compile the program.
res = doit(msg)

cleanup()

sys.exit(res)


# vim: set sw=4 et sts=4 tw=79 fo+=l: