Skip to content

Commit

Permalink
(cake-buildGH-943) Correcting AssemblyInfo Parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
gep13 committed Jun 5, 2016
1 parent c68360c commit c00f8d7
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/Cake.Common.Tests/Fixtures/AssemblyInfoParserFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public AssemblyInfoParserFixture()
CreateAssemblyInfo = true;
}

public void WithAssemblyInfoContents(string assemblyInfoContents)
{
FileSystem.CreateFile("/Working/output.cs").SetContent(assemblyInfoContents);
}

public AssemblyInfoParseResult Parse()
{
if (CreateAssemblyInfo && Path != null)
Expand Down
40 changes: 40 additions & 0 deletions src/Cake.Common.Tests/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions src/Cake.Common.Tests/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -768,4 +768,60 @@ Line #3]]></releaseNotes>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
&lt;/Project&gt;</value>
</data>
<data name="MonoDevelopAssemblyInfo" xml:space="preserve">
<value>using System.Reflection;
using System.Runtime.CompilerServices;

// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.

[assembly: AssemblyTitle ("MonoDevelopAssemblyTitle")]
[assembly: AssemblyDescription ("MonoDevelopAssemblyDescription")]
[assembly: AssemblyConfiguration ("MonoDevelopConfiguration")]
[assembly: AssemblyCompany ("MonoDevelopCompany")]
[assembly: AssemblyProduct ("MonoDevelopProduct")]
[assembly: AssemblyCopyright ("MonoDevelopCopyright")]
[assembly: AssemblyTrademark ("MonoDevelopTrademark")]
[assembly: AssemblyCulture ("en-US")]

// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion ("1.0.14")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.

//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]</value>
</data>
<data name="VisualStudioAssemblyInfo" xml:space="preserve">
<value>using System.Reflection;
using System.Runtime.CompilerServices;

// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.

[assembly: AssemblyTitle("VisualStudioAssemblyTitle")]
[assembly: AssemblyDescription("VisualStudioAssemblyDescription")]
[assembly: AssemblyConfiguration("VisualStudioConfiguration")]
[assembly: AssemblyCompany("VisualStudioCompany")]
[assembly: AssemblyProduct("VisualStudioProduct")]
[assembly: AssemblyCopyright("VisualStudioCopyright")]
[assembly: AssemblyTrademark("VisualStudioTrademark")]
[assembly: AssemblyCulture("en-US")]

// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion("1.0.13")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.

//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using Cake.Common.Solution.Project.Properties;
using Cake.Common.Tests.Fixtures;
using Cake.Common.Tests.Properties;
using Cake.Core;
using Cake.Core.IO;
using NSubstitute;
Expand Down Expand Up @@ -305,6 +306,48 @@ public void Should_Read_AssemblyVersion(string value, string expected)
// Then
Assert.Equal(expected, result.AssemblyVersion);
}

[Fact]
public void Should_Correctly_Parse_VisualStudio_AssemblyInfo_File()
{
// Given
var fixture = new AssemblyInfoParserFixture();
fixture.CreateAssemblyInfo = false;
fixture.WithAssemblyInfoContents(Resources.VisualStudioAssemblyInfo.NormalizeLineEndings());

// When
var result = fixture.Parse();

// Then
Assert.Equal(result.Title, "VisualStudioAssemblyTitle");
Assert.Equal(result.Description, "VisualStudioAssemblyDescription");
Assert.Equal(result.Configuration, "VisualStudioConfiguration");
Assert.Equal(result.Company, "VisualStudioCompany");
Assert.Equal(result.Product, "VisualStudioProduct");
Assert.Equal(result.Copyright, "VisualStudioCopyright");
Assert.Equal(result.Trademark, "VisualStudioTrademark");
}

[Fact]
public void Should_Correctly_Parse_MonoDevelop_AssemblyInfo_File()
{
// Given
var fixture = new AssemblyInfoParserFixture();
fixture.CreateAssemblyInfo = false;
fixture.WithAssemblyInfoContents(Resources.MonoDevelopAssemblyInfo.NormalizeLineEndings());

// When
var result = fixture.Parse();

// Then
Assert.Equal(result.Title, "MonoDevelopAssemblyTitle");
Assert.Equal(result.Description, "MonoDevelopAssemblyDescription");
Assert.Equal(result.Configuration, "MonoDevelopConfiguration");
Assert.Equal(result.Company, "MonoDevelopCompany");
Assert.Equal(result.Product, "MonoDevelopProduct");
Assert.Equal(result.Copyright, "MonoDevelopCopyright");
Assert.Equal(result.Trademark, "MonoDevelopTrademark");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace Cake.Common.Solution.Project.Properties
/// </summary>
public sealed class AssemblyInfoParser
{
private const string NonQuotedPattern = @"^\s*\[assembly: {0}\((?<attributeValue>.*)\)";
private const string QuotedPattern = @"^\s*\[assembly: {0}\(""(?<attributeValue>.*)""\)";
private const string NonQuotedPattern = @"^\s*\[assembly: {0} ?\((?<attributeValue>.*)\)";
private const string QuotedPattern = @"^\s*\[assembly: {0} ?\(""(?<attributeValue>.*)""\)";
private const string DefaultVersion = "1.0.0.0";

private readonly IFileSystem _fileSystem;
Expand Down

0 comments on commit c00f8d7

Please sign in to comment.