Skip to content

Use ITestOutputHelper instead of Console.WriteLine #371

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 1 commit into from
Feb 5, 2025
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
20 changes: 14 additions & 6 deletions assemblies-valid/AssembliesValid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Text;
using System.Text.RegularExpressions;
using Xunit;
using Xunit.Abstractions;

namespace AssembliesValid
{
Expand Down Expand Up @@ -40,30 +41,37 @@ public class AssembliesValid
new Regex("/packs/"),
};

private readonly ITestOutputHelper _output;

public AssembliesValid(ITestOutputHelper output)
{
_output = output;
}

[Fact]
public void ValidateAssemblies()
{
string dotnetPath = null;
int exitCode = RunProcessAndGetOutput(new string[] { "bash", "-c", "command -v dotnet" }, out dotnetPath);
if (exitCode != 0)
{
Console.Error.WriteLine("'dotnet' command not found");
Console.Error.WriteLine("PATH: " + Environment.GetEnvironmentVariable("PATH"));
_output.WriteLine("'dotnet' command not found");
_output.WriteLine("PATH: " + Environment.GetEnvironmentVariable("PATH"));
Assert.True(false);
}
dotnetPath = dotnetPath.Trim();
exitCode = RunProcessAndGetOutput(new string[] { "readlink", "-f", dotnetPath }, out dotnetPath);
if (exitCode != 0)
{
Console.Error.WriteLine($"Unable to run readlink -f {dotnetPath}");
_output.WriteLine($"Unable to run readlink -f {dotnetPath}");
Assert.True(false);
}
dotnetPath = dotnetPath.Trim();

string searchRoot = new FileInfo(dotnetPath).DirectoryName;
var searchRootDirectory = new System.IO.DirectoryInfo(searchRoot);

Console.WriteLine($"Searching for dotnet binaries in {searchRoot}");
_output.WriteLine($"Searching for dotnet binaries in {searchRoot}");

var architecture = RuntimeInformation.OSArchitecture;
var machine = GetCurrentMachine(architecture);
Expand Down Expand Up @@ -106,11 +114,11 @@ public void ValidateAssemblies()

if (valid)
{
Console.WriteLine($"{assembly}: OK");
_output.WriteLine($"{assembly}: OK");
}
else
{
Console.WriteLine($"error: {assembly} hasMethods: {hasMethods}, hasAot: {hasAot}, inReleaseMode: {inReleaseMode}");
_output.WriteLine($"error: {assembly} hasMethods: {hasMethods}, hasAot: {hasAot}, inReleaseMode: {inReleaseMode}");
allOkay = false;
}
}
Expand Down
16 changes: 12 additions & 4 deletions version-apis/VersionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,34 @@
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using Xunit;
using Xunit.Abstractions;

namespace DotNetCoreVersionApis
{
public class VersionTest
{
public static readonly int MAX_DOTNET_MAJOR_VERSION = 10;

private readonly ITestOutputHelper _output;

public VersionTest(ITestOutputHelper output)
{
_output = output;
}

[Fact]
public void EnvironmentVersion()
{
var version = Environment.Version;
Console.WriteLine($"Environment.Version: {version}");
_output.WriteLine($"Environment.Version: {version}");
Assert.InRange(version.Major, 3, MAX_DOTNET_MAJOR_VERSION);
}

[Fact]
public void RuntimeInformationFrameworkDescription()
{
var description = RuntimeInformation.FrameworkDescription;
Console.WriteLine($"RuntimeInformation.FrameworkDescription: {description}");
_output.WriteLine($"RuntimeInformation.FrameworkDescription: {description}");
Assert.StartsWith(".NET", description);
}

Expand All @@ -31,11 +39,11 @@ public void RuntimeInformationFrameworkDescription()
[InlineData("corefx", typeof(Uri))]
public void CommitHashesAreAvailable(string repo, Type type)
{
Console.WriteLine($"Testing commit hashes for {repo}");
_output.WriteLine($"Testing commit hashes for {repo}");

var attributes = (AssemblyInformationalVersionAttribute[])type.Assembly.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute),false);
var versionAttribute = attributes[0];
Console.WriteLine($"AssemblyInformationVersionAttribute: {versionAttribute.InformationalVersion}");
_output.WriteLine($"AssemblyInformationVersionAttribute: {versionAttribute.InformationalVersion}");

string[] versionParts = versionAttribute.InformationalVersion.Split("+");
Assert.Equal(2, versionParts.Length);
Expand Down