Skip to content

Commit ee153c6

Browse files
committed
- Fixed division bug.
- Improved unit tests and added another. Still need to add a few more.
1 parent ae4421a commit ee153c6

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Ignore generated test files.
2+
*_UsedByTests_*

Set-ProjectFilesClickOnceVersion.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ foreach ($clickOncePropertyGroup in $clickOncePropertyGroups)
243243
if ($BuildSystemsBuildId -gt -1)
244244
{
245245
# Use a calculation for the Build and Revision to prevent the Revision value from being too large, and to increment the Build value as the BuildSystemsBuildId continues to grow larger.
246-
$build = $BuildSystemsBuildId / $maxVersionPartValueAllowed
246+
$build = [int]($BuildSystemsBuildId / $maxVersionPartValueAllowed)
247247
$revision = $BuildSystemsBuildId % $maxVersionPartValueAllowed
248248
}
249249

Tests/RunTests.ps1

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,24 @@ $projectFilePathCopy = $projectFilePath + '_UsedByTests_.csproj'
2121
Copy-Item -Path $projectFilePath -Destination $projectFilePathCopy -Force
2222

2323
$global:runScriptExpression = "& $scriptPath -ProjectFilePath $projectFilePathCopy "
24+
$global:versionNumberAtEndOfOutputRegex = New-Object System.Text.RegularExpressions.Regex "'(?<Version>\d+\.\d+\.\d+\.\d+)'.$", SingleLine
2425

2526
function RunScriptWithParameters($parameters)
2627
{
27-
Invoke-Expression "$($global:runScriptExpression) $parameters"
28-
28+
$output = Invoke-Expression -Command "$($global:runScriptExpression) $parameters"
29+
if ($output -imatch $global:versionNumberAtEndOfOutputRegex)
30+
{
31+
return $matches["Version"]
32+
}
33+
return $output
2934
}
3035

3136
$testNumber = 0
3237

3338
Write-Host ("{0}. Explicitly set version number..." -f ++$testNumber)
34-
if ((RunScriptWithParameters "-Version '1.2.3.4'").EndsWith("'1.2.3.4'.")) { Write-Host "Passed" } else { throw "Test $testNumber failed." }
39+
$output = RunScriptWithParameters "-Version '1.2.3.4'"
40+
if ($output -eq '1.2.3.4') { Write-Host "Passed" } else { throw "Test $testNumber failed. Output was '$output'." }
3541

42+
Write-Host ("{0}. Explicitly set version number..." -f ++$testNumber)
43+
$output = RunScriptWithParameters "-BuildSystemsBuildId 1234"
44+
if ($output -eq '1.2.0.1234') { Write-Host "Passed" } else { throw "Test $testNumber failed. Output was '$output'." }

0 commit comments

Comments
 (0)