aboutsummaryrefslogtreecommitdiff
path: root/0.8.0/ruby/environment_TEST.rb
blob: 5eba5f79bc0411b74d4ba21786a29f9797bac04b (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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#!/usr/bin/ruby
# vim: set sw=4 sts=4 et tw=80 :

#
# Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
#
# This file is part of the Paludis package manager. Paludis is free software;
# you can redistribute it and/or modify it under the terms of the GNU General
# Public License version 2, as published by the Free Software Foundation.
#
# Paludis 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, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA  02111-1307  USA
#

ENV["PALUDIS_HOME"] = Dir.getwd().to_s + "/environment_TEST_dir/home";

require 'test/unit'
require 'Paludis'

Paludis::Log.instance.log_level = Paludis::LogLevel::Warning

class Paludis

    class TestCase_DefaultEnvironment < Test::Unit::TestCase
        def test_instance
            assert_equal DefaultEnvironment.instance.__id__, DefaultEnvironment.instance.__id__
            assert_kind_of Environment, DefaultEnvironment.instance
            assert_kind_of DefaultEnvironment, DefaultEnvironment.instance
        end

        def test_no_create
            assert_raise NoMethodError do
                x = DefaultEnvironment.new()
            end
        end
    end

    class TestCase_NoConfigEnvironment < Test::Unit::TestCase
        def test_create
            e = NoConfigEnvironment.new(Dir.getwd().to_s + "/environment_TEST_dir/testrepo")
            assert_kind_of Environment, e
            assert_kind_of NoConfigEnvironment, e

            e = NoConfigEnvironment.new(Dir.new(Dir.getwd().to_s + "/environment_TEST_dir/testrepo"))
            assert_kind_of Environment, e
            assert_kind_of NoConfigEnvironment, e

            assert_raise TypeError do
                e = NoConfigEnvironment.new(123)
            end
        end
    end

    class TestCase_DefaultEnvironmentUse < Test::Unit::TestCase
        def test_query_use
            assert DefaultEnvironment.instance.query_use("enabled")
            assert ! DefaultEnvironment.instance.query_use("not_enabled")
            assert ! DefaultEnvironment.instance.query_use("sometimes_enabled")

            pde = PackageDatabaseEntry.new("foo/bar", VersionSpec.new("1.0"), "testrepo")

            assert DefaultEnvironment.instance.query_use("enabled", pde)
            assert ! DefaultEnvironment.instance.query_use("not_enabled", pde)
            assert DefaultEnvironment.instance.query_use("sometimes_enabled", pde)
        end

        def test_query_use_bad
            assert_raise ArgumentError do
                DefaultEnvironment.instance.query_use(1, 2, 3)
            end
            assert_raise TypeError do
                DefaultEnvironment.instance.query_use(123)
            end
        end
    end

    class TestCase_NoConfigEnvironmentUse < Test::Unit::TestCase
        def env
            NoConfigEnvironment.new(Dir.getwd().to_s + "/environment_TEST_dir/testrepo")
        end

        def test_query_use
            assert ! env.query_use("foo")
            pde = PackageDatabaseEntry.new("foo/bar", VersionSpec.new("1.0"), "testrepo")
            assert ! env.query_use("foo", pde)
        end

        def test_query_use_bad
            assert_raise ArgumentError do
                env.query_use(1, 2, 3)
            end
            assert_raise TypeError do
                env.query_use(123)
            end
        end
    end

    class TestCase_DefaultEnvironmentAcceptKeyword < Test::Unit::TestCase
        def test_accept_keyword
            assert DefaultEnvironment.instance.accept_keyword("test")
            assert ! DefaultEnvironment.instance.accept_keyword("bad")
            assert ! DefaultEnvironment.instance.accept_keyword("~test")

            pde = PackageDatabaseEntry.new("foo/bar", "1.0", "testrepo")

            assert DefaultEnvironment.instance.accept_keyword("test", pde)
            assert ! DefaultEnvironment.instance.accept_keyword("bad", pde)
            assert DefaultEnvironment.instance.accept_keyword("~test", pde)
        end

        def test_accept_keyword_bad
            assert_raise ArgumentError do
                DefaultEnvironment.instance.accept_keyword(1, 2, 3)
            end
            assert_raise TypeError do
                DefaultEnvironment.instance.accept_keyword(123)
            end
        end
    end

    class TestCase_NoConfigEnvironmentAcceptKeyword < Test::Unit::TestCase
        def env
            NoConfigEnvironment.new(Dir.getwd().to_s + "/environment_TEST_dir/testrepo")
        end

        def test_accept_keyword
            assert env.accept_keyword("test")
            assert ! env.accept_keyword("bad")
            assert ! env.accept_keyword("~test")

            pde = PackageDatabaseEntry.new("foo/bar", "1.0", "testrepo")

            assert env.accept_keyword("test", pde)
            assert ! env.accept_keyword("bad", pde)
            assert ! env.accept_keyword("~test", pde)
        end

        def test_accept_keyword_bad
            assert_raise ArgumentError do
                env.accept_keyword(1, 2, 3)
            end
            assert_raise TypeError do
                env.accept_keyword(123)
            end
        end
    end

    class TestCase_DefaultEnvironmentAcceptLicense < Test::Unit::TestCase
        def test_accept_license
            assert DefaultEnvironment.instance.accept_license("test")

            pde = PackageDatabaseEntry.new("foo/bar", VersionSpec.new("1.0"), "testrepo")

            assert DefaultEnvironment.instance.accept_license("test", pde)
        end

        def test_accept_license_bad
            assert_raise ArgumentError do
                DefaultEnvironment.instance.accept_license(1, 2, 3)
            end
            assert_raise TypeError do
                DefaultEnvironment.instance.accept_license(123)
            end
        end
    end

    class TestCase_NoConfigEnvironmentAcceptLicense < Test::Unit::TestCase
        def env
            NoConfigEnvironment.new(Dir.getwd().to_s + "/environment_TEST_dir/testrepo")
        end

        def test_accept_license
            assert env.accept_license("test")
            pde = PackageDatabaseEntry.new("foo/bar", VersionSpec.new("1.0"), "testrepo")
            assert env.accept_license("test", pde)
        end

        def test_accept_license_bad
            assert_raise ArgumentError do
                env.accept_license(1, 2, 3)
            end
            assert_raise TypeError do
                env.accept_license(123)
            end
        end
    end

    class TestCase_NoConfigEnvironmentMaskReasons < Test::Unit::TestCase
        def env
            NoConfigEnvironment.new(Dir.getwd().to_s + "/environment_TEST_dir/testrepo")
        end

        def test_mask_reasons
            p = PackageDatabaseEntry.new("foo/bar", VersionSpec.new("1.0"), "testrepo")

            m = env.mask_reasons(p)
            assert m.empty?
        end

        def test_mask_reasons_not_empty
            p = PackageDatabaseEntry.new("foo/bar", VersionSpec.new("2.0"), "testrepo")

            m = env.mask_reasons(p)
            assert ! m.empty?
            assert m.include?("keyword")
            assert_equal ["keyword"], m.to_a
        end

        def test_mask_reasons_no_such_repo
            p = PackageDatabaseEntry.new("foo/bar", VersionSpec.new("1.0"), "nosuchrepo")

            assert_raise RuntimeError do
                env.mask_reasons p
            end
        end

        def test_mask_reasons_bad
            assert_raise ArgumentError do
                env.mask_reasons(1, 2)
            end
            assert_raise TypeError do
                env.mask_reasons(123)
            end
        end
    end

    class TestCase_DefaultEnvironmentPackageDatabase < Test::Unit::TestCase
        def db
            DefaultEnvironment.instance.package_database
        end

        def test_package_database
            assert_kind_of PackageDatabase, db
            assert_equal "testrepo", db.fetch_repository("testrepo").name
        end
    end

    class TestCase_NoConfigEnvironmentPackageDatabase < Test::Unit::TestCase
        def env
            NoConfigEnvironment.new(Dir.getwd().to_s + "/environment_TEST_dir/testrepo")
        end

        def db
            env.package_database
        end

        def test_package_database
            assert_kind_of PackageDatabase, db
            assert_equal "testrepo", db.fetch_repository("testrepo").name
        end
    end
end