-
Notifications
You must be signed in to change notification settings - Fork 181
/
macros.t
100 lines (95 loc) · 2.02 KB
/
macros.t
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
#!/usr/bin/perl -w
use strict;
use Test::More tests => 37;
use Build::Rpm;
my @tests = (
q{
%%} => '%',
q{
%{%}} => '%{%}',
q{
%not_defined} => '%not_defined',
q{
%{not_defined}} => '%{not_defined}',
q{
%{}} => '%{}',
q{
%{ test }} => '%{ test }',
q{
%define this that
%{this}} => 'that',
q{
%define this that
%{?this}} => 'that',
q{
%define this that
%{?that}} => '',
q{
%define this that
%{?!this}} => '',
q{
%define this that
%{?!that}} => '',
q{
%define this that
%{?this:foo}} => 'foo',
q{
%define this that
%{?that:foo}} => '',
q{
%define this that
%{?!this:foo}} => '',
q{
%define this that
%{?!that:foo}} => 'foo',
q{
%define this that
%define that_that foo
%{expand:%%{%{this}_that}}} => 'foo',
q{
%define bar() "Bar %#: %{?1} %{?2}"
%define foo() "Foo %#: %{?1} %{?2}" %bar a
%foo 1 2} => '"Foo 2: 1 2" "Bar 1: a "',
q{
%define foo hello" + "world
%["%foo"]} => 'hello" + "world',
q{
%define foo hello
%define bar world
%{foo:%{bar}}} => 'hello',
q{
%define foo hello
%define bar world
%{?foo:%{bar}}} => 'world',
q{%[1 + %[2 * 3]]} => '7',
q{%[0 && %does_not_exist]} => '0',
q{%{shrink: a b c }} => 'a b c',
q{%{expr: 1 + 2}} => '3',
q{%{dirname:foo/bar}} => 'foo',
q{%{basename:foo/bar}} => 'bar',
q{%{dirname:foo}} => 'foo',
q{%{basename:foo}} => 'foo',
q{%{dirname:foo/bar/}} => 'foo/bar',
q{%{basename:foo/bar/}} => '',
q{%{dirname:/}} => '',
q{%{basename:/}} => '',
q{%{dirname}} => '',
q{%{basename}} => '',
q{
%define foo bar
%define baz foo
%{expand:%%%baz}} => 'bar',
q{%{expand %%%%%%%%}} => '%%',
q{
%define foo bar
%{defined:foo}/%{defined:oof}} => '1/0',
);
while (@tests) {
my ($in, $expected) = splice(@tests, 0, 2);
$in =~ s/^\n//s;
my %macros = ( 'nil' => '' );
my %macros_args;
my $actual = '';
$actual .= Build::Rpm::expandmacros({}, $_, undef, \%macros, \%macros_args) for split("\n", $in);
is($actual, $expected, $in);
}