Skip to content
This repository was archived by the owner on Jul 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
5 changes: 1 addition & 4 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,9 @@ function Invoke-Tests() {
foreach ($test in $(Get-ChildItem $testFolder | ? { $_.PsIsContainer })) {
$csprojs = Get-ChildItem $test.FullName -Recurse | ? { $_.Extension -eq ".csproj" }
foreach ($proj in $csprojs) {
$trx = "$($proj.BaseName).$(Get-Date -Format "yyyy-MM-dd.hh_mm_ss").trx"
$fullpath = Join-Path $testResults $trx

Write-Host "Testing $($proj.Name). Output: $trx"

dotnet test "$($proj.FullName)" --configuration $Configuration --logger "trx;LogFileName=$fullpath" --no-build
dotnet test "$($proj.FullName)" --configuration $Configuration --logger "trx" --no-build
}
}
}
Expand Down
76 changes: 58 additions & 18 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ RootDir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DotNetSDKPath=$RootDir"/.tools/dotnet/"$DotNetSDKVersion
DotNetExe=$DotNetSDKPath"/dotnet"

TestResults=$RootDir"/TestResults"
BuildApps=true
RunTests=false

usage() {
echo "Usage: build.sh [-c|--configuration <Debug|Release>] [--downloadCatalog]"
echo "Usage: build.sh [-c|--configuration <Debug|Release>] [--downloadCatalog] [--runTests] [--no-build]"
}

downloadCatalog() {
Expand All @@ -39,6 +40,14 @@ downloadCatalog() {
}

installSDK() {
local dotnetPath=$(command -v dotnet)

if [[ $dotnetPath != "" ]]; then
echo "dotnet is found on PATH. using that."
DotNetExe=$dotnetPath
return 0
fi

if [[ -e $DotNetExe ]]; then
echo $DotNetExe" exists. Skipping install..."
return 0
Expand All @@ -53,33 +62,51 @@ installSDK() {
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel Current --install-dir $DotNetSDKPath
}

tryGetTargetFramework() {
local file=$1
local targetFramework=$(awk -F: '/<TargetFramework(s)?>.*netcoreapp[1-9]\.[0-9].*<\/TargetFramework(s)?>/ { print $0 }' $file | sed 's/.*\(netcoreapp[1-9]\.[0-9]\).*/\1/')
echo $targetFramework
}

build() {
echo "Building ApiPort... Configuration: ["$Configuration"]"

pushd src/ApiPort/ApiPort >/dev/null
$DotNetExe build ApiPort.csproj -f netcoreapp2.1 -c $Configuration
$DotNetExe build ApiPort.Offline.csproj -f netcoreapp2.1 -c $Configuration

local targetFramework=$(tryGetTargetFramework ApiPort.props)
echo "Building for: $targetFramework"

$DotNetExe build ApiPort.csproj -f $targetFramework -c $Configuration
$DotNetExe build ApiPort.Offline.csproj -f $targetFramework -c $Configuration
popd >/dev/null
}

runTest() {
ls $1/*.csproj | while read file; do
if awk -F: '/<TargetFramework>netcoreapp[1-9]\.[0-9]<\/TargetFramework>/ { found = 1 } END { if (found == 1) { exit 0 } else { exit 1 } }' $file; then
echo "Testing "$file
$DotNetExe test $file -c $Configuration --logger trx
else
# Can remove this when: https://github.com/dotnet/sdk/issues/335 is resolved
local targetFramework=$(tryGetTargetFramework $file)

if [[ $targetFramework == "" ]]; then
echo "Skipping "$file
echo "--- Desktop .NET Framework testing is not currently supported on Unix."
else
echo "Testing "$file
$DotNetExe test $file -c $Configuration --logger trx --framework $targetFramework --results-directory $2
fi
done
}

if [ ! -d $TestResults ]; then
mkdir $TestResults
findAndRunTests() {
local testResultsDirectory=$COMMON_TESTRESULTSDIRECTORY

if [[ $testResultsDirectory == "" ]]; then
testResultsDirectory=$RootDir/TestResults
echo "Results directory not specified, using $testResultsDirectory."
else
echo "Using common one set by build agent."
fi

find $RootDir/tests/ -type f -name "*.trx" | while read line; do
mv $line $TestResults/
find tests/ -type d -name "*\.Tests" | while read file; do
runTest $file $testResultsDirectory
done
}

Expand All @@ -94,6 +121,14 @@ while [[ $# -gt 0 ]]; do
Configuration="$2"
shift 2
;;
"--runtests")
RunTests=true
shift
;;
"--no-build")
BuildApps=false
shift
;;
"--downloadcatalog")
downloadCatalog "true"
exit 0
Expand Down Expand Up @@ -124,12 +159,17 @@ if [[ ! -e $DotNetExe ]]; then
exit 2
fi

downloadCatalog
if [[ $BuildApps == "true" ]]; then
downloadCatalog
build
fi

build
if [[ $RunTests == "true" ]]; then
if [[$BuildApps != "true" ]]; then
echo "WARNING: Not building applications because --no-build is set."
fi

find tests/ -type d -name "*\.Tests" | while read file; do
runTest $file
done
findAndRunTests
fi

echo "Finished!"
2 changes: 1 addition & 1 deletion tests/ApiPort/ApiPort.Tests/ApiPort.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFrameworks>netcoreapp2.1;net461</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net46</TargetFramework>
<TargetFrameworks>netcoreapp2.1;net461</TargetFrameworks>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<NonShipping>true</NonShipping>
Expand Down
21 changes: 15 additions & 6 deletions tests/lib/Microsoft.Fx.Portability.Cci.Tests/TestAssembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ namespace Microsoft.Fx.Portability.Cci.Tests
internal class TestAssembly
{
private const string TFM = @"[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute("".NETFramework,Version=v4.5.1"", FrameworkDisplayName = "".NET Framework 4.5.1"")]";
private static readonly string Mscorlib = typeof(object).GetTypeInfo().Assembly.Location;
private static readonly IEnumerable<string> DefaultReferences = new[]
{
typeof(object).Assembly.Location,
typeof(Console).Assembly.Location,

// Reference to System.Runtime.dll rather than System.Private.CoreLib on .NET Core
typeof(RuntimeReflectionExtensions).Assembly.Location
}.Distinct();

private readonly string _path;

private TestAssembly(string assemblyName, string text, IEnumerable<string> referencePaths)
Expand Down Expand Up @@ -56,7 +64,7 @@ public static string EmptyProject
get
{
var text = GetText("EmptyProject.cs");
return new TestAssembly("EmptyProject", text, new[] { Mscorlib }).Path;
return new TestAssembly("EmptyProject", text, DefaultReferences).Path;
}
}

Expand All @@ -65,7 +73,8 @@ public static string WithGenericsAndReference
get
{
var text = GetText("WithGenericsAndReference.cs");
return new TestAssembly("WithGenericsAndReference", text, new[] { Mscorlib, EmptyProject }).Path;
var references = DefaultReferences.Concat(new[] { EmptyProject });
return new TestAssembly("WithGenericsAndReference", text, references).Path;
}
}

Expand All @@ -76,9 +85,9 @@ private static string GetText(string fileName)
using (var stream = typeof(TestAssembly).GetTypeInfo().Assembly.GetManifestResourceStream(name))
{
using (var reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
{
return reader.ReadToEnd();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,17 @@ public ManagedMetadataReaderTests(ITestOutputHelper output)
[InlineData("OpImplicitMethod2Parameter.cs", "M:Microsoft.Fx.Portability.MetadataReader.Tests.OpImplicit_Method_2Parameter`1.op_Implicit(`0,`0)")]
[InlineData("OpExplicit.cs", "M:Microsoft.Fx.Portability.MetadataReader.Tests.Class2_OpExplicit`1.op_Explicit(Microsoft.Fx.Portability.MetadataReader.Tests.Class2_OpExplicit{`0})~Microsoft.Fx.Portability.MetadataReader.Tests.Class1_OpExplicit{`0}")]
[InlineData("NestedGenericTypesWithInvalidNames.cs", "M:Microsoft.Fx.Portability.MetadataReader.Tests.OtherClass.<GetValues>d__0`1.System#Collections#Generic#IEnumerable{System#Tuple{T@System#Int32}}#GetEnumerator")]
[InlineData("modopt.il", "M:TestClass.Foo(System.Int32 optmod System.Runtime.CompilerServices.IsConst)")]
[InlineData("modopt.il", "M:TestClass.Bar(System.SByte optmod System.Runtime.CompilerServices.IsConst reqmod System.Runtime.CompilerServices.IsSignUnspecifiedByte*)")]
[InlineData("NestedGenericTypes.cs", "M:OuterClass`2.InnerClass`2.InnerInnerClass.InnerInnerMethod(OuterClass{`3,`2}.InnerClass{System.Int32,`0}.InnerInnerClass)")]
[InlineData("NestedGenericTypes.cs", "M:OuterClass`2.InnerClass`2.InnerMethod(OuterClass{`2,`2}.InnerClass{`1,`1})")]
[InlineData("NestedGenericTypes.cs", "M:OuterClass`2.OuterMethod(`0,OuterClass{`1,`0}.InnerClass{`1,`0})")]

[Theory]
public void TestForDocId(string source, string docid)
{
TestForDocIdHelper(source, docid, false);
}

#if FEATURE_ILDASM
// IL can, bizarrely, define non-generic types that take generic paratmers
[InlineData("NonGenericTypesWithGenericParameters.il", "M:OuterClass.InnerClass.InnerMethod(OuterClass.InnerClass{`2,`2})")]
[InlineData("NonGenericTypesWithGenericParameters.il", "M:OuterClass.OuterMethod(`0,OuterClass.InnerClass{`1,`0,System.Object,`0})")]
Expand All @@ -45,12 +50,14 @@ public ManagedMetadataReaderTests(ITestOutputHelper output)
// This is not possible to construct in C#, but was being encoded incorrectly by the metadata reader parser.
[InlineData("NestedGenericTypes.il", "M:OuterClass`2.InnerClass`2.InnerMethod(OuterClass{`2,`2}.InnerClass`2)")]
[InlineData("NestedGenericTypes.il", "M:OuterClass`2.OuterMethod(`0,OuterClass{`1,`0}.InnerClass{`1,`0})")]

[InlineData("modopt.il", "M:TestClass.Foo(System.Int32 optmod System.Runtime.CompilerServices.IsConst)")]
[InlineData("modopt.il", "M:TestClass.Bar(System.SByte optmod System.Runtime.CompilerServices.IsConst reqmod System.Runtime.CompilerServices.IsSignUnspecifiedByte*)")]
[Theory]
public void TestForDocId(string source, string docid)
public void TestForDocIdIL(string source, string docid)
{
TestForDocIdHelper(source, docid, false);
}
#endif

[InlineData("Spec.cs", "T:N.X`1")]
[InlineData("Spec.cs", "M:N.X`1.#ctor")]
Expand Down Expand Up @@ -140,7 +147,9 @@ public void VerifyFilter()
.OrderBy(x => x, StringComparer.Ordinal);

var assemblyName = "FilterApis";
var filter = new AssemblyNameFilter(assemblyName);

// We want to recognize System.Console but not System.Uri.
var filter = new AssemblyNameFilter(assemblyName, new[] { "System.Console" });
var dependencyFinder = new ReflectionMetadataDependencyFinder(filter, new SystemObjectFinder(filter));
var assemblyToTest = TestAssembly.Create($"{assemblyName}.cs", _output);
var progressReporter = Substitute.For<IProgressReporter>();
Expand Down Expand Up @@ -240,6 +249,7 @@ public void ThrowsSystemObjectNotFoundException()
Assert.IsType<SystemObjectNotFoundException>(exception.InnerException);
}

#if FEATURE_ILDASM
[Fact]
public void AssemblyWithNoReferencesIsSkipped()
{
Expand All @@ -257,6 +267,7 @@ public void AssemblyWithNoReferencesIsSkipped()

Assert.Equal("NoReferences, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", assembly.AssemblyIdentity);
}
#endif

private static IEnumerable<Tuple<string, int>> EmptyProjectMemberDocId()
{
Expand Down Expand Up @@ -296,21 +307,37 @@ private static IEnumerable<Tuple<string, int>> EmptyProjectMemberDocId()

private class AssemblyNameFilter : IDependencyFilter
{
private static readonly HashSet<string> SystemObjectAssemblies = new HashSet<string>(StringComparer.Ordinal)
{
"mscorlib",
"netstandard",
"System.Private.CoreLib",
"System.Runtime"
};

private readonly string _assemblyName;
private readonly HashSet<string> _frameworkAssemblies;

public AssemblyNameFilter(string assemblyName)
public AssemblyNameFilter(string assemblyName, IEnumerable<string> frameworkAssemblies)
{
_assemblyName = assemblyName;
_assemblyName = assemblyName ?? throw new ArgumentNullException(nameof(assemblyName));
_frameworkAssemblies = new HashSet<string>(
frameworkAssemblies ?? Enumerable.Empty<string>(),
StringComparer.Ordinal);
}

public bool IsFrameworkAssembly(AssemblyReferenceInformation assembly)
{
var comparison = StringComparison.Ordinal;
var name = assembly?.Name;

var result = string.Equals(_assemblyName, name, comparison)
|| string.Equals("mscorlib", name, comparison)
|| string.Equals("System.Runtime", name, comparison);
if (string.IsNullOrEmpty(name))
{
return false;
}

var result = string.Equals(_assemblyName, name, StringComparison.Ordinal)
|| SystemObjectAssemblies.Contains(name)
|| _frameworkAssemblies.Contains(name);

return result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net46</TargetFramework>
<TargetFrameworks>net461;netcoreapp2.1</TargetFrameworks>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<NonShipping>true</NonShipping>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
</PropertyGroup>

<PropertyGroup Condition="$(TargetFramework) == 'net461'">
<!-- Need to specify RuntimeIdentifier in here because using
RuntimeIdentifiers will not copy native assets (ildasm) to the output.
folder.
TODO: ilasm exists on Linux but for some reason the assets are not copied
during dotnet test even when using RuntimeIdentifier. See:
https://github.com/dotnet/sdk/issues/2765 -->
<RuntimeIdentifier>win7-x86</RuntimeIdentifier>
<DefineConstants>$(DefineConstants);FEATURE_ILDASM</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public SystemObjectFinderTests(ITestOutputHelper output)
_output = output;
}

#if FEATURE_ILDASM
[Fact]
public void MultipleMscorlibReferencesFound()
{
Expand Down Expand Up @@ -114,5 +115,6 @@ public void LookInFilePassedInAssembly(string name)
}
}
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,18 @@ public StringAssemblyFile(string name, string contents)
private class CSharpCompileAssemblyFile : ResourceStreamAssemblyFile
{
private const string TFM = @"[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute("".NETFramework,Version=v4.5.1"", FrameworkDisplayName = "".NET Framework 4.5.1"")]";
private static readonly IEnumerable<MetadataReference> References = new[] { typeof(object).GetTypeInfo().Assembly.Location, typeof(Uri).GetTypeInfo().Assembly.Location, typeof(Console).GetTypeInfo().Assembly.Location }
.Distinct()
.Select(r => MetadataReference.CreateFromFile(r))
.ToList();
private static readonly IEnumerable<MetadataReference> References = new[]
{
typeof(object).GetTypeInfo().Assembly.Location,
typeof(Uri).GetTypeInfo().Assembly.Location,
typeof(Console).GetTypeInfo().Assembly.Location,

// Reference to System.Runtime.dll rather than System.Private.CoreLib on .NET Core
typeof(RuntimeReflectionExtensions).Assembly.Location
}
.Distinct()
.Select(r => MetadataReference.CreateFromFile(r))
.ToList();

private readonly bool _allowUnsafe;
private readonly IEnumerable<string> _additionalReferences;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFrameworks>netcoreapp2.1;net461</TargetFrameworks>
<NonShipping>true</NonShipping>
</PropertyGroup>

<!-- FxCop does not understand this target platform and will output the
following errors:
MSBUILD : error : CA0055 : Could not identify platform for 'bin\Debug\ApiPort\netcoreapp2.0\ApiPort.dll'
MSBUILD : error : CA0055 : Could not identify platform for 'bin\Debug\ApiPort\netcoreapp2.1\ApiPort.dll'
MSBUILD : error : CA0052 : No targets were selected.
-->
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
Expand Down
Loading