summaryrefslogtreecommitdiff
path: root/xnt/tests/maketests.py
blob: c022b12dbac769e64419b4ad0582ffbdaec82bab (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env python
"""Make (make/ant/nant) Tests Module"""

#   Xnt -- A Wrapper Build Tool
#   Copyright (C) 2013  Kenny Ballou

#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.

#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.

#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest
import xnt
import xnt.build.make
import xnt.tests

@unittest.skipUnless(xnt.in_path("ant") or xnt.in_path("ant.exe"),
                     "Apache ant is not in your path")
class AntTests(unittest.TestCase):
    """Test Case for Ant Build"""
    def setUp(self):
        """Test Setup"""
        xnt.tests.set_up()
        with open("temp/build.xml", "w") as build:
            build.write("<?xml version=\"1.0\" ?>\n")
            build.write("<project name=\"test\" default=\"test\">\n")
            build.write("<target name=\"test\">\n")
            build.write("<echo>${test_var}</echo>\n")
            build.write("</target>\n")
            build.write("</project>\n")

    def tearDown(self):
        """Test Teardown"""
        xnt.tests.tear_down()

    def test_default_build(self):
        """Test the default target of ant"""
        result = xnt.build.make.ant(target="test", path="temp")
        self.assertEqual(result, 0)

    def test_passing_flags(self):
        """Test ant with passing flags"""
        result = xnt.build.make.ant(target="test",
                                    path="temp",
                                    flags=["-verbose"])
        self.assertEqual(result, 0)

    def test_pass_var(self):
        """Test passing variables to ant"""
        result = xnt.build.make.ant(target="test", path="temp",
                                    pkeys=["test_var"],
                                    pvalues=["testing"])
        self.assertEqual(result, 0)

@unittest.skipUnless(xnt.in_path("make"), "make is not in your path")
class MakeTests(unittest.TestCase):
    """GNU Make Tests"""

    def setUp(self):
        """Test Setup"""
        xnt.tests.set_up()
        with open("temp/Makefile", "w") as makefile:
            makefile.write("build:\n")
            makefile.write("\techo 'testing'\n")

    def tearDown(self):
        """Test Teardown"""
        xnt.tests.tear_down()

    def test_default_make(self):
        """Test Default make"""
        result = xnt.build.make.make(target="build", path="temp")
        self.assertEqual(result, 0)

    def test_passing_vars(self):
        """Test Parameter Passing with Make"""
        result = xnt.build.make.make(target="build",
                                     path="temp",
                                     pkeys=["test_var"],
                                     pvalues=["testing"])
        self.assertEqual(result, 0)

    def test_passing_flags(self):
        """Test Flag Passing with Make"""
        result = xnt.build.make.make(target="build",
                                     path="temp",
                                     flags=["-B"])
        self.assertEqual(result, 0)

@unittest.skipUnless(xnt.in_path("nant") or xnt.in_path("nant.exe"),
                     "nant is not in your path")
class NAntTests(unittest.TestCase):
    """.NET Ant Tests"""

    def setUp(self):
        """Test Setup"""
        xnt.tests.set_up()
        with open("temp/default.build", "w") as default_build:
            default_build.write("<?xml version=\"1.0\"?>\n")
            default_build.write("<project name=\"test\">\n")
            default_build.write("<target name=\"test\">\n")
            default_build.write("<if \n")
            default_build.write("test=\"${property::exists('test_var')}\">\n")
            default_build.write("<echo>${test_var}</echo>\n")
            default_build.write("</if>\n")
            default_build.write("</target>\n")
            default_build.write("</project>")

    def tearDown(self):
        """Test Teardown"""
        xnt.tests.tear_down()

    def test_default_nant(self):
        """Test Deault nant"""
        result = xnt.build.make.nant(target="test", path="temp")
        self.assertEqual(result, 0)

    def test_parameters_passing(self):
        """Test Parameter Passing with NAnt"""
        result = xnt.build.make.nant(target="test",
                                     path="temp",
                                     pkeys=["test_var"],
                                     pvalues=["testing"])
        self.assertEqual(result, 0)

    def test_flag_passing(self):
        """Test Flag Passing with NAnt"""
        result = xnt.build.make.nant(target="test",
                                     path="temp",
                                     flags=["-v"])
        self.assertEqual(result, 0)


if __name__ == '__main__':
    unittest.main()