Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/Test.ps1 @ 17158

Last change on this file since 17158 was 17016, checked in by abeham, 5 years ago

#2875: Adapted the Test command scripts to use VS2017

File size: 4.8 KB
Line 
1# find ms build
2$programFilesX86Dir = ($Env:ProgramFiles, ${Env:ProgramFiles(x86)})[[bool]${Env:ProgramFiles(x86)}]
3$locations = @(
4  [System.IO.Path]::Combine($programFilesX86Dir, "Microsoft Visual Studio", "2017", "Enterprise")
5  [System.IO.Path]::Combine($programFilesX86Dir, "Microsoft Visual Studio", "2017", "Community")
6  [System.IO.Path]::Combine($programFilesX86Dir, "Microsoft Visual Studio", "2017", "BuildTools")
7)
8
9$vstestPath = $undefined
10Foreach ($loc in $locations) {
11  $vstestloc = [System.IO.Path]::Combine($loc, "Common7", "IDE", "CommonExtensions", "Microsoft", "TestWindow", "vstest.console.exe")
12  If([System.IO.File]::Exists($vstestloc)) {
13    $vstestPath = $vstestloc
14    Break;
15  }
16}
17
18If ($vstestPath -eq $undefined) {
19  "Could not locate vstest.console.exe, ABORTING ..."
20  Return
21}
22
23$testcontainer = "HeuristicLab.Tests.dll"
24$input = Read-Host "Which container to test? [$($testcontainer)]"
25$testcontainer = ($testcontainer, $input)[[bool]$input]
26
27$testplatform = "x64"
28$input = Read-Host "Which platform to run the tests? [$($testplatform)]"
29$testplatform = ($testplatform, $input)[[bool]$input]
30
31$testcategory = "Essential"
32$input = Read-Host "Which category do you want to run? [$($testcategory)]"
33$testcategory = ($testcategory, $input)[[bool]$input]
34
35# query whether to build
36$input = Read-Host "Should the tests be rebuilt y/N?"
37$input = ([string]("n", $input)[[bool]$input]).ToLowerInvariant()
38$dobuild = $input -eq "y"
39
40If($dobuild) {
41
42  $msBuildPath = $undefined
43  Foreach ($loc in $locations) {
44    $msbuildloc64 = [System.IO.Path]::Combine($loc, "MSBuild", "15.0", "Bin", "amd64", "MSBuild.exe")
45    $msbuildloc32 = [System.IO.Path]::Combine($loc, "MSBuild", "15.0", "Bin", "MSBuild.exe")
46    If ([System.IO.File]::Exists($msbuildloc64)) {
47      $msBuildPath = $msbuildloc64
48      Break;
49    } ElseIf ([System.IO.File]::Exists($msbuildloc32)) {
50      $msBuildPath = $msbuildloc32
51      Break;
52    }
53  }
54 
55  If ($msBuildPath -eq $undefined) {
56    "Could not locate MSBuild, ABORTING ..."
57    Return
58  }
59
60  $curPath = $MyInvocation.MyCommand.Path
61  $curDir = Split-Path $curPath
62
63  $slnFiles = Get-ChildItem $curDir -Filter *Tests.sln
64
65  If ($slnFiles.Count -le 0) {
66    "No solutions found, ABORTING ..."
67    Return
68  }
69
70  $slnIndices = @()
71
72  If ($slnFiles.Count -eq 1) {
73    "Selecting the only solution found: `"{0}`"" -f $slnFiles[0].Name
74    $slnIndices += 0
75  } Else {
76    "Found the following solutions:"
77
78    ""
79
80    $slnFiles | % { $i = 0 } { ("  {0}. `"{1}`"" -f ($i + 1), $_.Name); $i++ }
81
82    ""
83
84    $success = $false
85
86    # query solution to build
87    $slnIndex = -1
88    Do {
89        $input = Read-Host "Which solution(s) to build? (e.g.: 1 2 3) { 1..$($slnFiles.Count) }"
90        $inputParts = $input -Split " "
91
92        Foreach ($part in $inputParts) {
93          If ($part -eq "") { Continue }
94
95          $success = [int]::TryParse($part, [ref]$slnIndex) -and ($slnIndex -gt 0) -and ($slnIndex -le $slnFiles.Count)
96
97          If ($success) {
98            $slnIndices += $slnIndex - 1
99          } Else {
100            $slnIndices = @()
101            Break
102          }
103        }
104    } While (-Not $success)
105
106    $slnIndices = $slnIndices | Select-Object -Unique
107  }
108
109
110  # query configuration to build
111  $config = "Release"
112  $input = Read-Host "Which configuration to build? [$($config)]"
113  $config = ($config, $input)[[bool]$input]
114
115  # query platform to build
116  $platform = "Any CPU"
117  $input = Read-Host "Which platform to build? [$($platform)]"
118  $platform = ($platform, $input)[[bool]$input]
119
120  # query clean desire
121  $clean = $false
122  Do {
123      $input = Read-Host "Would you like to clean before building? [y/N]"
124      $input = ([string]("n", $input)[[bool]$input]).ToLowerInvariant()
125      $success = $input -eq "n" -or ($clean = $input -eq "y")
126  } While (-Not $success)
127
128  ""
129
130  If ($clean) {
131    Foreach ($slnIndex in $slnIndices) {
132      $solution = $slnFiles[$slnIndex]
133      "Cleaning `"$($solution.Name)`" ..."
134      $args = @(
135        $solution.FullName,
136        "/t:Clean",
137        "/p:Configuration=`"$config`",Platform=`"$platform`"",
138        "/m", "/nologo", "/verbosity:q", "/clp:ErrorsOnly"
139      )
140      & $msBuildPath $args
141      "===== CLEAN FINISHED ====="
142    }
143  }
144
145  Foreach ($slnIndex in $slnIndices) {
146    $solution = $slnFiles[$slnIndex]
147    "Building `"$($solution.Name)`" ($config|$platform) ..."
148    $args = @(
149      $solution.FullName,
150      "/t:Restore,Build",
151      "/p:Configuration=`"$config`",Platform=`"$platform`"",
152      "/m", "/nologo", "/verbosity:q", "/clp:ErrorsOnly"
153    )
154    & $msBuildPath $args
155    "===== BUILD FINISHED ====="
156  }
157}
158
159& $vstestPath "bin\$testcontainer" /Framework:framework40 /Platform:$testplatform /TestCaseFilter:"TestCategory=$testcategory"
Note: See TracBrowser for help on using the repository browser.