Skip to content

move to file scoped namespaces #2619

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
45 changes: 22 additions & 23 deletions src/System.CommandLine.ApiCompatibility.Tests/LocalizationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,35 @@
using System.Linq;
using Xunit;

namespace System.CommandLine.ApiCompatibility.Tests
namespace System.CommandLine.ApiCompatibility.Tests;

public class LocalizationTests
{
public class LocalizationTests
private const string CommandName = "the-command";

[Theory]
[InlineData("es", $"Falta el argumento requerido para el comando: '{CommandName}'.")]
[InlineData("en-US", $"Required argument missing for command: '{CommandName}'.")]
public void ErrorMessages_AreLocalized(string cultureName, string expectedMessage)
{
private const string CommandName = "the-command";
CultureInfo uiCultureBefore = CultureInfo.CurrentUICulture;

[Theory]
[InlineData("es", $"Falta el argumento requerido para el comando: '{CommandName}'.")]
[InlineData("en-US", $"Required argument missing for command: '{CommandName}'.")]
public void ErrorMessages_AreLocalized(string cultureName, string expectedMessage)
try
{
CultureInfo uiCultureBefore = CultureInfo.CurrentUICulture;
CultureInfo.CurrentUICulture = new CultureInfo(cultureName);

try
Command command = new(CommandName)
{
CultureInfo.CurrentUICulture = new CultureInfo(cultureName);

Command command = new(CommandName)
{
new Argument<string>("arg")
};
new Argument<string>("arg")
};

ParseResult parseResult = command.Parse(CommandName);
ParseResult parseResult = command.Parse(CommandName);

Assert.Equal(expectedMessage, parseResult.Errors.Single().Message);
}
finally
{
CultureInfo.CurrentUICulture = uiCultureBefore;
}
Assert.Equal(expectedMessage, parseResult.Errors.Single().Message);
}
finally
{
CultureInfo.CurrentUICulture = uiCultureBefore;
}
}
}
}
253 changes: 126 additions & 127 deletions src/System.CommandLine.Suggest.Tests/DotnetSuggestEndToEndTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,151 +10,150 @@
using static System.Environment;
using Process = System.CommandLine.Tests.Utility.Process;

namespace System.CommandLine.Suggest.Tests
namespace System.CommandLine.Suggest.Tests;

public class DotnetSuggestEndToEndTests : IDisposable
{
public class DotnetSuggestEndToEndTests : IDisposable
private readonly ITestOutputHelper _output;
private readonly FileInfo _endToEndTestApp;
private readonly FileInfo _dotnetSuggest;
private readonly (string, string)[] _environmentVariables;
private readonly DirectoryInfo _dotnetHostDir = DotnetMuxer.Path.Directory;
private static string _testRoot;

public DotnetSuggestEndToEndTests(ITestOutputHelper output)
{
private readonly ITestOutputHelper _output;
private readonly FileInfo _endToEndTestApp;
private readonly FileInfo _dotnetSuggest;
private readonly (string, string)[] _environmentVariables;
private readonly DirectoryInfo _dotnetHostDir = DotnetMuxer.Path.Directory;
private static string _testRoot;

public DotnetSuggestEndToEndTests(ITestOutputHelper output)
{
_output = output;
_output = output;

// delete sentinel files for EndToEndTestApp in order to trigger registration when it's run
var sentinelsDir = new DirectoryInfo(Path.Combine(Path.GetTempPath(), "system-commandline-sentinel-files"));
// delete sentinel files for EndToEndTestApp in order to trigger registration when it's run
var sentinelsDir = new DirectoryInfo(Path.Combine(Path.GetTempPath(), "system-commandline-sentinel-files"));

if (sentinelsDir.Exists)
{
var sentinels = sentinelsDir.GetFiles("*EndToEndTestApp*");
if (sentinelsDir.Exists)
{
var sentinels = sentinelsDir.GetFiles("*EndToEndTestApp*");

foreach (var sentinel in sentinels)
{
sentinel.Delete();
}
foreach (var sentinel in sentinels)
{
sentinel.Delete();
}
}

var currentDirectory = Path.Combine(
Directory.GetCurrentDirectory(),
"TestAssets");
var currentDirectory = Path.Combine(
Directory.GetCurrentDirectory(),
"TestAssets");

_endToEndTestApp = new DirectoryInfo(currentDirectory)
.GetFiles("EndToEndTestApp".ExecutableName())
.SingleOrDefault();
_endToEndTestApp = new DirectoryInfo(currentDirectory)
.GetFiles("EndToEndTestApp".ExecutableName())
.SingleOrDefault();

_dotnetSuggest = new DirectoryInfo(currentDirectory)
.GetFiles("dotnet-suggest".ExecutableName())
.SingleOrDefault();
_dotnetSuggest = new DirectoryInfo(currentDirectory)
.GetFiles("dotnet-suggest".ExecutableName())
.SingleOrDefault();

PrepareTestHomeDirectoryToAvoidPolluteBuildMachineHome();
PrepareTestHomeDirectoryToAvoidPolluteBuildMachineHome();

_environmentVariables = new[] {
("DOTNET_ROOT", _dotnetHostDir.FullName),
("INTERNAL_TEST_DOTNET_SUGGEST_HOME", _testRoot)};
}
_environmentVariables = new[] {
("DOTNET_ROOT", _dotnetHostDir.FullName),
("INTERNAL_TEST_DOTNET_SUGGEST_HOME", _testRoot)};
}

public void Dispose()
public void Dispose()
{
if (_testRoot != null && Directory.Exists(_testRoot))
{
if (_testRoot != null && Directory.Exists(_testRoot))
{
Directory.Delete(_testRoot, recursive: true);
}
Directory.Delete(_testRoot, recursive: true);
}
}

private static void PrepareTestHomeDirectoryToAvoidPolluteBuildMachineHome()
{
_testRoot = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
Directory.CreateDirectory(_testRoot);
}
private static void PrepareTestHomeDirectoryToAvoidPolluteBuildMachineHome()
{
_testRoot = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
Directory.CreateDirectory(_testRoot);
}

[ReleaseBuildOnlyFact]
public void Test_app_supplies_suggestions()
{
var stdOut = new StringBuilder();
[ReleaseBuildOnlyFact]
public void Test_app_supplies_suggestions()
{
var stdOut = new StringBuilder();

Process.RunToCompletion(
_endToEndTestApp.FullName,
"[suggest:1] \"a\"",
stdOut: value => stdOut.AppendLine(value),
environmentVariables: _environmentVariables);
Process.RunToCompletion(
_endToEndTestApp.FullName,
"[suggest:1] \"a\"",
stdOut: value => stdOut.AppendLine(value),
environmentVariables: _environmentVariables);

stdOut.ToString()
.Should()
.Be($"--apple{NewLine}--banana{NewLine}--durian{NewLine}");
}
stdOut.ToString()
.Should()
.Be($"--apple{NewLine}--banana{NewLine}--durian{NewLine}");
}

[ReleaseBuildOnlyFact]
public void Dotnet_suggest_provides_suggestions_for_app()
{
// run "dotnet-suggest register" in explicit way
Process.RunToCompletion(
_dotnetSuggest.FullName,
$"register --command-path \"{_endToEndTestApp.FullName}\"",
stdOut: s => _output.WriteLine(s),
stdErr: s => _output.WriteLine(s),
environmentVariables: _environmentVariables).Should().Be(0);

var stdOut = new StringBuilder();
var stdErr = new StringBuilder();

var commandLineToComplete = "a";

Process.RunToCompletion(
_dotnetSuggest.FullName,
$"get -e \"{_endToEndTestApp.FullName}\" --position {commandLineToComplete.Length} -- \"{commandLineToComplete}\"",
stdOut: value => stdOut.AppendLine(value),
stdErr: value => stdErr.AppendLine(value),
environmentVariables: _environmentVariables);

_output.WriteLine($"stdOut:{NewLine}{stdOut}{NewLine}");
_output.WriteLine($"stdErr:{NewLine}{stdErr}{NewLine}");

stdErr.ToString()
.Should()
.BeEmpty();

stdOut.ToString()
.Should()
.Be($"--apple{NewLine}--banana{NewLine}--durian{NewLine}");
}
[ReleaseBuildOnlyFact]
public void Dotnet_suggest_provides_suggestions_for_app()
{
// run "dotnet-suggest register" in explicit way
Process.RunToCompletion(
_dotnetSuggest.FullName,
$"register --command-path \"{_endToEndTestApp.FullName}\"",
stdOut: s => _output.WriteLine(s),
stdErr: s => _output.WriteLine(s),
environmentVariables: _environmentVariables).Should().Be(0);

var stdOut = new StringBuilder();
var stdErr = new StringBuilder();

var commandLineToComplete = "a";

Process.RunToCompletion(
_dotnetSuggest.FullName,
$"get -e \"{_endToEndTestApp.FullName}\" --position {commandLineToComplete.Length} -- \"{commandLineToComplete}\"",
stdOut: value => stdOut.AppendLine(value),
stdErr: value => stdErr.AppendLine(value),
environmentVariables: _environmentVariables);

_output.WriteLine($"stdOut:{NewLine}{stdOut}{NewLine}");
_output.WriteLine($"stdErr:{NewLine}{stdErr}{NewLine}");

stdErr.ToString()
.Should()
.BeEmpty();

stdOut.ToString()
.Should()
.Be($"--apple{NewLine}--banana{NewLine}--durian{NewLine}");
}

[ReleaseBuildOnlyFact]
public void Dotnet_suggest_provides_suggestions_for_app_with_only_commandname()
{
// run "dotnet-suggest register" in explicit way
Process.RunToCompletion(
_dotnetSuggest.FullName,
$"register --command-path \"{_endToEndTestApp.FullName}\"",
stdOut: s => _output.WriteLine(s),
stdErr: s => _output.WriteLine(s),
environmentVariables: _environmentVariables).Should().Be(0);

var stdOut = new StringBuilder();
var stdErr = new StringBuilder();

var commandLineToComplete = "a ";

Process.RunToCompletion(
_dotnetSuggest.FullName,
$"get -e \"{_endToEndTestApp.FullName}\" --position {commandLineToComplete.Length} -- \"{commandLineToComplete}\"",
stdOut: value => stdOut.AppendLine(value),
stdErr: value => stdErr.AppendLine(value),
environmentVariables: _environmentVariables);

_output.WriteLine($"stdOut:{NewLine}{stdOut}{NewLine}");
_output.WriteLine($"stdErr:{NewLine}{stdErr}{NewLine}");

stdErr.ToString()
.Should()
.BeEmpty();

stdOut.ToString()
.Should()
.Be($"--apple{NewLine}--banana{NewLine}--cherry{NewLine}--durian{NewLine}--help{NewLine}--version{NewLine}-?{NewLine}-h{NewLine}/?{NewLine}/h{NewLine}");
}
[ReleaseBuildOnlyFact]
public void Dotnet_suggest_provides_suggestions_for_app_with_only_commandname()
{
// run "dotnet-suggest register" in explicit way
Process.RunToCompletion(
_dotnetSuggest.FullName,
$"register --command-path \"{_endToEndTestApp.FullName}\"",
stdOut: s => _output.WriteLine(s),
stdErr: s => _output.WriteLine(s),
environmentVariables: _environmentVariables).Should().Be(0);

var stdOut = new StringBuilder();
var stdErr = new StringBuilder();

var commandLineToComplete = "a ";

Process.RunToCompletion(
_dotnetSuggest.FullName,
$"get -e \"{_endToEndTestApp.FullName}\" --position {commandLineToComplete.Length} -- \"{commandLineToComplete}\"",
stdOut: value => stdOut.AppendLine(value),
stdErr: value => stdErr.AppendLine(value),
environmentVariables: _environmentVariables);

_output.WriteLine($"stdOut:{NewLine}{stdOut}{NewLine}");
_output.WriteLine($"stdErr:{NewLine}{stdErr}{NewLine}");

stdErr.ToString()
.Should()
.BeEmpty();

stdOut.ToString()
.Should()
.Be($"--apple{NewLine}--banana{NewLine}--cherry{NewLine}--durian{NewLine}--help{NewLine}--version{NewLine}-?{NewLine}-h{NewLine}/?{NewLine}/h{NewLine}");
}
}
}
Loading