aboutsummaryrefslogtreecommitdiff
path: root/paludis/dep_spec_TEST.cc
blob: 7a50d8d936c4886e5842239f2d89de98d8719e2b (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
260
261
262
263
264
265
266
267
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2006, 2007 Ciaran McCreesh
 *
 * 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
 */

#include <paludis/dep_spec.hh>
#include <paludis/util/clone-impl.hh>
#include <paludis/util/sequence.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/util/iterator_funcs.hh>
#include <paludis/util/options.hh>
#include <paludis/util/visitor_cast.hh>
#include <paludis/util/visitor-impl.hh>
#include <paludis/version_requirements.hh>
#include <paludis/use_requirements.hh>
#include <test/test_framework.hh>
#include <test/test_runner.hh>

using namespace paludis;
using namespace test;

namespace test_cases
{
    struct DepSpecAsTest : TestCase
    {
        DepSpecAsTest() : TestCase("dep spec as") { }

        void run()
        {
            tr1::shared_ptr<PackageDepSpec> x(new PackageDepSpec(parse_user_package_dep_spec("foo/bar", UserPackageDepSpecOptions())));
            TEST_CHECK(0 == x->as_use_dep_spec());

            tr1::shared_ptr<UseDepSpec> y(new UseDepSpec(UseFlagName("foo"), x));
            TEST_CHECK(0 != y->as_use_dep_spec());
            TEST_CHECK(y.get() == y->as_use_dep_spec());
        }
    } test_dep_spec_as;

    struct PackageDepSpecTest : TestCase
    {
        PackageDepSpecTest() : TestCase("package dep spec") { }

        void run()
        {
            PackageDepSpec a(parse_user_package_dep_spec("foo/bar", UserPackageDepSpecOptions()));
            TEST_CHECK_STRINGIFY_EQUAL(a, "foo/bar");
            TEST_CHECK_STRINGIFY_EQUAL(*a.package_ptr(), "foo/bar");
            TEST_CHECK(! a.slot_ptr());
            TEST_CHECK(! a.version_requirements_ptr());

            PackageDepSpec b(parse_user_package_dep_spec(">=foo/bar-1.2.3", UserPackageDepSpecOptions()));
            TEST_CHECK_STRINGIFY_EQUAL(b, ">=foo/bar-1.2.3");
            TEST_CHECK_STRINGIFY_EQUAL(*b.package_ptr(), "foo/bar");
            TEST_CHECK(! b.slot_ptr());
            TEST_CHECK(b.version_requirements_ptr());
            TEST_CHECK_EQUAL(std::distance(b.version_requirements_ptr()->begin(),
                        b.version_requirements_ptr()->end()), 1);
            TEST_CHECK_STRINGIFY_EQUAL(b.version_requirements_ptr()->begin()->version_spec, "1.2.3");
            TEST_CHECK_EQUAL(b.version_requirements_ptr()->begin()->version_operator, vo_greater_equal);

            PackageDepSpec c(parse_user_package_dep_spec("foo/bar:baz", UserPackageDepSpecOptions()));
            TEST_CHECK_STRINGIFY_EQUAL(c, "foo/bar:baz");
            TEST_CHECK_STRINGIFY_EQUAL(*c.package_ptr(), "foo/bar");
            TEST_CHECK(c.slot_ptr());
            TEST_CHECK_STRINGIFY_EQUAL(*c.slot_ptr(), "baz");
            TEST_CHECK(! c.version_requirements_ptr());

            PackageDepSpec d(parse_user_package_dep_spec("=foo/bar-1.2*:1.2.1", UserPackageDepSpecOptions()));
            TEST_CHECK_STRINGIFY_EQUAL(d, "=foo/bar-1.2*:1.2.1");
            TEST_CHECK_STRINGIFY_EQUAL(*d.package_ptr(), "foo/bar");
            TEST_CHECK(d.slot_ptr());
            TEST_CHECK_STRINGIFY_EQUAL(*d.slot_ptr(), "1.2.1");
            TEST_CHECK(d.version_requirements_ptr());
            TEST_CHECK_STRINGIFY_EQUAL(d.version_requirements_ptr()->begin()->version_spec, "1.2");
            TEST_CHECK_EQUAL(d.version_requirements_ptr()->begin()->version_operator, vo_equal_star);

            PackageDepSpec e(parse_user_package_dep_spec("foo/bar:1.2.1", UserPackageDepSpecOptions()));
            TEST_CHECK_STRINGIFY_EQUAL(e, "foo/bar:1.2.1");
            TEST_CHECK_STRINGIFY_EQUAL(*e.package_ptr(), "foo/bar");
            TEST_CHECK(e.slot_ptr());
            TEST_CHECK_STRINGIFY_EQUAL(*e.slot_ptr(), "1.2.1");
            TEST_CHECK(! e.version_requirements_ptr());

            PackageDepSpec f(parse_user_package_dep_spec("foo/bar:0", UserPackageDepSpecOptions()));
            TEST_CHECK_STRINGIFY_EQUAL(f, "foo/bar:0");
            TEST_CHECK_STRINGIFY_EQUAL(*f.package_ptr(), "foo/bar");
            TEST_CHECK(f.slot_ptr());
            TEST_CHECK_STRINGIFY_EQUAL(*f.slot_ptr(), "0");
            TEST_CHECK(! f.version_requirements_ptr());

            PackageDepSpec g(parse_user_package_dep_spec("foo/bar-100dpi", UserPackageDepSpecOptions()));
            TEST_CHECK_STRINGIFY_EQUAL(g, "foo/bar-100dpi");
            TEST_CHECK_STRINGIFY_EQUAL(*g.package_ptr(), "foo/bar-100dpi");

            PackageDepSpec h(parse_user_package_dep_spec(">=foo/bar-100dpi-1.23", UserPackageDepSpecOptions()));
            TEST_CHECK_STRINGIFY_EQUAL(h, ">=foo/bar-100dpi-1.23");
            TEST_CHECK_STRINGIFY_EQUAL(*h.package_ptr(), "foo/bar-100dpi");
            TEST_CHECK(h.version_requirements_ptr());
            TEST_CHECK_STRINGIFY_EQUAL(h.version_requirements_ptr()->begin()->version_spec, "1.23");
            TEST_CHECK_EQUAL(h.version_requirements_ptr()->begin()->version_operator, vo_greater_equal);

            TEST_CHECK_THROWS(parse_user_package_dep_spec("", UserPackageDepSpecOptions()), PackageDepSpecError);
            TEST_CHECK_THROWS(parse_user_package_dep_spec("=foo/bar-1.2[=1.3]", UserPackageDepSpecOptions()), PackageDepSpecError);

            PackageDepSpec i(parse_user_package_dep_spec("foo/bar[one][-two]", UserPackageDepSpecOptions()));
            TEST_CHECK_STRINGIFY_EQUAL(i, "foo/bar[-two][one]");
            TEST_CHECK_STRINGIFY_EQUAL(*i.package_ptr(), "foo/bar");
            TEST_CHECK(! i.version_requirements_ptr());
            TEST_CHECK(! i.repository_ptr());
            TEST_CHECK(! i.slot_ptr());
            TEST_CHECK(i.use_requirements_ptr());
            TEST_CHECK(i.use_requirements_ptr()->find(UseFlagName("one")) != i.use_requirements_ptr()->end());
            TEST_CHECK(i.use_requirements_ptr()->find(UseFlagName("two")) != i.use_requirements_ptr()->end());
            TEST_CHECK(i.use_requirements_ptr()->find(UseFlagName("three")) == i.use_requirements_ptr()->end());
            TEST_CHECK(visitor_cast<const EnabledUseRequirement>(**i.use_requirements_ptr()->find(UseFlagName("one"))));
            TEST_CHECK(visitor_cast<const DisabledUseRequirement>(**i.use_requirements_ptr()->find(UseFlagName("two"))));

            PackageDepSpec j(parse_user_package_dep_spec("=foo/bar-scm-r3", UserPackageDepSpecOptions()));
            TEST_CHECK_STRINGIFY_EQUAL(j, "=foo/bar-scm-r3");
            TEST_CHECK_STRINGIFY_EQUAL(*j.package_ptr(), "foo/bar");
            TEST_CHECK(j.version_requirements_ptr());
            TEST_CHECK_STRINGIFY_EQUAL(j.version_requirements_ptr()->begin()->version_spec, "scm-r3");
            TEST_CHECK_EQUAL(j.version_requirements_ptr()->begin()->version_operator, vo_equal);

            PackageDepSpec k(parse_user_package_dep_spec("=foo/bar-scm", UserPackageDepSpecOptions()));
            TEST_CHECK_STRINGIFY_EQUAL(k, "=foo/bar-scm");
            TEST_CHECK_STRINGIFY_EQUAL(*k.package_ptr(), "foo/bar");
            TEST_CHECK(k.version_requirements_ptr());
            TEST_CHECK_STRINGIFY_EQUAL(k.version_requirements_ptr()->begin()->version_spec, "scm");
            TEST_CHECK_EQUAL(k.version_requirements_ptr()->begin()->version_operator, vo_equal);

            PackageDepSpec l(parse_user_package_dep_spec("foo/bar[one][-two][>=1.2&<2.0]", UserPackageDepSpecOptions()));
            TEST_CHECK_STRINGIFY_EQUAL(l, "foo/bar[>=1.2&<2.0][-two][one]");
            TEST_CHECK_STRINGIFY_EQUAL(*l.package_ptr(), "foo/bar");
            TEST_CHECK(l.version_requirements_ptr());
            TEST_CHECK(! l.repository_ptr());
            TEST_CHECK_STRINGIFY_EQUAL(l.version_requirements_ptr()->begin()->version_spec, "1.2");
            TEST_CHECK_EQUAL(l.version_requirements_ptr()->begin()->version_operator, vo_greater_equal);
            TEST_CHECK_STRINGIFY_EQUAL(next(l.version_requirements_ptr()->begin())->version_spec, "2.0");
            TEST_CHECK_EQUAL(next(l.version_requirements_ptr()->begin())->version_operator, vo_less);
            TEST_CHECK(! l.slot_ptr());
            TEST_CHECK(l.use_requirements_ptr());
            TEST_CHECK(l.use_requirements_ptr()->find(UseFlagName("one")) != l.use_requirements_ptr()->end());
            TEST_CHECK(l.use_requirements_ptr()->find(UseFlagName("two")) != l.use_requirements_ptr()->end());
            TEST_CHECK(l.use_requirements_ptr()->find(UseFlagName("three")) == l.use_requirements_ptr()->end());
            TEST_CHECK(visitor_cast<const EnabledUseRequirement>(**l.use_requirements_ptr()->find(UseFlagName("one"))));
            TEST_CHECK(visitor_cast<const DisabledUseRequirement>(**l.use_requirements_ptr()->find(UseFlagName("two"))));

            PackageDepSpec m(parse_user_package_dep_spec("foo/bar[=1.2|=1.3*|~1.4]", UserPackageDepSpecOptions()));
            TEST_CHECK_STRINGIFY_EQUAL(m, "foo/bar[=1.2|=1.3*|~1.4]");
            TEST_CHECK_STRINGIFY_EQUAL(*m.package_ptr(), "foo/bar");
            TEST_CHECK(m.version_requirements_ptr());
            TEST_CHECK(! m.repository_ptr());
            TEST_CHECK_STRINGIFY_EQUAL(m.version_requirements_ptr()->begin()->version_spec, "1.2");
            TEST_CHECK_EQUAL(m.version_requirements_ptr()->begin()->version_operator, vo_equal);
            TEST_CHECK_STRINGIFY_EQUAL(next(m.version_requirements_ptr()->begin())->version_spec, "1.3");
            TEST_CHECK_EQUAL(next(m.version_requirements_ptr()->begin())->version_operator, vo_equal_star);
            TEST_CHECK_STRINGIFY_EQUAL(next(next(m.version_requirements_ptr()->begin()))->version_spec, "1.4");
            TEST_CHECK_EQUAL(next(next(m.version_requirements_ptr()->begin()))->version_operator, vo_tilde);
            TEST_CHECK(! m.slot_ptr());
        }
    } test_package_dep_spec;

    struct FetchableURIDepSpecTest : TestCase
    {
        FetchableURIDepSpecTest() : TestCase("fetchable uri dep spec") { }

        void run()
        {
            FetchableURIDepSpec a("foo");
            TEST_CHECK_EQUAL(a.original_url(), "foo");
            TEST_CHECK_EQUAL(a.renamed_url_suffix(), "");
            TEST_CHECK_EQUAL(a.filename(), "foo");

            FetchableURIDepSpec b("fnord -> bar");
            TEST_CHECK_EQUAL(b.original_url(), "fnord");
            TEST_CHECK_EQUAL(b.renamed_url_suffix(), "bar");
            TEST_CHECK_EQUAL(b.filename(), "bar");

            FetchableURIDepSpec c("http://example.com/download/baz");
            TEST_CHECK_EQUAL(c.filename(), "baz");
        }
    } test_fetchable_uri_dep_spec;

    struct PackageDepSpecUnspecificTest : TestCase
    {
        PackageDepSpecUnspecificTest() : TestCase("package dep spec unspecific") { }

        void run()
        {
            PackageDepSpec a(parse_user_package_dep_spec("*/*", UserPackageDepSpecOptions() + updso_allow_wildcards));
            TEST_CHECK_STRINGIFY_EQUAL(a, "*/*");
            TEST_CHECK(! a.package_ptr());
            TEST_CHECK(! a.package_name_part_ptr());
            TEST_CHECK(! a.category_name_part_ptr());

            PackageDepSpec b(parse_user_package_dep_spec("foo/*", UserPackageDepSpecOptions() + updso_allow_wildcards));
            TEST_CHECK_STRINGIFY_EQUAL(b, "foo/*");
            TEST_CHECK(! b.package_ptr());
            TEST_CHECK(! b.package_name_part_ptr());
            TEST_CHECK(b.category_name_part_ptr());
            TEST_CHECK_EQUAL(*b.category_name_part_ptr(), CategoryNamePart("foo"));

            PackageDepSpec c(parse_user_package_dep_spec("*/foo", UserPackageDepSpecOptions() + updso_allow_wildcards));
            TEST_CHECK_STRINGIFY_EQUAL(c, "*/foo");
            TEST_CHECK(! c.package_ptr());
            TEST_CHECK(c.package_name_part_ptr());
            TEST_CHECK_EQUAL(*c.package_name_part_ptr(), PackageNamePart("foo"));
            TEST_CHECK(! c.category_name_part_ptr());

            PackageDepSpec d(parse_user_package_dep_spec("~*/*-0", UserPackageDepSpecOptions() + updso_allow_wildcards));
            TEST_CHECK_STRINGIFY_EQUAL(d, "~*/*-0");
            TEST_CHECK(! d.package_ptr());
            TEST_CHECK(! d.package_name_part_ptr());
            TEST_CHECK(! d.category_name_part_ptr());

            PackageDepSpec e(parse_user_package_dep_spec(">=foo/*-1.23", UserPackageDepSpecOptions() + updso_allow_wildcards));
            TEST_CHECK_STRINGIFY_EQUAL(e, ">=foo/*-1.23");
            TEST_CHECK(! e.package_ptr());
            TEST_CHECK(! e.package_name_part_ptr());
            TEST_CHECK(e.category_name_part_ptr());
            TEST_CHECK_EQUAL(*e.category_name_part_ptr(), CategoryNamePart("foo"));

            PackageDepSpec f(parse_user_package_dep_spec("=*/foo-1*", UserPackageDepSpecOptions() + updso_allow_wildcards));
            TEST_CHECK_STRINGIFY_EQUAL(f, "=*/foo-1*");
            TEST_CHECK(! f.package_ptr());
            TEST_CHECK(f.package_name_part_ptr());
            TEST_CHECK_EQUAL(*f.package_name_part_ptr(), PackageNamePart("foo"));
            TEST_CHECK(! f.category_name_part_ptr());
        }
    } test_package_dep_spec_unspecific;

    struct DepSpecCloneTest : TestCase
    {
        DepSpecCloneTest() : TestCase("dep spec clone") { }

        void run()
        {
            PackageDepSpec a(parse_user_package_dep_spec("cat/pkg:1::repo[=1|>3.2][foo]", UserPackageDepSpecOptions()));

            tr1::shared_ptr<PackageDepSpec> b(tr1::static_pointer_cast<PackageDepSpec>(a.clone()));
            TEST_CHECK_STRINGIFY_EQUAL(a, *b);

            tr1::shared_ptr<PackageDepSpec> c(tr1::static_pointer_cast<PackageDepSpec>(a.clone()));
            TEST_CHECK_STRINGIFY_EQUAL(a, *c);

            BlockDepSpec d(c);
            tr1::shared_ptr<BlockDepSpec> e(tr1::static_pointer_cast<BlockDepSpec>(d.clone()));
            TEST_CHECK_STRINGIFY_EQUAL(*(d.blocked_spec()), *(e->blocked_spec()));
        }
    } test_dep_spec_clone;
}