summaryrefslogtreecommitdiffstats
path: root/src/scons/EnvironmentTests.py
blob: 5c6c151f6c9e16fa28cc580ecdde85b6848bacff (plain)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
__revision__ = "EnivronmentTests.py __REVISION__ __DATE__ __DEVELOPER__"

import sys
import unittest

from scons.Environment import *



built_it = {}

class Builder:
    """A dummy Builder class for testing purposes.  "Building"
    a target is simply setting a value in the dictionary.
    """
    def __init__(self, name = None):
    	self.name = name

    def execute(self, target = None, source = None):
	built_it[target] = 1



class EnvironmentTestCase(unittest.TestCase):

    def test_Builders(self):
	"""Test the ability to execute simple builders through
	different environment, one initialized with a single
	Builder object, one with a list of a single Builder
	object, and one with a list of two Builder objects.
	"""
	global built_it

	b1 = Builder(name = 'builder1')
	b2 = Builder(name = 'builder2')

	built_it = {}
	env1 = Environment(BUILDERS = b1)
	env1.builder1.execute(target = 'out1')
	assert built_it['out1']

	built_it = {}
	env2 = Environment(BUILDERS = [b1])
	env1.builder1.execute(target = 'out1')
	assert built_it['out1']

	built_it = {}
	env3 = Environment(BUILDERS = [b1, b2])
	env3.builder1.execute(target = 'out1')
	env3.builder2.execute(target = 'out2')
	env3.builder1.execute(target = 'out3')
	assert built_it['out1']
	assert built_it['out2']
	assert built_it['out3']

    def test_Command(self):
	pass	# XXX

    def test_Copy(self):
	"""Test the ability to copy a construction Environment.
	Update the copy independently afterwards and check that
	the original remains intact (that is, no dangling
	references point to objects in the copied environment).
	"""
	env1 = Environment(XXX = 'x', YYY = 'y')
	env2 = env1.Copy()
	env1copy = env1.Copy()
	env2.Update(YYY = 'yyy')
	assert env1 != env2
	assert env1 == env1copy

    def test_Dictionary(self):
	"""Test the simple ability to retrieve known construction
	variables from the Dictionary and check for well-known
	defaults that get inserted.
	"""
	env = Environment(XXX = 'x', YYY = 'y')
	assert env.Dictionary['XXX'] == 'x'
	assert env.Dictionary['YYY'] == 'y'
	assert env.Dictionary.has_key('BUILDERS')

    def test_Environment(self):
	"""Test the simple ability to create construction
	Environments.  Create two with identical arguments
	and check that they compare the same.
	"""
	env1 = Environment(XXX = 'x', YYY = 'y')
	env2 = Environment(XXX = 'x', YYY = 'y')
	assert env1 == env2

    def test_Install(self):
	pass	# XXX

    def test_InstallAs(self):
	pass	# XXX

    def test_Scanners(self):
	pass	# XXX

    def test_Update(self):
	"""Test the ability to update a construction Environment
	with new construction variables after it was first created.
	"""
	env1 = Environment(AAA = 'a', BBB = 'b')
	env1.Update(BBB = 'bbb', CCC = 'ccc')
	env2 = Environment(AAA = 'a', BBB = 'bbb', CCC = 'c')
	assert env1 != env2

    def test_subst(self):
	"""Test the ability to substitute construction variables
	into a string.  Check various combinations, including
	recursive expansion of variables into other variables.
	"""
	env = Environment(AAA = 'a', BBB = 'b')
	str = env.subst("%AAA %{AAA}A %BBBB %BBB")
	assert str == "a aA  b", str
	env = Environment(AAA = '%BBB', BBB = 'b', BBBA = 'foo')
	str = env.subst("%AAA %{AAA}A %{AAA}B %BBB")
	assert str == "b foo  b", str
	env = Environment(AAA = '%BBB', BBB = '%CCC', CCC = 'c')
	str = env.subst("%AAA %{AAA}A %{AAA}B %BBB")
	assert str == "c   c", str



if __name__ == "__main__":
    suite = unittest.makeSuite(EnvironmentTestCase, 'test_')
    if not unittest.TextTestRunner().run(suite).wasSuccessful():
	sys.exit(1)