-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_test.go
168 lines (165 loc) · 5.74 KB
/
parse_test.go
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
package main
import (
"fmt"
"reflect"
"strings"
"testing"
)
func TestParseLine(t *testing.T) {
for _, v := range []struct {
fname string
expected []string
}{
{
fname: "testdata/correct_gcc_config_tag.txt",
expected: []string{
"macro", "correct_gcc_config_tag", "i686-slc5-gcc43-opt",
"x86_64", "x86_64-slc5",
},
},
{
fname: "testdata/buggy_gcc_config_tag.txt",
expected: []string{
"macro", "buggy_gcc_config_tag", "i686-slc5-gcc43-opt",
"x86_64", "x86_64-slc5",
},
},
// FIXME!!
{
fname: "testdata/pp_cppflags.txt",
expected: []string{
"macro_append", "pp_cppflags", `-DTDAQ_PACKAGE_NAME="$(package)"`,
},
},
{
fname: "testdata/lib_suffix.txt",
expected: []string{
"macro", "lib_suffix", ".so",
"ppc-rtems-rce405", ".a",
},
},
{
fname: "testdata/app_inst_group.txt",
expected: []string{"macro", "app_inst_group", "inst",
"ppc-rtems-rce405", "____"},
},
{
fname: "testdata/c_opt_flags.txt",
expected: []string{
"macro", "c_opt_flags", "",
"x86_64-slc4&gcc34", "-O2 -mtune=nocona -fomit-frame-pointer -fno-exceptions",
"x86_64-slc4&gcc43", "-O2 -mtune=nocona -fomit-frame-pointer -fno-exceptions",
"x86_64-slc5&gcc43", "-O2 -mtune=nocona -fomit-frame-pointer -fno-exceptions",
"x86_64-slc5&gcc46", "-O2 -mtune=core2 -ftree-vectorize -ftree-vectorizer-verbose=2 -fomit-frame-pointer",
"x86_64-slc6&gcc4", "-O2 -mtune=nocona -fomit-frame-pointer -fno-exceptions",
"gcc32", "-O2 -march=i686 -mcpu=i686 -funroll-loops -falign-loops -falign-jumps -falign-functions -fno-exceptions",
"gcc323", "-O2 -mcpu=pentium4 -funroll-loops -falign-loops -falign-jumps -falign-functions -fno-exceptions",
"i686-slc4&gcc34", "-O2 -mtune=pentium4 -funroll-loops -falign-loops -falign-jumps -falign-functions -fno-exceptions",
"i686-slc4&gcc43", "-O2 -mtune=pentium4 -funroll-loops -falign-loops -falign-jumps -falign-functions -fno-exceptions",
"i686-slc5&gcc4", "-O2 -mtune=pentium4 -funroll-loops -falign-loops -falign-jumps -falign-functions -fno-exceptions",
"i686-slc6&gcc4", "-O2 -mtune=pentium4 -funroll-loops -falign-loops -falign-jumps -falign-functions -fno-exceptions",
"icc8", "-O2 -mtune=pentium4",
"icc11", "-O2 -axSSSE3 -vec-report1 -par-report1 -parallel",
"powerpc-rtems-gcc43", "-O4 -mlongcall -msoft-float",
},
},
{
fname: "testdata/cpp_opt_flags.txt",
expected: []string{
"macro", "cpp_opt_flags", "",
"x86_64-slc4&gcc34", "-O2 -mtune=nocona -fomit-frame-pointer",
"x86_64-slc4&gcc43", "-O2 -mtune=nocona -fomit-frame-pointer",
"x86_64-slc6&gcc46", "-O2 -mtune=core2 -std=c++0x -ftree-vectorize -ftree-vectorizer-verbose=2 -fomit-frame-pointer",
"x86_64-slc6&gcc47", "-O2 -mtune=core2 -std=c++11 -ftree-vectorize -ftree-vectorizer-verbose=2 -fomit-frame-pointer",
"x86_64-slc6&gcc4", "-O2 -mtune=nocona -fomit-frame-pointer",
"x86_64-slc5&gcc43", "-O2 -mtune=nocona -fomit-frame-pointer",
"x86_64-slc5&gcc46", "-O2 -mtune=core2 -std=c++0x -ftree-vectorize -ftree-vectorizer-verbose=2 -fomit-frame-pointer",
"x86_64-slc5&gcc47", "-O2 -mtune=core2 -std=c++11 -ftree-vectorize -ftree-vectorizer-verbose=2 -fomit-frame-pointer",
"gcc32", "-O2 -march=i686 -mcpu=i686 -funroll-loops -falign-loops -falign-jumps -falign-functions",
"gcc323", "-O2 -mcpu=pentium4 -funroll-loops -falign-loops -falign-jumps -falign-functions",
"i686-slc4&gcc34", "-O2 -mtune=pentium4 -funroll-loops -falign-loops -falign-jumps -falign-functions",
"i686-slc4&gcc43", "-O2 -mtune=pentium4 -funroll-loops -falign-loops -falign-jumps -falign-functions",
"i686-slc5&gcc4", "-O2 -mtune=pentium4 -funroll-loops -falign-loops -falign-jumps -falign-functions",
"i686-slc6&gcc4", "-O2 -mtune=pentium4 -funroll-loops -falign-loops -falign-jumps -falign-functions",
"icc8", "-O2 -mtune=pentium4",
"icc11", "-O2 -axSSSE3 -vec-report1 -par-report1 -parallel",
"powerpc-rtems-gcc43", "-O4 -mlongcall -msoft-float",
},
},
{
fname: "testdata/cppappcomp.txt",
expected: []string{
"macro", "cppappcomp", "$(cppcomp)",
"ppc-rtems-rce405", "echo",
},
},
{
fname: "testdata/applytag.txt",
expected: []string{
"apply_tag", "Foo",
},
},
{
fname: "testdata/unittest.txt",
expected: []string{
//FIXME:
//"apply_pattern", "Foo", "name=\"toto was there\"",
"apply_pattern", "Foo", `name="toto was there`,
},
},
{
fname: "testdata/unittest2.txt",
expected: []string{
//FIXME:
//"apply_pattern", "Foo", "name='toto was there'",
"apply_pattern", "Foo", "name='toto was there",
},
},
{
fname: "testdata/unittest3.txt",
expected: []string{
//FIXME:
//"apply_pattern", "Foo", "name=\" toto was there\"",
"apply_pattern", "Foo", "name= toto was there",
},
},
{
fname: "testdata/unittest4.txt",
expected: []string{
//FIXME:
//"apply_pattern", "Foo", "name=' toto was there'",
"apply_pattern", "Foo", "name= toto was there",
},
},
{
fname: "testdata/declare_jobo.txt",
expected: []string{
//FIXME:
//"apply_pattern", "declare_joboptions", "files=\"-s=../share *.py\"",
"apply_pattern", "declare_joboptions", "files=\"-s=../share *.py",
},
},
} {
p, err := NewParser(v.fname)
if err != nil {
t.Fatalf(err.Error())
}
err = p.run()
out := p.tokens
if !reflect.DeepEqual(out, v.expected) {
s_expected := make([]string, 0, len(v.expected))
for _, vv := range v.expected {
s_expected = append(s_expected, fmt.Sprintf("%q", vv))
}
s_out := make([]string, 0, len(out))
for _, vv := range out {
s_out = append(s_out, fmt.Sprintf("%q", vv))
}
t.Fatalf(
"\nexpected: %v\ngot: %v\n",
strings.Join(s_expected, ", "),
strings.Join(s_out, ", "),
)
}
}
}