Skip to content

Commit

Permalink
Merge pull request #136 from magne/update-appveyor
Browse files Browse the repository at this point in the history
Update appveyor
  • Loading branch information
b3b00 authored Nov 27, 2019
2 parents fa8135c + 96da678 commit 0d75f92
Show file tree
Hide file tree
Showing 7 changed files with 505 additions and 47 deletions.
10 changes: 10 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project>

<ItemGroup Condition=" '$(LangVersion)' == '8.0' and '$(TargetFramework)' != 'netcoreapp3.0' " >
<Compile Include="$(MSBuildThisFileDirectory)/csharp8.0-polyfill/Index.cs" />
<Compile Include="$(MSBuildThisFileDirectory)/csharp8.0-polyfill/Range.cs" />
<Compile Include="$(MSBuildThisFileDirectory)/csharp8.0-polyfill/RuntimeHelpers.cs" />
<Compile Include="$(MSBuildThisFileDirectory)/csharp8.0-polyfill/NullableAttributes.cs" />
</ItemGroup>

</Project>
80 changes: 41 additions & 39 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,64 +1,66 @@
version: 1.0.{build}
image: Visual Studio 2017
init:
- cmd: ''

image:
- Ubuntu
- Visual Studio 2019

environment:
CONFIGURATION: Release
nugetKey:
secure: jlkQ4lJxiapfC87YZMljFZbeROpo26F7wbEB7q+xn5xWlAyfOvy/SNrji8a5uKap
codecovToken:
secure: tDNSMb2HRVQsJEgwVvuqY02+qgaKI3bw0LHSqplQKSPSRJNEkdCVnX352HoSht5t
COVERALLS_REPO_TOKEN:
secure: ntYxuZR1S4QagcvXJ+rXGhJoIw0Ln556M3h6PQEwaGr/41x+JazkKeRJ8DHzHODc
build_script:
- cmd: >-
dotnet tool install coveralls.net --version 1.0.0 --tool-path tools


# Instll coverall.net only on Windows
install:
- cmd: dotnet tool install coveralls.net --global --version 1.0.0

echo "tools\csmacnz.coveralls.exe --opencover -i ParserTests\coverage.opencover.xml --repoToken 4I3WBzHay1o8YwAH4xRskEHbi5w71atBP --commitBranch "%APPVEYOR_REPO_BRANCH%" --commitId "%APPVEYOR_REPO_COMMIT%" --commitAuthor "%APPVEYOR_REPO_COMMIT_AUTHOR%" --commitEmail "%APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL%" --jobId "%APPVEYOR_JOB_ID%" --useRelativePaths --basePath "%APPVEYOR_BUILD_FOLDER%"
dotnet restore

build_script:
- ps: dotnet build -c $env:CONFIGURATION

dotnet build -c Release

after_build:
- ps: dotnet pack -c $env:CONFIGURATION sly


# Run coverage on Windows
test_script:
- sh: dotnet test -c $CONFIGURATION --no-build
- cmd: dotnet test -c %CONFIGURATION% --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:exclude=\"[while]*,[expressionParser]*,[GenericLexerWithCallbacks]*,[jsonparser]*,[SimpleExpressionParser]*\" ParserTests/ParserTests.csproj

dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:exclude=\"[while]*,[expressionParser]*,[GenericLexerWithCallbacks]*,[jsonparser]*,[SimpleExpressionParser]*\" ParserTests/ParserTests.csproj

echo "############################"
# Publish coverage to Coverall on Windows
after_test:
- ps: |
if ($isWindows) {
csmacnz.Coveralls --opencover -i ./ParserTests/coverage.opencover.xml --repoToken 4I3WBzHay1o8YwAH4xRskEHbi5w71atBP --commitBranch "%APPVEYOR_REPO_BRANCH%" --commitId "%APPVEYOR_REPO_COMMIT%" --commitAuthor "%APPVEYOR_REPO_COMMIT_AUTHOR%" --commitEmail "%APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL%" --jobId "%APPVEYOR_JOB_ID%"
}
tools\csmacnz.coveralls.exe --opencover -i ./ParserTests/coverage.opencover.xml --repoToken 4I3WBzHay1o8YwAH4xRskEHbi5w71atBP --commitBranch "%APPVEYOR_REPO_BRANCH%" --commitId "%APPVEYOR_REPO_COMMIT%" --commitAuthor "%APPVEYOR_REPO_COMMIT_AUTHOR%" --commitEmail "%APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL%" --jobId "%APPVEYOR_JOB_ID%"
artifacts:
- path: sly/bin/$(CONFIGURATION)/*.nupkg
name: sly


echo "############################"
# Deploy nuget package from Windows
deploy:
- provider: NuGet
skip_symbols: true
api_key:
secure: jlkQ4lJxiapfC87YZMljFZbeROpo26F7wbEB7q+xn5xWlAyfOvy/SNrji8a5uKap
on:
branch: dev
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019


dotnet pack -c Release
test_script:
- ps: dotnet test ParserTests/ParserTests.csproj
artifacts:
- path: sly/bin/release/*
name: sly
- path: sly_coverage.xml
name: sly
- path: ParserTests/coverage.opencover.xml
name: sly
deploy:
- provider: NuGet
api_key:
secure: jlkQ4lJxiapfC87YZMljFZbeROpo26F7wbEB7q+xn5xWlAyfOvy/SNrji8a5uKap
skip_symbols: true
on:
branch: dev
notifications:
- provider: Email
to:
- [email protected]
on_build_success: true
on_build_failure: true
on_build_status_changed: true
- provider: Email
to:
- [email protected]
on_build_success: true
on_build_failure: true
on_build_status_changed: true
145 changes: 145 additions & 0 deletions csharp8.0-polyfill/Index.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// https://github.com/dotnet/corefx/blob/1597b894a2e9cac668ce6e484506eca778a85197/src/Common/src/CoreLib/System/Index.cs

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
using System.Runtime.CompilerServices;

namespace System
{
/// <summary>Represent a type can be used to index a collection either from the start or the end.</summary>
/// <remarks>
/// Index is used by the C# compiler to support the new index syntax
/// <code>
/// int[] someArray = new int[5] { 1, 2, 3, 4, 5 } ;
/// int lastElement = someArray[^1]; // lastElement = 5
/// </code>
/// </remarks>
internal readonly struct Index : IEquatable<Index>
{
private readonly int _value;

/// <summary>Construct an Index using a value and indicating if the index is from the start or from the end.</summary>
/// <param name="value">The index value. it has to be zero or positive number.</param>
/// <param name="fromEnd">Indicating if the index is from the start or from the end.</param>
/// <remarks>
/// If the Index constructed from the end, index value 1 means pointing at the last element and index value 0 means pointing at beyond last element.
/// </remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Index(int value, bool fromEnd = false)
{
if (value < 0)
{
throw new ArgumentOutOfRangeException(nameof(value), "value must be non-negative");
}

if (fromEnd)
_value = ~value;
else
_value = value;
}

// The following private constructors mainly created for perf reason to avoid the checks
private Index(int value)
{
_value = value;
}

/// <summary>Create an Index pointing at first element.</summary>
public static Index Start => new Index(0);

/// <summary>Create an Index pointing at beyond last element.</summary>
public static Index End => new Index(~0);

/// <summary>Create an Index from the start at the position indicated by the value.</summary>
/// <param name="value">The index value from the start.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Index FromStart(int value)
{
if (value < 0)
{
throw new ArgumentOutOfRangeException(nameof(value), "value must be non-negative");
}

return new Index(value);
}

/// <summary>Create an Index from the end at the position indicated by the value.</summary>
/// <param name="value">The index value from the end.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Index FromEnd(int value)
{
if (value < 0)
{
throw new ArgumentOutOfRangeException(nameof(value), "value must be non-negative");
}

return new Index(~value);
}

/// <summary>Returns the index value.</summary>
public int Value
{
get
{
if (_value < 0)
return ~_value;
else
return _value;
}
}

/// <summary>Indicates whether the index is from the start or the end.</summary>
public bool IsFromEnd => _value < 0;

/// <summary>Calculate the offset from the start using the giving collection length.</summary>
/// <param name="length">The length of the collection that the Index will be used with. length has to be a positive value</param>
/// <remarks>
/// For performance reason, we don't validate the input length parameter and the returned offset value against negative values.
/// we don't validate either the returned offset is greater than the input length.
/// It is expected Index will be used with collections which always have non negative length/count. If the returned offset is negative and
/// then used to index a collection will get out of range exception which will be same affect as the validation.
/// </remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int GetOffset(int length)
{
int offset = _value;
if (IsFromEnd)
{
// offset = length - (~value)
// offset = length + (~(~value) + 1)
// offset = length + value + 1

offset += length + 1;
}
return offset;
}

#pragma warning disable CS8632
/// <summary>Indicates whether the current Index object is equal to another object of the same type.</summary>
/// <param name="value">An object to compare with this object</param>
public override bool Equals(object? value) => value is Index && _value == ((Index)value)._value;
#pragma warning restore CS8632

/// <summary>Indicates whether the current Index object is equal to another Index object.</summary>
/// <param name="other">An object to compare with this object</param>
public bool Equals(Index other) => _value == other._value;

/// <summary>Returns the hash code for this instance.</summary>
public override int GetHashCode() => _value;

/// <summary>Converts integer number to an Index.</summary>
public static implicit operator Index(int value) => FromStart(value);

/// <summary>Converts the value of the current Index object to its equivalent string representation.</summary>
public override string ToString()
{
if (IsFromEnd)
return "^" + ((uint)Value).ToString();

return ((uint)Value).ToString();
}
}
}
Loading

0 comments on commit 0d75f92

Please sign in to comment.