Skip to content

Commit 4560929

Browse files
committed
Generate unit test placeholder if not exist
To automatically create compile errors for new unit classes, to not forget to implement tests for the units.
1 parent cc424af commit 4560929

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

Src/Scripts/GenerateUnits.ps1

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,26 @@ function GenerateUnitClass($unitClass)
7373

7474
function GenerateUnitTestBaseClass($unitClass)
7575
{
76-
Write-Host "Generate test for: " + $unitClass.Name;
76+
Write-Host "Generate test base for: " + $unitClass.Name;
7777

7878
$outFileName = "$PSScriptRoot/../../Tests/GeneratedCode/$($unitClass.Name)TestsBase.g.cs";
7979
GenerateUnitTestBaseClassSourceCode $unitClass | Out-File -Encoding "UTF8" $outFileName
8080
}
8181

82+
function GenerateUnitTestClassIfNotExists($unitClass)
83+
{
84+
$outFileName = "$PSScriptRoot/../../Tests/CustomCode/$($unitClass.Name)Tests.cs";
85+
if (Test-Path $outFileName)
86+
{
87+
return;
88+
}
89+
else
90+
{
91+
Write-Host "Generate test placeholder for: " + $unitClass.Name;
92+
GenerateUnitTestPlaceholderSourceCode $unitClass | Out-File -Encoding "UTF8" $outFileName
93+
}
94+
}
95+
8296
function GenerateUnitEnum($unitClass)
8397
{
8498
Write-Host "Generate unit enum for: " + $unitClass.Name;
@@ -112,6 +126,7 @@ function GenerateUnitSystemDefault($unitClasses)
112126
. "$PSScriptRoot/Include-GenerateUnitClassSourceCode.ps1"
113127
. "$PSScriptRoot/Include-GenerateUnitEnumSourceCode.ps1"
114128
. "$PSScriptRoot/Include-GenerateUnitTestBaseClassSourceCode.ps1"
129+
. "$PSScriptRoot/Include-GenerateUnitTestPlaceholderSourceCode.ps1"
115130

116131
$templatesDir = "$PSScriptRoot/UnitDefinitions";
117132
$unitClasses = @();
@@ -127,6 +142,7 @@ get-childitem -path $templatesDir -filter "*.json" | % {
127142
GenerateUnitClass $unitClass
128143
GenerateUnitEnum $unitClass
129144
GenerateUnitTestBaseClass $unitClass
145+
GenerateUnitTestClassIfNotExists $unitClass
130146

131147
$unitClasses += $unitClass;
132148
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
function GenerateUnitTestPlaceholderSourceCode($unitClass)
2+
{
3+
$className = $unitClass.Name;
4+
@"
5+
// Copyright © 2007 by Initial Force AS. All rights reserved.
6+
// https://github.com/InitialForce/UnitsNet
7+
//
8+
// Permission is hereby granted, free of charge, to any person obtaining a copy
9+
// of this software and associated documentation files (the "Software"), to deal
10+
// in the Software without restriction, including without limitation the rights
11+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
// copies of the Software, and to permit persons to whom the Software is
13+
// furnished to do so, subject to the following conditions:
14+
//
15+
// The above copyright notice and this permission notice shall be included in
16+
// all copies or substantial portions of the Software.
17+
//
18+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
// THE SOFTWARE.
25+
26+
27+
using System;
28+
29+
namespace UnitsNet.Tests.CustomCode
30+
{
31+
public class $($className)Tests : $($className)TestsBase
32+
{
33+
// TODO Override properties in base class here
34+
}
35+
}
36+
"@;
37+
}

0 commit comments

Comments
 (0)