|
1 | 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved.
|
2 | 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
3 | 3 |
|
4 |
| -using System.Reflection; |
5 | 4 | using FluentAssertions;
|
6 | 5 | using Xunit;
|
7 | 6 | using System.CommandLine.Parsing;
|
8 |
| -using static System.Runtime.InteropServices.JavaScript.JSType; |
9 | 7 |
|
10 |
| -namespace System.CommandLine.Subsystems.Tests |
| 8 | +namespace System.CommandLine.Subsystems.Tests; |
| 9 | + |
| 10 | +public class ErrorReportingSubsystemTests |
11 | 11 | {
|
12 |
| - public class ErrorReportingSubsystemTests |
| 12 | + [Fact] |
| 13 | + public void Report_when_single_error_writes_to_console_hack() |
13 | 14 | {
|
14 |
| - [Fact] |
15 |
| - public void Report_when_single_error_writes_to_console_hack() |
16 |
| - { |
17 |
| - var error = new ParseError("a sweet error message"); |
18 |
| - var errors = new List<ParseError> { error }; |
19 |
| - var errorSubsystem = new ErrorReportingSubsystem(); |
20 |
| - var consoleHack = new ConsoleHack().RedirectToBuffer(true); |
| 15 | + var error = new ParseError("a sweet error message"); |
| 16 | + var errors = new List<ParseError> { error }; |
| 17 | + var errorSubsystem = new ErrorReportingSubsystem(); |
| 18 | + var consoleHack = new ConsoleHack().RedirectToBuffer(true); |
21 | 19 |
|
22 |
| - errorSubsystem.Report(consoleHack, errors); |
| 20 | + errorSubsystem.Report(consoleHack, errors); |
23 | 21 |
|
24 |
| - consoleHack.GetBuffer().Trim().Should().Be(error.Message); |
25 |
| - } |
| 22 | + consoleHack.GetBuffer().Trim().Should().Be(error.Message); |
| 23 | + } |
26 | 24 |
|
27 |
| - [Fact] |
28 |
| - public void Report_when_multiple_error_writes_to_console_hack() |
29 |
| - { |
30 |
| - var error = new ParseError("a sweet error message"); |
31 |
| - var anotherError = new ParseError("another sweet error message"); |
32 |
| - var errors = new List<ParseError> { error, anotherError }; |
33 |
| - var errorSubsystem = new ErrorReportingSubsystem(); |
34 |
| - var consoleHack = new ConsoleHack().RedirectToBuffer(true); |
| 25 | + [Fact] |
| 26 | + public void Report_when_multiple_error_writes_to_console_hack() |
| 27 | + { |
| 28 | + var error = new ParseError("a sweet error message"); |
| 29 | + var anotherError = new ParseError("another sweet error message"); |
| 30 | + var errors = new List<ParseError> { error, anotherError }; |
| 31 | + var errorSubsystem = new ErrorReportingSubsystem(); |
| 32 | + var consoleHack = new ConsoleHack().RedirectToBuffer(true); |
35 | 33 |
|
36 |
| - errorSubsystem.Report(consoleHack, errors); |
| 34 | + errorSubsystem.Report(consoleHack, errors); |
37 | 35 |
|
38 |
| - consoleHack.GetBuffer().Trim().Should().Be($"{error.Message}\r\n{anotherError.Message}"); |
39 |
| - } |
| 36 | + consoleHack.GetBuffer().Trim().Should().Be($"{error.Message}{Environment.NewLine}{anotherError.Message}"); |
| 37 | + } |
40 | 38 |
|
41 |
| - [Fact] |
42 |
| - public void Report_when_no_errors_writes_nothing_to_console_hack() |
43 |
| - { |
44 |
| - var errors = new List<ParseError> { }; |
45 |
| - var errorSubsystem = new ErrorReportingSubsystem(); |
46 |
| - var consoleHack = new ConsoleHack().RedirectToBuffer(true); |
| 39 | + [Fact] |
| 40 | + public void Report_when_no_errors_writes_nothing_to_console_hack() |
| 41 | + { |
| 42 | + var errors = new List<ParseError> { }; |
| 43 | + var errorSubsystem = new ErrorReportingSubsystem(); |
| 44 | + var consoleHack = new ConsoleHack().RedirectToBuffer(true); |
47 | 45 |
|
48 |
| - errorSubsystem.Report(consoleHack, errors); |
| 46 | + errorSubsystem.Report(consoleHack, errors); |
49 | 47 |
|
50 |
| - consoleHack.GetBuffer().Trim().Should().Be(""); |
51 |
| - } |
| 48 | + consoleHack.GetBuffer().Trim().Should().Be(""); |
| 49 | + } |
52 | 50 |
|
53 |
| - [Theory] |
54 |
| - [InlineData("-v", false)] |
55 |
| - [InlineData("-x", true)] |
56 |
| - [InlineData("", false)] |
57 |
| - public void GetIsActivated_tests(string input, bool result) |
58 |
| - { |
59 |
| - var rootCommand = new CliRootCommand {new CliOption<bool>("-v")}; |
60 |
| - var configuration = new CliConfiguration(rootCommand); |
61 |
| - var errorSubsystem = new ErrorReportingSubsystem(); |
62 |
| - Subsystem.Initialize(errorSubsystem, configuration); |
| 51 | + [Theory] |
| 52 | + [InlineData("-v", false)] |
| 53 | + [InlineData("-x", true)] |
| 54 | + [InlineData("", false)] |
| 55 | + public void GetIsActivated_tests(string input, bool result) |
| 56 | + { |
| 57 | + var rootCommand = new CliRootCommand {new CliOption<bool>("-v")}; |
| 58 | + var configuration = new CliConfiguration(rootCommand); |
| 59 | + var errorSubsystem = new ErrorReportingSubsystem(); |
| 60 | + IReadOnlyList<string> args = [""]; |
| 61 | + Subsystem.Initialize(errorSubsystem, configuration, args); |
63 | 62 |
|
64 |
| - var parseResult = CliParser.Parse(rootCommand, input, configuration); |
65 |
| - var isActive = Subsystem.GetIsActivated(errorSubsystem, parseResult); |
| 63 | + var parseResult = CliParser.Parse(rootCommand, input, configuration); |
| 64 | + var isActive = Subsystem.GetIsActivated(errorSubsystem, parseResult); |
66 | 65 |
|
67 |
| - isActive.Should().Be(result); |
68 |
| - } |
| 66 | + isActive.Should().Be(result); |
69 | 67 | }
|
70 | 68 | }
|
0 commit comments