Skip to content

Add SBRPTests #689

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

Merged
merged 58 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
9cc191b
Add SBRPTests
Jun 1, 2023
341b5c0
Update
v-chayan Jun 5, 2023
a44a595
Generate package to sandbox instead of repo src
Jun 5, 2023
3317b3e
Optimize according to review comments
Jun 6, 2023
1d35990
Update
Jun 7, 2023
c059ae8
Merge branch 'main' into AddSBRPTests
v-chayan Jun 7, 2023
a02a301
Integrate tests into pipline
v-chayan Jun 12, 2023
71b62ef
Fix running tests on Windows
v-chayan Jun 13, 2023
53e47a4
Test in Pipeline attemption
v-chayan Jun 13, 2023
58b7d1f
update
v-chayan Jun 13, 2023
538c64e
update
v-chayan Jun 13, 2023
cea8a98
Fix job name
v-chayan Jun 14, 2023
2a1f106
update
v-chayan Jun 14, 2023
40fc1ef
update
v-chayan Jun 14, 2023
a3872d2
update
v-chayan Jun 14, 2023
1adf0df
update
v-chayan Jun 14, 2023
aa62bdf
Fix issue
v-chayan Jun 14, 2023
4bcddb2
update
v-chayan Jun 14, 2023
3a6fba1
update
v-chayan Jun 14, 2023
0d872fc
update
v-chayan Jun 14, 2023
02d53cf
update
v-chayan Jun 14, 2023
33602f9
update
v-chayan Jun 14, 2023
e34b359
update
v-chayan Jun 15, 2023
c432dd9
update
v-chayan Jun 15, 2023
0912d12
update
v-chayan Jun 15, 2023
0f2ed6d
update
v-chayan Jun 15, 2023
f04f238
update
v-chayan Jun 15, 2023
73b6e40
fix test issue in pipeline
v-chayan Jun 15, 2023
f69df98
update
v-chayan Jun 15, 2023
d3e1b9e
update
v-chayan Jun 15, 2023
e743a20
update
v-chayan Jun 15, 2023
754dbf9
update
v-chayan Jun 15, 2023
dc6648d
update
v-chayan Jun 16, 2023
b46422c
update
v-chayan Jun 16, 2023
27d9b9e
update
v-chayan Jun 16, 2023
977d4cc
update
v-chayan Jun 16, 2023
e40b86b
update
v-chayan Jun 16, 2023
549cd50
update
v-chayan Jun 16, 2023
9c88d76
update
v-chayan Jun 16, 2023
9737cc4
update
v-chayan Jun 16, 2023
3d3398c
update
v-chayan Jun 16, 2023
3f89c4d
update
v-chayan Jun 16, 2023
79ac625
update
v-chayan Jun 16, 2023
6b0169c
update
v-chayan Jun 16, 2023
87aaf62
Merge branch 'main' into AddSBRPTests
v-chayan Jun 20, 2023
eaaf94a
Use git diff for comparison
Jun 26, 2023
638f270
Merge branch 'main' into AddSBRPTests
v-chayan Jun 29, 2023
33c0c0d
update
v-chayan Jun 29, 2023
17f7633
update
Jun 29, 2023
e93b6ef
undo incorrect change
v-chayan Jul 7, 2023
d1dfd1c
Merge branch 'main' into AddSBRPTests
v-chayan Jul 7, 2023
9af641e
Update
Winniexu01 Jul 25, 2023
4515e0f
Update
Winniexu01 Jul 25, 2023
3fb54d4
Update
Winniexu01 Aug 2, 2023
3695786
Generate latest text package
Winniexu01 Aug 2, 2023
86c602f
Delete icon file
Winniexu01 Aug 3, 2023
e88cc70
Revert "Delete icon file"
Winniexu01 Aug 3, 2023
78d36af
Merge branch 'main' into AddSBRPTests
Winniexu01 Aug 3, 2023
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
3 changes: 3 additions & 0 deletions azure-pipelines/builds/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ stages:
artifacts: true
manifests: true
enableSourceBuild: true
- template: /azure-pipelines/builds/generatescript-tests.yml
parameters:
buildConfiguration: Debug

# Based on - https://github.com/dotnet/arcade/blob/9b3f304c7bc9fd4d11be9ca0b466b83e98d2a191/Documentation/CorePackages/Publishing.md#moving-away-from-the-legacy-pushtoblobfeed-task
- ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}:
Expand Down
37 changes: 37 additions & 0 deletions azure-pipelines/builds/generatescript-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
parameters:
- name: buildConfiguration
type: string
values:
- Debug
- Release

jobs:
- job:
strategy:
matrix:
Windows_NT:
agentOs: Windows_NT
imageName: "windows-latest"
Linux:
agentOs: Linux
imageName: "ubuntu-latest"
pool:
vmImage: $(imageName)

steps:
- checkout: self
clean: true
- script: $(Build.SourcesDirectory)/test.cmd
displayName: Windows NT GenerateScript Tests
condition: eq(variables.agentOs, 'Windows_NT')
- script: $(Build.SourcesDirectory)/test.sh
displayName: Linux GenerateScript Tests
condition: eq(variables.agentOs, 'Linux')
- task: PublishTestResults@2
displayName: Publish Test Results
inputs:
testRunner: xUnit
testResultsFiles: 'artifacts/TestResults/${{ parameters.buildConfiguration }}/*.xml'
testRunTitle: '$(agentOs)_GenerateScript_tests'
configuration: '${{ parameters.buildConfiguration }}'
condition: always()
8 changes: 6 additions & 2 deletions eng/Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
<ProjectToBuild Include="$(RepoRoot)src\packageSourceGenerator\PackageSourceGenerator.proj" />
</ItemGroup>

<ItemGroup Condition="'$(GeneratePackageSource)' != 'true'">
<ItemGroup Condition="'$(Test)' == 'true'">
<ProjectToBuild Include="$(RepoRoot)tests\GenerateScriptTests\GenerateScript.Tests.csproj" Test="$(Test)" />
</ItemGroup>

<ItemGroup Condition="'$(GeneratePackageSource)' != 'true' and '$(Test)' != 'true'">
<!--
The following DependencyPackageProjects are ones on which other packages depend on that do
not exist in the source-build package cache. Adding them to this ItemGroup will ensure that
Expand Down Expand Up @@ -79,7 +83,7 @@
DestinationFolder="$(LocalNuGetPackageCacheDirectory)" />
</Target>

<ItemGroup Condition="'$(GeneratePackageSource)' != 'true' and '$(BuildDependencyPackageProjects)' != 'true'">
<ItemGroup Condition="'$(GeneratePackageSource)' != 'true' and '$(BuildDependencyPackageProjects)' != 'true' and '$(Test)' != 'true'">
<TargetingPackageProject Include="$(RepoRoot)src\targetPacks\ILsrc\**\*.csproj" />
<ProjectToBuild Include="@(TargetingPackageProject)" />

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

<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<AssemblyName>Microsoft.Build.NoTargets</AssemblyName>
<ProjectTemplateVersion>2</ProjectTemplateVersion>
</PropertyGroup>

</Project>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>Microsoft.Build.NoTargets</id>
<version>3.7.0</version>
<authors>Microsoft</authors>
<license type="expression">MIT</license>
<licenseUrl>https://licenses.nuget.org/MIT</licenseUrl>
<icon>MSBuild-NuGet-Icon.png</icon>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This icon file should be deleted.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried deleting the icon file, but the test failed. Because the icon file is still generated by the latest tooling. So I reverted the change and kept the icon file.

<projectUrl>https://github.com/Microsoft/MSBuildSdks</projectUrl>
<description>Provides targets for projects that do not compile an assembly.</description>
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
Expand All @@ -16,7 +15,6 @@
</packageTypes>
<repository url="https://github.com/Microsoft/MSBuildSdks.git" />
<dependencies>
<group targetFramework=".NETFramework4.0" />
<group targetFramework=".NETStandard2.0" />
</dependencies>
</metadata>
Expand Down
2 changes: 2 additions & 0 deletions test.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
powershell -ExecutionPolicy ByPass -NoProfile -command "& """%~dp0eng\common\Build.ps1""" -restore -build -test %*"
21 changes: 21 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

source="${BASH_SOURCE[0]}"

# resolve $SOURCE until the file is no longer a symlink
while [[ -h $source ]]; do
scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
source="$(readlink "$source")"

# if $source was a relative symlink, we need to resolve it relative to the path where the
# symlink file was located
[[ $source != /* ]] && source="$scriptroot/$source"
done

scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"

export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
export DOTNET_MULTILEVEL_LOOKUP=0

"$scriptroot/eng/common/build.sh" --restore --build --test "$@"
119 changes: 119 additions & 0 deletions tests/GenerateScriptTests/ExecuteHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Xunit.Abstractions;

namespace GenerateScriptTests;

internal static class ExecuteHelper
{
public static (Process Process, string StdOut, string StdErr) ExecuteProcess(
string fileName,
string args,
ITestOutputHelper outputHelper,
bool logOutput = false,
Action<Process>? configure = null,
int millisecondTimeout = -1)
{
outputHelper.WriteLine($"Executing: {fileName} {args}");

Process process = new()
{
EnableRaisingEvents = true,
StartInfo =
{
FileName = fileName,
Arguments = args,
RedirectStandardOutput = true,
RedirectStandardError = true,
}
};

configure?.Invoke(process);

StringBuilder stdOutput = new();
process.OutputDataReceived += new DataReceivedEventHandler(
(sender, e) =>
{
lock (stdOutput)
{
stdOutput.AppendLine(e.Data);
}
});

StringBuilder stdError = new();
process.ErrorDataReceived += new DataReceivedEventHandler(
(sender, e) =>
{
lock (stdError)
{
stdError.AppendLine(e.Data);
}
});

process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit(millisecondTimeout);

if (!process.HasExited)
{
outputHelper.WriteLine($"Process did not exit. Killing {fileName} {args} after waiting {millisecondTimeout} milliseconds.");
process.Kill(true);
process.WaitForExit();
}

string output;
string error;

lock (stdOutput)
{
output = stdOutput.ToString().Trim();
}

lock (stdError)
{
error = stdError.ToString().Trim();
}

if (logOutput)
{
if (!string.IsNullOrWhiteSpace(output))
{
outputHelper.WriteLine(output);
}

if (string.IsNullOrWhiteSpace(error))
{
outputHelper.WriteLine(error);
}
}

return (process, output, error);
}

public static string ExecuteProcessValidateExitCode(string fileName, string args, ITestOutputHelper outputHelper)
{
(Process Process, string StdOut, string StdErr) result = ExecuteHelper.ExecuteProcess(fileName, args, outputHelper);
ValidateExitCode(result);

return result.StdOut;
}

public static void ValidateExitCode((Process Process, string StdOut, string StdErr) result, int expectedExitCode = 0)
{
if (result.Process.ExitCode != expectedExitCode)
{
ProcessStartInfo startInfo = result.Process.StartInfo;
string msg = $"Failed to execute {startInfo.FileName} {startInfo.Arguments}" +
$"{Environment.NewLine}Exit code: {result.Process.ExitCode}" +
$"{Environment.NewLine}{result.StdOut}" +
$"{Environment.NewLine}{result.StdErr}";
throw new InvalidOperationException(msg);
}
}
}
8 changes: 8 additions & 0 deletions tests/GenerateScriptTests/GenerateScript.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(NetCurrent)</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
65 changes: 65 additions & 0 deletions tests/GenerateScriptTests/GenerateScriptTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using Xunit;
using Xunit.Abstractions;

namespace GenerateScriptTests;

public class GenerateScriptTests
{
public enum PackageType
{
Reference,
Text
}

public static IEnumerable<object[]> Data => new List<object[]>
{
new object[] { "System.Xml.ReaderWriter", "4.0.11", PackageType.Reference },
new object[] { "Microsoft.Extensions.Logging.Abstractions", "7.0.1", PackageType.Reference },
new object[] { "Microsoft.CodeAnalysis.CSharp", "3.11.0", PackageType.Reference },
new object[] { "System.Security.Cryptography.Pkcs", "7.0.2", PackageType.Reference },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be validating text only packages as well. All the test infrastructure was defined but no test data for them were added.

Suggested change
new object[] { "System.Security.Cryptography.Pkcs", "7.0.2", PackageType.Reference },
new object[] { "System.Security.Cryptography.Pkcs", "7.0.2", PackageType.Reference },
new object[] { "Microsoft.Build.NoTargets", "3.7.0", PackageType.Text },

new object[] { "Microsoft.Build.NoTargets", "3.7.0", PackageType.Text },
};

public string SandboxDirectory { get; set; }
public string RepoRoot { get; set; }
public ITestOutputHelper output { get; set; }

public GenerateScriptTests(ITestOutputHelper output)
{
this.output = output;
RepoRoot = Environment.CurrentDirectory.Substring(0, Environment.CurrentDirectory.IndexOf("artifacts"));
SandboxDirectory = Path.Combine(Environment.CurrentDirectory, $"GenerateTests-{DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString()}");
Directory.CreateDirectory(SandboxDirectory);
}

[Theory]
[MemberData(nameof(GenerateScriptTests.Data), MemberType = typeof(GenerateScriptTests))]
public void VerifyGenerateScript(string package, string version, PackageType type)
{
string command = Path.Combine(RepoRoot, RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "generate.cmd" : "generate.sh");
string arguments = $"-p {package},{version} -x -d {SandboxDirectory}";
string packageSrcDirectory = string.Empty;
string sandboxPackageGeneratedDirecotry = Path.Combine(SandboxDirectory, package.ToLower(), version);

switch (type)
{
case PackageType.Reference:
packageSrcDirectory = Path.Combine(RepoRoot, "src", "referencePackages", "src", package.ToLower(), version);
break;
case PackageType.Text:
arguments += " -t text";
packageSrcDirectory = Path.Combine(RepoRoot, "src", "textOnlyPackages", "src", package.ToLower(), version);
break;
}

ExecuteHelper.ExecuteProcess(command, arguments, output);
Assert.Empty(ExecuteHelper.ExecuteProcess("git", $"diff --no-index {packageSrcDirectory} {sandboxPackageGeneratedDirecotry}", output, true).StdOut);
}
}