Skip to content

Commit 8e65245

Browse files
committed
Added VariableDocumentationIsUpToDate test
1 parent 83f304f commit 8e65245

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
5+
using GitVersion;
6+
7+
using NUnit.Framework;
8+
9+
using Shouldly;
10+
11+
[TestFixture]
12+
public class DocumentationTests
13+
{
14+
[Test]
15+
public void VariableDocumentationIsUpToDate()
16+
{
17+
var variableDocumentationFile = ReadDocumentationFile("more-info/variables.md");
18+
var variables = VersionVariables.AvailableVariables.ToList();
19+
20+
variables.ShouldNotBeEmpty();
21+
22+
foreach (var variable in variables)
23+
{
24+
variableDocumentationFile.ShouldContain(variable,
25+
Environment.NewLine + variableDocumentationFile);
26+
}
27+
}
28+
29+
30+
static string ReadDocumentationFile(string relativeDocumentationFilePath)
31+
{
32+
var currentDirectory = new DirectoryInfo(Environment.CurrentDirectory);
33+
while (currentDirectory != null)
34+
{
35+
var docsDirectory = currentDirectory
36+
.EnumerateDirectories("docs", SearchOption.TopDirectoryOnly)
37+
.FirstOrDefault();
38+
39+
if (docsDirectory != null)
40+
{
41+
currentDirectory = docsDirectory;
42+
break;
43+
}
44+
45+
currentDirectory = currentDirectory.Parent;
46+
}
47+
48+
if (currentDirectory == null || !currentDirectory.Name.Equals("docs", StringComparison.Ordinal))
49+
{
50+
throw new DirectoryNotFoundException("Couldn't find the 'docs' directory.");
51+
}
52+
53+
var documentationFilePath = Path.Combine(currentDirectory.FullName, relativeDocumentationFilePath);
54+
// Normalize path separators and such.
55+
documentationFilePath = new FileInfo(documentationFilePath).FullName;
56+
57+
if (!File.Exists(documentationFilePath))
58+
{
59+
throw new FileNotFoundException(string.Format("The documentation file '{0}' couldn't be found.", documentationFilePath), documentationFilePath);
60+
}
61+
62+
return File.ReadAllText(documentationFilePath);
63+
}
64+
}

src/GitVersionCore.Tests/GitVersionCore.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
<Compile Include="BuildServers\MyGetTests.cs" />
121121
<Compile Include="BuildServers\VsoAgentTests.cs" />
122122
<Compile Include="BuildServers\TeamCityTests.cs" />
123+
<Compile Include="DocumentationTests.cs" />
123124
<Compile Include="Fixtures\CommitCountingRepoFixture.cs" />
124125
<Compile Include="ConfigProviderTests.cs" />
125126
<Compile Include="Fixtures\LocalRepositoryFixture.cs" />

src/GitVersionCore/OutputVariables/VersionVariables.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections;
44
using System.Collections.Generic;
55
using System.Linq;
6+
using System.Reflection;
67

78
public class VersionVariables : IEnumerable<KeyValuePair<string, string>>
89
{
@@ -81,8 +82,9 @@ public static IEnumerable<string> AvailableVariables
8182
get
8283
{
8384
return typeof(VersionVariables)
84-
.GetProperties()
85+
.GetProperties(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance)
8586
.Select(p => p.Name)
87+
.Where(p => p != "AvailableVariables" && p != "Item")
8688
.OrderBy(a => a);
8789
}
8890
}

0 commit comments

Comments
 (0)