Invoke-CmdScript($scriptName)1 function Invoke-CmdScript($scriptName)
2 {
3 	$cmdLine = """$scriptName"" $args & set"
4 	& $Env:SystemRoot\system32\cmd.exe /c $cmdLine |
5 	select-string '^([^=]*)=(.*)$' | foreach-object {
6 		$varName = $_.Matches[0].Groups[1].Value
7 		$varValue = $_.Matches[0].Groups[2].Value
8 		set-item Env:$varName $varValue
9 	}
10 }
11 
12 $sources = @("src/pugixml.cpp") + (Get-ChildItem -Path "tests/*.cpp" -Exclude "fuzz_*.cpp")
13 $failed = $FALSE
14 
15 foreach ($vs in 9,10,11,12,14)
16 {
17 	foreach ($arch in "x86","x64")
18 	{
19 		Write-Output "# Setting up VS$vs $arch"
20 
21 		Invoke-CmdScript "C:\Program Files (x86)\Microsoft Visual Studio $vs.0\VC\vcvarsall.bat" $arch
22 		if (! $?) { throw "Error setting up VS$vs $arch" }
23 
24 		foreach ($defines in "standard", "PUGIXML_WCHAR_MODE", "PUGIXML_COMPACT")
25 		{
26 			$target = "tests_vs${vs}_${arch}_${defines}"
27 			$deflist = if ($defines -eq "standard") { "" } else { "/D$defines" }
28 
29 			Add-AppveyorTest $target -Outcome Running
30 
31 			Write-Output "# Building $target.exe"
32 			& cmd /c "cl.exe /Fe$target.exe /EHsc /W4 /WX $deflist $sources 2>&1" | Tee-Object -Variable buildOutput
33 
34 			if ($?)
35 			{
36 				Write-Output "# Running $target.exe"
37 
38 				$sw = [Diagnostics.Stopwatch]::StartNew()
39 
40 				& .\$target | Tee-Object -Variable testOutput
41 
42 				if ($?)
43 				{
44 					Write-Output "# Passed"
45 
46 					Update-AppveyorTest $target -Outcome Passed -StdOut ($testOutput | out-string) -Duration $sw.ElapsedMilliseconds
47 				}
48 				else
49 				{
50 					Write-Output "# Failed"
51 
52 					Update-AppveyorTest $target -Outcome Failed -StdOut ($testOutput | out-string) -ErrorMessage "Running failed"
53 
54 					$failed = $TRUE
55 				}
56 			}
57 			else
58 			{
59 				Write-Output "# Failed to build"
60 
61 				Update-AppveyorTest $target -Outcome Failed -StdOut ($buildOutput | out-string) -ErrorMessage "Compilation failed"
62 
63 				$failed = $TRUE
64 			}
65 		}
66 	}
67 }
68 
69 if ($failed) { throw "One or more build steps failed" }
70 
71 Write-Output "# End"
72