Skip to content
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
1 change: 1 addition & 0 deletions Semver.Benchmarks/DecimalDigits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Semver.Benchmarks
{
[SimpleJob(RuntimeMoniker.Net461)]
[SimpleJob(RuntimeMoniker.NetCoreApp21)]
[SimpleJob(RuntimeMoniker.NetCoreApp31)]
public class DecimalDigits
{
[Params(99, 999, 999_999, int.MaxValue)]
Expand Down
1 change: 1 addition & 0 deletions Semver.Benchmarks/IsDigits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Semver.Benchmarks
{
[SimpleJob(RuntimeMoniker.Net461)]
[SimpleJob(RuntimeMoniker.NetCoreApp21)]
[SimpleJob(RuntimeMoniker.NetCoreApp31)]
public class IsDigits
{
private const string Value = "245413548946516575165756156751323245451984";
Expand Down
1 change: 1 addition & 0 deletions Semver.Benchmarks/NewSemVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Semver.Benchmarks
{
[SimpleJob(RuntimeMoniker.Net461)]
[SimpleJob(RuntimeMoniker.NetCoreApp21)]
[SimpleJob(RuntimeMoniker.NetCoreApp31)]
public class NewSemVersion
{
private const string Prerelease = "asdf.24534634.sdfdg.02343sd";
Expand Down
1 change: 1 addition & 0 deletions Semver.Benchmarks/Parsing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Semver.Benchmarks
/// </summary>
[SimpleJob(RuntimeMoniker.Net461)]
[SimpleJob(RuntimeMoniker.NetCoreApp21)]
[SimpleJob(RuntimeMoniker.NetCoreApp31)]
public abstract class Parsing
{
protected const int VersionCount = 1_000;
Expand Down
2 changes: 1 addition & 1 deletion Semver.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static void Main(string[] args)
//var random = new Random();
//var version = BasicPrereleaseParsing.RandomVersion(random);
//var seed = random.Next(int.MinValue, int.MaxValue);
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args).ToList();
_ = BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args).ToList();
}
}
}
12 changes: 2 additions & 10 deletions Semver.Benchmarks/Semver.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,14 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.1;net461</TargetFrameworks>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1;net461</TargetFrameworks>
<StartupObject>Semver.Benchmarks.Program</StartupObject>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.1' ">
<DefineConstants>$(DefineConstants);NETSTANDARD</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net461' ">
<DefineConstants>$(DefineConstants);NET461</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet">
<Version>0.13.0</Version>
<Version>0.13.1</Version>
</PackageReference>
<PackageReference Include="semver" Version="2.0.6">
<Aliases>previous</Aliases>
Expand Down
9 changes: 5 additions & 4 deletions Semver.Test/FrameworkCharacterizationTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Globalization;
using Xunit;
using static System.Environment;

namespace Semver.Test
{
Expand All @@ -24,7 +23,8 @@ public void IntTryParseOfInvalidNumberStyleThrowsArgumentException()
var ex = Assert.Throws<ArgumentException>(
() => int.TryParse("45", InvalidNumberStyle, CultureInfo.InvariantCulture, out _));

Assert.Equal(InvalidNumberStyleMessage, ex.Message);
Assert.StartsWith(InvalidNumberStyleMessageStart, ex.Message);
Assert.Equal("style", ex.ParamName);
}

[Fact]
Expand All @@ -33,7 +33,8 @@ public void IntParseOfNullAndInvalidNumberStyleThrowsInvalidNumberStyleArgumentE
var ex = Assert.Throws<ArgumentException>(
() => int.Parse(null, InvalidNumberStyle, CultureInfo.InvariantCulture));

Assert.Equal(InvalidNumberStyleMessage, ex.Message);
Assert.StartsWith(InvalidNumberStyleMessageStart, ex.Message);
Assert.Equal("style", ex.ParamName);
}

[Fact]
Expand All @@ -54,7 +55,7 @@ public void IntParseOverflow()
Assert.Equal(IntOverflowMessage, ex.Message);
}

private static readonly string InvalidNumberStyleMessage = $"An undefined NumberStyles value is being used.{NewLine}Parameter name: style";
private const string InvalidNumberStyleMessageStart = "An undefined NumberStyles value is being used.";
private const string InvalidFormatMessage = "Input string was not in a correct format.";
private const string IntOverflowMessage = "Value was either too large or too small for an Int32.";
private const NumberStyles InvalidNumberStyle = (NumberStyles)int.MaxValue;
Expand Down
9 changes: 4 additions & 5 deletions Semver.Test/PrereleaseIdentifierTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Globalization;
using Xunit;
using static System.Environment;

namespace Semver.Test
{
Expand Down Expand Up @@ -54,7 +53,7 @@ public void ConstructWithEmptyString(bool allowLeadingZeros)
var ex = Assert.Throws<ArgumentException>(() => new PrereleaseIdentifier("", allowLeadingZeros));

Assert.Equal("value", ex.ParamName);
Assert.Equal($"Cannot be empty string.{NewLine}Parameter name: value", ex.Message);
Assert.StartsWith($"Cannot be empty string.", ex.Message);
}

[Theory]
Expand Down Expand Up @@ -92,7 +91,7 @@ public void ConstructWithStringThrowsExceptionForLeadingZero(string value)
var ex = Assert.Throws<ArgumentException>(() => new PrereleaseIdentifier(value));

Assert.Equal("value", ex.ParamName);
Assert.Equal($"Leading zeros are not allowed on numeric prerelease identifiers '{value}'.{NewLine}Parameter name: value",
Assert.StartsWith($"Leading zeros are not allowed on numeric prerelease identifiers '{value}'.",
ex.Message);
}

Expand All @@ -108,7 +107,7 @@ public void ConstructWithStringWithInvalidCharacters(string value)
var ex = Assert.Throws<ArgumentException>(() => new PrereleaseIdentifier(value));

Assert.Equal("value", ex.ParamName);
Assert.Equal($"A prerelease identifier can contain only ASCII alphanumeric characters and hyphens '{value}'.{NewLine}Parameter name: value",
Assert.StartsWith($"A prerelease identifier can contain only ASCII alphanumeric characters and hyphens '{value}'.",
ex.Message);
}

Expand All @@ -132,7 +131,7 @@ public void ConstructWithNegativeInt(int value)
var ex = Assert.Throws<ArgumentException>(() => new PrereleaseIdentifier(value));

Assert.Equal("value", ex.ParamName);
Assert.Equal($"Numeric prerelease identifiers can't be negative: {value}.{NewLine}Parameter name: value",
Assert.StartsWith($"Numeric prerelease identifiers can't be negative: {value}.",
ex.Message);
}

Expand Down
19 changes: 12 additions & 7 deletions Semver.Test/SemVersionObsoleteParsingTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Text;
using Xunit;
using static System.Environment;

namespace Semver.Test
{
Expand Down Expand Up @@ -351,7 +350,8 @@ public void ParseLooseValidTest(string versionString, int major, int minor, int
public void ParseLooseInvalidThrowsArgumentExceptionTest(string versionString)
{
var ex = Assert.Throws<ArgumentException>(() => SemVersion.Parse(versionString));
Assert.Equal($"Invalid version '{versionString}'.{NewLine}Parameter name: version", ex.Message);
Assert.StartsWith($"Invalid version '{versionString}'.", ex.Message);
Assert.Equal("version", ex.ParamName);
}

[Theory]
Expand All @@ -366,8 +366,9 @@ public void ParseLooseInvalidThrowsOverflowExceptionTest(string versionString)
public void ParseLooseNullTest()
{
var ex = Assert.Throws<ArgumentNullException>(() => SemVersion.Parse(null));
Assert.StartsWith("Value cannot be null.", ex.Message);
// TODO that is a strange error message, should be version
Assert.Equal($"Value cannot be null.{NewLine}Parameter name: input", ex.Message);
Assert.Equal("input", ex.ParamName);
}

[Fact]
Expand Down Expand Up @@ -421,7 +422,8 @@ public void ParseStrictInvalidThrowsArgumentExceptionTest(string versionString)
#pragma warning disable CS0618 // Type or member is obsolete
var ex = Assert.Throws<ArgumentException>(() => SemVersion.Parse(versionString, true));
#pragma warning restore CS0618 // Type or member is obsolete
Assert.Equal($"Invalid version '{versionString}'.{NewLine}Parameter name: version", ex.Message);
Assert.StartsWith($"Invalid version '{versionString}'.", ex.Message);
Assert.Equal("version", ex.ParamName);
}

[Theory]
Expand Down Expand Up @@ -460,8 +462,9 @@ public void ParseStrictNullTest()
#pragma warning disable CS0618 // Type or member is obsolete
var ex = Assert.Throws<ArgumentNullException>(() => SemVersion.Parse(null, true));
#pragma warning restore CS0618 // Type or member is obsolete
Assert.StartsWith("Value cannot be null.", ex.Message);
// TODO that is a strange error message, should be version
Assert.Equal($"Value cannot be null.{NewLine}Parameter name: input", ex.Message);
Assert.Equal("input", ex.ParamName);
}

[Theory]
Expand Down Expand Up @@ -584,7 +587,8 @@ public void ImplicitConversionFromInvalidStringThrowsArgumentExceptionTest(strin
SemVersion _ = versionString;
#pragma warning restore CS0618 // Type or member is obsolete
});
Assert.Equal($"Invalid version '{versionString}'.{NewLine}Parameter name: version", ex.Message);
Assert.StartsWith($"Invalid version '{versionString}'.", ex.Message);
Assert.Equal("version", ex.ParamName);
}

[Theory]
Expand All @@ -610,8 +614,9 @@ public void ImplicitConversionFromNullStringTest()
SemVersion _ = default(string);
#pragma warning restore CS0618 // Type or member is obsolete
});
Assert.StartsWith("Value cannot be null.", ex.Message);
// TODO that is a strange error message, should be version
Assert.Equal($"Value cannot be null.{NewLine}Parameter name: input", ex.Message);
Assert.Equal("input", ex.ParamName);
}
#endregion

Expand Down
24 changes: 16 additions & 8 deletions Semver.Test/SemVersionParsingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Text;
using Semver.Test.Builders;
using Xunit;
using static System.Environment;
using static Semver.SemVersionStyles;

namespace Semver.Test
Expand All @@ -15,7 +14,7 @@ namespace Semver.Test
/// </summary>
public class SemVersionParsingTests
{
private static readonly string InvalidSemVersionStylesMessage = $"An invalid SemVersionStyles value was used.{NewLine}Parameter name: style";
private static readonly string InvalidSemVersionStylesMessageStart = $"An invalid SemVersionStyles value was used.";

private const string LeadingWhitespaceMessage = "Version '{0}' has leading whitespace.";
private const string TrailingWhitespaceMessage = "Version '{0}' has trailing whitespace.";
Expand Down Expand Up @@ -323,7 +322,7 @@ public class SemVersionParsingTests
ValidLongVersion(1445670),
ValidLongVersion(5646),

Invalid<ArgumentNullException>(null, $"Value cannot be null.{NewLine}Parameter name: version"));
Invalid<ArgumentNullException>(null, "Value cannot be null."));

[Fact]
public void CanConstructParsingTestCases()
Expand All @@ -349,7 +348,8 @@ public void ParseWithInvalidStyle(SemVersionStyles styles)
{
var ex = Assert.Throws<ArgumentException>(() => SemVersion.Parse("ignored", styles));

Assert.Equal(InvalidSemVersionStylesMessage, ex.Message);
Assert.StartsWith(InvalidSemVersionStylesMessageStart, ex.Message);
Assert.Equal("style", ex.ParamName);
}

[Theory]
Expand All @@ -369,9 +369,16 @@ public void ParseWithStyleParsesCorrectly(ParsingTestCase testCase)
var ex = Assert.Throws(testCase.ExceptionType,
() => SemVersion.Parse(testCase.Version, testCase.Styles, testCase.MaxLength));

Assert.Equal(string.Format(CultureInfo.InvariantCulture,
testCase.ExceptionMessageFormat, LimitLength(testCase.Version)),
ex.Message);
var expected = string.Format(CultureInfo.InvariantCulture,
testCase.ExceptionMessageFormat, LimitLength(testCase.Version));

if (ex is ArgumentException argumentException)
{
Assert.StartsWith(expected, argumentException.Message);
Assert.Equal("version", argumentException.ParamName);
}
else
Assert.Equal(expected, ex.Message);
}
}

Expand All @@ -381,7 +388,8 @@ public void TryParseWithInvalidStyle(SemVersionStyles styles)
{
var ex = Assert.Throws<ArgumentException>(() => SemVersion.TryParse("ignored", styles, out _));

Assert.Equal(InvalidSemVersionStylesMessage, ex.Message);
Assert.StartsWith(InvalidSemVersionStylesMessageStart, ex.Message);
Assert.Equal("style", ex.ParamName);
}

[Theory]
Expand Down
10 changes: 6 additions & 4 deletions Semver.Test/SemVersionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Runtime.Serialization.Formatters.Binary;
#endif
using Xunit;
using static System.Environment;

namespace Semver.Test
{
Expand Down Expand Up @@ -252,7 +251,8 @@ public void ConstructSemVersionFromNullSystemVersionTest()
var ex = Assert.Throws<ArgumentNullException>(() => new SemVersion(null));
#pragma warning restore 618

Assert.Equal($"Value cannot be null.{NewLine}Parameter name: version", ex.Message);
Assert.StartsWith("Value cannot be null.", ex.Message);
Assert.Equal("version", ex.ParamName);
}

[Theory]
Expand Down Expand Up @@ -285,7 +285,8 @@ public void FromVersionWithPositiveRevisionTest(int major, int minor, int build,

var ex = Assert.Throws<ArgumentException>(() => SemVersion.FromVersion(nonSemanticVersion));

Assert.Equal($"Version with Revision number can't be converted to SemVer.{NewLine}Parameter name: version", ex.Message);
Assert.StartsWith("Version with Revision number can't be converted to SemVer.", ex.Message);
Assert.Equal("version", ex.ParamName);
}

[Theory]
Expand Down Expand Up @@ -333,7 +334,8 @@ public void FromVersionNullTest()
{
var ex = Assert.Throws<ArgumentNullException>(() => SemVersion.FromVersion(null));

Assert.Equal($"Value cannot be null.{NewLine}Parameter name: version", ex.Message);
Assert.StartsWith("Value cannot be null.", ex.Message);
Assert.Equal("version", ex.ParamName);
}

[Theory]
Expand Down
20 changes: 3 additions & 17 deletions Semver.Test/Semver.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;net452</TargetFrameworks>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1;net452</TargetFrameworks>
<IsPackable>false</IsPackable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DebugType>portable</DebugType>
Expand All @@ -28,11 +28,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.3">
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.analyzers" Version="0.10.0" />
Expand All @@ -42,18 +42,4 @@
</PackageReference>
</ItemGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.1' ">
<DefineConstants>$(DefineConstants);NETSTANDARD</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net46' ">
<DefineConstants>$(DefineConstants);NET46</DefineConstants>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
<Reference Include="System.Runtime" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions Semver/PublicAPI/netstandard2.0/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading