Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3128_Prediction_Intervals/Test.ps1 @ 18239

Last change on this file since 18239 was 17191, checked in by abeham, 5 years ago

#3017: Adapted discovery of msbuild and vstest

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