Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VB-specific DocumentationFile generation. #1848

Merged
merged 1 commit into from
Jan 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Assets/TestProjects/AppWithLibraryVB/TestApp/Program.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
' Copyright (c) .NET Foundation and contributors. All rights reserved.
' Licensed under the MIT license. See LICENSE file in the project root for full license information.

Imports System

Namespace TestApp

Module Program

Sub Main(args As String())
Console.WriteLine(TestLibrary.Helper.GetMessage())
End Sub

End Module

End Namespace
14 changes: 14 additions & 0 deletions src/Assets/TestProjects/AppWithLibraryVB/TestApp/TestApp.vbproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>1.2.3-beta</Version>
<Authors>Test Authors</Authors>
<Product>Test Product</Product>
<AssemblyTitle>Test AssemblyTitle</AssemblyTitle>
<Copyright>Copyright (c) Test Authors</Copyright>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../TestLibrary/TestLibrary.vbproj" />
</ItemGroup>
</Project>
18 changes: 18 additions & 0 deletions src/Assets/TestProjects/AppWithLibraryVB/TestLibrary/Helper.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
' Copyright (c) .NET Foundation and contributors. All rights reserved.
' Licensed under the MIT license. See LICENSE file in the project root for full license information.

Namespace TestLibrary

Public Class Helper

Public Shared Function GetMessage() As String
Return "This string came from the test library!"
End Function

Public Sub SayHi()
Console.WriteLine("Hello there!")
End Sub

End Class

End Namespace
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>42.43.44.45-alpha</Version>
<OutputType>Library</OutputType>
<TargetFramework>netstandard1.5</TargetFramework>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ Copyright (c) .NET Foundation. All rights reserved.
</PropertyGroup>

<PropertyGroup Condition="'$(GenerateDocumentationFile)' == 'true' and '$(DocumentationFile)' == ''">
<DocumentationFile>$(IntermediateOutputPath)$(AssemblyName).xml</DocumentationFile>
<DocumentationFile Condition="'$(MSBuildProjectExtension)' == '.vbproj'">$(AssemblyName).xml</DocumentationFile>
<DocumentationFile Condition="'$(MSBuildProjectExtension)' != '.vbproj'">$(IntermediateOutputPath)$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(GenerateDocumentationFile)' != 'true'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,20 @@ internal static List<string> GetValuesFromTestLibrary(
return itemValues;
}

private TestAsset CreateDocumentationFileLibraryAsset(bool? generateDocumentationFile, string documentationFile, [CallerMemberName] string callingMethod = "")
private TestAsset CreateDocumentationFileLibraryAsset(bool? generateDocumentationFile, string documentationFile, string language, [CallerMemberName] string callingMethod = "")
{
string genDocFileIdentifier = generateDocumentationFile == null ? "null" : generateDocumentationFile.Value.ToString();
string docFileIdentifier = documentationFile == null ? "null" : Path.GetFileName(documentationFile);
string identifier = $"-genDoc={genDocFileIdentifier}, docFile={Path.GetFileName(docFileIdentifier)}";

var testAssetName = "AppWithLibrary";
if (language != "cs")
{
testAssetName += language.ToUpperInvariant();
}

var testAsset = _testAssetsManager
.CopyTestAsset("AppWithLibrary", callingMethod, identifier)
.CopyTestAsset(testAssetName, callingMethod, identifier)
.WithSource()
.WithProjectChanges(project =>
{
Expand All @@ -232,10 +238,12 @@ private TestAsset CreateDocumentationFileLibraryAsset(bool? generateDocumentatio
return testAsset;
}

[Fact]
public void It_creates_a_documentation_file()
[Theory]
[InlineData("cs")]
[InlineData("vb")]
public void It_creates_a_documentation_file(string language)
{
var testAsset = CreateDocumentationFileLibraryAsset(true, null);
var testAsset = CreateDocumentationFileLibraryAsset(true, null, language);

var libraryProjectDirectory = Path.Combine(testAsset.TestRoot, "TestLibrary");

Expand All @@ -257,17 +265,19 @@ public void It_creates_a_documentation_file()

new DirectoryInfo(libraryProjectDirectory).Should().OnlyHaveFiles(new[]
{
"Helper.cs",
"TestLibrary.csproj"
$"Helper.{language}",
$"TestLibrary.{language}proj"
}, SearchOption.TopDirectoryOnly);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void It_allows_us_to_override_the_documentation_file_name(bool setGenerateDocumentationFileProperty)
[InlineData("cs", true)]
[InlineData("cs", false)]
[InlineData("vb", true)]
[InlineData("vb", false)]
public void It_allows_us_to_override_the_documentation_file_name(string language, bool setGenerateDocumentationFileProperty)
{
var testAsset = CreateDocumentationFileLibraryAsset(setGenerateDocumentationFileProperty ? (bool?)true : null, "TestLibDoc.xml", "OverrideDocFileName");
var testAsset = CreateDocumentationFileLibraryAsset(setGenerateDocumentationFileProperty ? (bool?)true : null, "TestLibDoc.xml", language, "OverrideDocFileName");

var libraryProjectDirectory = Path.Combine(testAsset.TestRoot, "TestLibrary");

Expand All @@ -289,20 +299,28 @@ public void It_allows_us_to_override_the_documentation_file_name(bool setGenerat

// Due to the way the DocumentationFile works, if you specify an unrooted filename, then the documentation file will be generated in that
// location relative to the project folder, and then copied to the output folder.
new DirectoryInfo(libraryProjectDirectory).Should().OnlyHaveFiles(new[]
var expectedProjectDirectoryFiles = new List<string>()
{
"Helper.cs",
"TestLibrary.csproj",
"TestLibDoc.xml"
}, SearchOption.TopDirectoryOnly);
$"Helper.{language}",
$"TestLibrary.{language}proj"
};

// vb uses DocumentationFile relative to the IntermediateOutputPath
if (language != "vb") {
expectedProjectDirectoryFiles.Add("TestLibDoc.xml");
}

new DirectoryInfo(libraryProjectDirectory).Should().OnlyHaveFiles(expectedProjectDirectoryFiles, SearchOption.TopDirectoryOnly);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void It_does_not_create_a_documentation_file_if_GenerateDocumentationFile_property_is_false(bool setDocumentationFileProperty)
[InlineData("cs", true)]
[InlineData("cs", false)]
[InlineData("vb", true)]
[InlineData("vb", false)]
public void It_does_not_create_a_documentation_file_if_GenerateDocumentationFile_property_is_false(string language, bool setDocumentationFileProperty)
{
var testAsset = CreateDocumentationFileLibraryAsset(false, setDocumentationFileProperty ? "TestLibDoc.xml" : null, "DoesntCreateDocFile");
var testAsset = CreateDocumentationFileLibraryAsset(false, setDocumentationFileProperty ? "TestLibDoc.xml" : null, language, "DoesntCreateDocFile");

var libraryProjectDirectory = Path.Combine(testAsset.TestRoot, "TestLibrary");

Expand All @@ -324,8 +342,8 @@ public void It_does_not_create_a_documentation_file_if_GenerateDocumentationFile
// Make sure documentation file isn't generated in project folder either
new DirectoryInfo(libraryProjectDirectory).Should().OnlyHaveFiles(new[]
{
"Helper.cs",
"TestLibrary.csproj"
$"Helper.{language}",
$"TestLibrary.{language}proj"
}, SearchOption.TopDirectoryOnly);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ internal static string FindProjectFile(ref string projectRootPath, string relati
}
}

var buildProjectFiles = Directory.GetFiles(projectRootPath, "*.csproj");
var buildProjectFiles = Directory.GetFiles(projectRootPath, "*.*proj");

if (buildProjectFiles.Length != 1)
{
var errorMsg = $"Found {buildProjectFiles.Length} .csproj files under {projectRootPath} instead of just 1.";
var errorMsg = $"Found {buildProjectFiles.Length} project files under {projectRootPath} instead of just 1.";
throw new ArgumentException(errorMsg);
}

Expand Down