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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
|
T.vs2010_vcxproj = { }
local vs10_vcxproj = T.vs2010_vcxproj
local include_directory = "bar/foo"
local include_directory2 = "baz/foo"
local debug_define = "I_AM_ALIVE_NUMBER_FIVE"
local sln, prj
function vs10_vcxproj.setup()
_ACTION = "vs2010"
sln = solution "MySolution"
configurations { "Debug", "Release" }
platforms {}
prj = project "MyProject"
language "C++"
kind "ConsoleApp"
uuid "AE61726D-187C-E440-BD07-2556188A6565"
includedirs
{
include_directory,
include_directory2
}
files
{
"foo/dummyHeader.h",
"foo/dummySource.cpp",
"../src/host/*h",
"../src/host/*.c"
}
configuration("Release")
flags {"Optimize"}
links{"foo","bar"}
configuration("Debug")
defines {debug_define}
links{"foo_d"}
end
local function get_buffer()
io.capture()
premake.buildconfigs()
sln.vstudio_configs = premake.vstudio_buildconfigs(sln)
premake.vs2010_vcxproj(prj)
buffer = io.endcapture()
return buffer
end
function vs10_vcxproj.xmlDeclarationPresent()
buffer = get_buffer()
test.istrue(string.startswith(buffer, '<?xml version=\"1.0\" encoding=\"utf-8\"?>'))
end
function vs10_vcxproj.projectBlocksArePresent()
buffer = get_buffer()
test.string_contains(buffer,'<Project.*</Project>')
end
function vs10_vcxproj.projectOpenTagIsCorrect()
buffer = get_buffer()
test.string_contains(buffer,'<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">.*</Project>')
end
function vs10_vcxproj.configItemGroupPresent()
buffer = get_buffer()
test.string_contains(buffer,'<ItemGroup Label="ProjectConfigurations">.*</ItemGroup>')
end
function vs10_vcxproj.configBlocksArePresent()
buffer = get_buffer()
test.string_contains(buffer,'<ProjectConfiguration.*</ProjectConfiguration>')
end
function vs10_vcxproj.configTypeBlockPresent()
buffer = get_buffer()
test.string_contains(buffer,'<PropertyGroup Condition="\'%$%(Configuration%)|%$%(Platform%)\'==\'.*\'" Label="Configuration">.*</PropertyGroup>')
end
function vs10_vcxproj.twoConfigTypeBlocksPresent()
buffer = get_buffer()
test.string_contains(buffer,'<PropertyGroup Condition.*</PropertyGroup>.*<PropertyGroup Condition=.*</PropertyGroup>')
end
function vs10_vcxproj.propsDefaultForCppProjArePresent()
buffer = get_buffer()
test.string_contains(buffer,'<Import Project="$%(VCTargetsPath%)\\Microsoft.Cpp.Default.props" />')
end
function vs10_vcxproj.propsForCppProjArePresent()
buffer = get_buffer()
test.string_contains(buffer,'<Import Project="%$%(VCTargetsPath%)\\Microsoft.Cpp.props" />')
end
function vs10_vcxproj.extensionSettingArePresent()
buffer = get_buffer()
test.string_contains(buffer,'<ImportGroup Label="ExtensionSettings">.*</ImportGroup>')
end
function vs10_vcxproj.userMacrosPresent()
buffer = get_buffer()
test.string_contains(buffer,'<PropertyGroup Label="UserMacros" />')
end
function vs10_vcxproj.intermediateAndOutDirsPropertyGroupWithMagicNumber()
buffer = get_buffer()
test.string_contains(buffer,'<PropertyGroup>.*<_ProjectFileVersion>10%.0%.30319%.1</_ProjectFileVersion>')
end
function vs10_vcxproj.outDirPresent()
buffer = get_buffer()
test.string_contains(buffer,'<OutDir.*</OutDir>')
end
function vs10_vcxproj.initDirPresent()
buffer = get_buffer()
test.string_contains(buffer,'<IntDir.*</IntDir>')
end
function vs10_vcxproj.projectWithDebugAndReleaseConfig_twoOutDirsAndTwoIntDirs()
buffer = get_buffer()
test.string_contains(buffer,'<OutDir.*</OutDir>.*<IntDir.*</IntDir>.*<OutDir.*</OutDir>.*<IntDir.*</IntDir>')
end
function vs10_vcxproj.containsItemDefinition()
buffer = get_buffer()
test.string_contains(buffer,'<ItemDefinitionGroup Condition="\'%$%(Configuration%)|%$%(Platform%)\'==\'.*\'">.*</ItemDefinitionGroup>')
end
function vs10_vcxproj.containsClCompileBlock()
buffer = get_buffer()
test.string_contains(buffer,'<ClCompile>.*</ClCompile>')
end
function vs10_vcxproj.containsAdditionalOptions()
buildoptions {"/Gm"}
buffer = get_buffer()
test.string_contains(buffer,'<AdditionalOptions>/Gm %%%(AdditionalOptions%)</AdditionalOptions>')
end
local function cl_compile_string(version)
return '<ItemDefinitionGroup Condition="\'%$%(Configuration%)|%$%(Platform%)\'==\''..version..'|Win32\'">.*<ClCompile>'
end
function vs10_vcxproj.debugHasNoOptimisation()
buffer = get_buffer()
test.string_contains(buffer, cl_compile_string('Debug').. '.*<Optimization>Disabled</Optimization>.*</ItemDefinitionGroup>')
end
function vs10_vcxproj.releaseHasFullOptimisation()
buffer = get_buffer()
test.string_contains(buffer, cl_compile_string('Release').. '.*<Optimization>Full</Optimization>.*</ItemDefinitionGroup>')
end
function vs10_vcxproj.includeDirectories_debugEntryContains_include_directory()
buffer = get_buffer()
test.string_contains(buffer,cl_compile_string('Debug').. '.*<AdditionalIncludeDirectories>'.. path.translate(include_directory, '\\') ..'.*</AdditionalIncludeDirectories>')
end
function vs10_vcxproj.includeDirectories_debugEntryContains_include_directory2PrefixWithSemiColon()
buffer = get_buffer()
test.string_contains(buffer,cl_compile_string('Debug').. '.*<AdditionalIncludeDirectories>.*;'.. path.translate(include_directory2, '\\') ..'.*</AdditionalIncludeDirectories>')
end
function vs10_vcxproj.includeDirectories_debugEntryContains_include_directory2PostfixWithSemiColon()
buffer = get_buffer()
test.string_contains(buffer,cl_compile_string('Debug').. '.*<AdditionalIncludeDirectories>.*'.. path.translate(include_directory2, '\\') ..';.*</AdditionalIncludeDirectories>')
end
function vs10_vcxproj.debugContainsPreprossorBlock()
buffer = get_buffer()
test.string_contains(buffer,cl_compile_string('Debug').. '.*<PreprocessorDefinitions>.*</PreprocessorDefinitions>')
end
function vs10_vcxproj.debugHasDebugDefine()
buffer = get_buffer()
test.string_contains(buffer,cl_compile_string('Debug')..'.*<PreprocessorDefinitions>.*'..debug_define..'.*</PreprocessorDefinitions>')
end
function vs10_vcxproj.releaseHasStringPoolingOn()
buffer = get_buffer()
test.string_contains(buffer,cl_compile_string('Release')..'.*<StringPooling>true</StringPooling>')
end
function vs10_vcxproj.hasItemGroupSection()
buffer = get_buffer()
test.string_contains(buffer,'<ItemGroup>.*</ItemGroup>')
end
function vs10_vcxproj.fileExtension_extEqualH()
local ext = get_file_extension('foo.h')
test.isequal('h', ext)
end
function vs10_vcxproj.fileExtension_containsTwoDots_extEqualH()
local ext = get_file_extension('foo.bar.h')
test.isequal('h', ext)
end
function vs10_vcxproj.fileExtension_alphaNumeric_extEqualOneH()
local ext = get_file_extension('foo.1h')
test.isequal('1h', ext)
end
function vs10_vcxproj.fileExtension_alphaNumericWithUnderscore_extEqualOne_H()
local ext = get_file_extension('foo.1_h')
test.isequal('1_h', ext)
end
function vs10_vcxproj.fileExtension_containsHyphen_extEqualHHyphenH()
local ext = get_file_extension('foo.h-h')
test.isequal('h-h', ext)
end
function vs10_vcxproj.fileExtension_containsMoreThanOneDot_extEqualOneH()
local ext = get_file_extension('foo.bar.h')
test.isequal('h', ext)
end
local function SortAndReturnSortedInputFiles(input)
local sorted =
{
ClInclude ={},
ClCompile ={},
None ={}
}
sort_input_files(input,sorted)
return sorted
end
function vs10_vcxproj.sortFile_headerFile_SortedClIncludeEqualToFile()
local file = {"bar.h"}
local sorted = SortAndReturnSortedInputFiles(file)
test.isequal(file, sorted.ClInclude)
end
function vs10_vcxproj.sortFile_srcFile_SortedClCompileEqualToFile()
local file = {"b.cxx"}
local sorted = SortAndReturnSortedInputFiles(file)
test.isequal(file, sorted.ClCompile)
end
function vs10_vcxproj.sortFile_notRegistered_SortedNoneEqualToFile()
local file = {"foo.bar.00h"}
local sorted = SortAndReturnSortedInputFiles(file)
test.isequal(file, sorted.None)
end
function vs10_vcxproj.itemGroupSection_hasHeaderListed()
buffer = get_buffer()
test.string_contains(buffer,'<ItemGroup>.*<ClInclude Include="foo\\dummyHeader%.h" />.*</ItemGroup>')
end
function vs10_vcxproj.checkProjectConfigurationOpeningTag_hasACloseingAngleBracket()
local buffer = get_buffer()
test.string_contains(buffer,'<ProjectConfiguration Include="Debug|Win32">')
end
function vs10_vcxproj.postBuildEvent_isPresent()
postbuildcommands { "doSomeThing" }
local buffer = get_buffer()
test.string_contains(buffer,'<PostBuildEvent>.*<Command>.*</Command>.*</PostBuildEvent>')
end
function vs10_vcxproj.postBuildEvent_containsCorrectInformationBetweenCommandTag()
postbuildcommands { "doSomeThing" }
local buffer = get_buffer()
test.string_contains(buffer,'<PostBuildEvent>.*<Command>doSomeThing</Command>.*</PostBuildEvent>')
end
function vs10_vcxproj.postBuildEvent_eventEncloseByQuotes_containsCorrectInformationBetweenCommandTag()
postbuildcommands { "\"doSomeThing\"" }
local buffer = get_buffer()
test.string_contains(buffer,'<PostBuildEvent>.*<Command>"doSomeThing"</Command>.*</PostBuildEvent>')
end
function vs10_vcxproj.outDir_directorySuppliedIsNotSlashPostFixed_bufferContainsOutDirSlashPostFixed()
targetdir("dir")
local buffer = get_buffer()
test.string_contains(buffer,'<OutDir Condition="\'%$%(Configuration%)|%$%(Platform%)\'==\.*\'">dir\\</OutDir>')
end
--postfixed directory slashes are removed by default
--yet these following two tests are to ensure if this behaviour is changed they will fail
function vs10_vcxproj.outDir_directorySuppliedWhichIsForwardSlashPostFixed_bufferContainsOutDirSlashPostFixed()
targetdir("dir/")
local buffer = get_buffer()
test.string_contains(buffer,'<OutDir Condition="\'%$%(Configuration%)|%$%(Platform%)\'==\.*\'">dir\\</OutDir>')
end
function vs10_vcxproj.outDir_directorySuppliedWhichIsWindowsSlashPostFixed_bufferContainsOutDirSlashPostFixed()
targetdir("dir\\")
local buffer = get_buffer()
test.string_contains(buffer,'<OutDir Condition="\'%$%(Configuration%)|%$%(Platform%)\'==\.*\'">dir\\</OutDir>')
end
function vs10_vcxproj.objectDir_directorySuppliedIsNotSlashPostFixed_bufferContainsIntermediateDirSlashPostFixed()
objdir ("dir")
local buffer = get_buffer()
test.string_contains(buffer,'<IntDir Condition="\'%$%(Configuration%)|%$%(Platform%)\'==\'.*\'">dir\\</IntDir>')
end
--postfixed directory slashes are removed by default
--yet these following two tests are to ensure if this behaviour is changed they will fail
function vs10_vcxproj.objectDir_directorySuppliedWhichIsSlashPostFixed_bufferContainsIntermediateDirSlashPostFixed()
objdir ("dir/")
local buffer = get_buffer()
test.string_contains(buffer,'<IntDir Condition="\'%$%(Configuration%)|%$%(Platform%)\'==\'.*\'">dir\\</IntDir>')
end
function vs10_vcxproj.objectDir_directorySuppliedWhichIsWindowsSlashPostFixed_bufferContainsIntermediateDirSlashPostFixed()
objdir ("dir\\")
local buffer = get_buffer()
test.string_contains(buffer,'<IntDir Condition="\'%$%(Configuration%)|%$%(Platform%)\'==\'.*\'">dir\\</IntDir>')
end
function vs10_vcxproj.targetName()
configuration("Debug")
targetname ("foo_d")
local buffer = get_buffer()
test.string_contains(buffer,'<TargetName Condition="\'%$%(Configuration%)|%$%(Platform%)\'==\'Debug|Win32\'">foo_d</TargetName>')
end
function vs10_vcxproj.noExtraWarnings_bufferDoesNotContainSmallerTypeCheck()
local buffer = get_buffer()
test.string_does_not_contain(buffer,'<SmallerTypeCheck>')
end
function vs10_vcxproj.debugAndExtraWarnings_bufferContainsSmallerTypeCheck()
configuration("Debug")
flags {"ExtraWarnings"}
local buffer = get_buffer()
test.string_contains(buffer,'<SmallerTypeCheck>true</SmallerTypeCheck>')
end
function vs10_vcxproj.releaseAndExtraWarnings_bufferDoesNotContainSmallerTypeCheck()
configuration("Release")
flags {"ExtraWarnings"}
local buffer = get_buffer()
test.string_does_not_contain(buffer,'<SmallerTypeCheck>')
end
function vs10_vcxproj.onlyOneProjectConfigurationBlockWhenMultipleConfigs()
local buffer = get_buffer()
test.string_does_not_contain(buffer,'<ItemGroup Label="ProjectConfigurations">.*<ItemGroup Label="ProjectConfigurations">')
end
function vs10_vcxproj.languageC_bufferContainsCompileAsC()
language "C"
local buffer = get_buffer()
test.string_contains(buffer,'<CompileAs>CompileAsC</CompileAs>')
end
|