3
3
4
4
using FluentAssertions ;
5
5
using System . CommandLine . Tests . Utility ;
6
- using System . IO ;
7
- using System . Linq ;
8
6
using System . Text ;
9
7
using Xunit . Abstractions ;
10
8
using static System . Environment ;
11
9
using Process = System . CommandLine . Tests . Utility . Process ;
12
10
13
11
namespace System . CommandLine . Suggest . Tests
14
12
{
15
- public class DotnetSuggestEndToEndTests : IDisposable
13
+ public class DotnetSuggestEndToEndTests : TestsWithTestApps
16
14
{
17
- private readonly ITestOutputHelper _output ;
18
- private readonly FileInfo _endToEndTestApp ;
19
- private readonly FileInfo _dotnetSuggest ;
20
- private readonly ( string , string ) [ ] _environmentVariables ;
21
- private readonly DirectoryInfo _dotnetHostDir = DotnetMuxer . Path . Directory ;
22
- private static string _testRoot ;
23
-
24
- public DotnetSuggestEndToEndTests ( ITestOutputHelper output )
15
+ public DotnetSuggestEndToEndTests ( ITestOutputHelper output ) : base ( output )
25
16
{
26
- _output = output ;
27
-
28
- // delete sentinel files for EndToEndTestApp in order to trigger registration when it's run
29
- var sentinelsDir = new DirectoryInfo ( Path . Combine ( Path . GetTempPath ( ) , "system-commandline-sentinel-files" ) ) ;
30
-
31
- if ( sentinelsDir . Exists )
32
- {
33
- var sentinels = sentinelsDir . GetFiles ( "*EndToEndTestApp*" ) ;
34
-
35
- foreach ( var sentinel in sentinels )
36
- {
37
- sentinel . Delete ( ) ;
38
- }
39
- }
40
-
41
- var currentDirectory = Path . Combine (
42
- Directory . GetCurrentDirectory ( ) ,
43
- "TestAssets" ) ;
44
-
45
- _endToEndTestApp = new DirectoryInfo ( currentDirectory )
46
- . GetFiles ( "EndToEndTestApp" . ExecutableName ( ) )
47
- . SingleOrDefault ( ) ;
48
-
49
- _dotnetSuggest = new DirectoryInfo ( currentDirectory )
50
- . GetFiles ( "dotnet-suggest" . ExecutableName ( ) )
51
- . SingleOrDefault ( ) ;
52
-
53
- PrepareTestHomeDirectoryToAvoidPolluteBuildMachineHome ( ) ;
54
-
55
- _environmentVariables = new [ ] {
56
- ( "DOTNET_ROOT" , _dotnetHostDir . FullName ) ,
57
- ( "INTERNAL_TEST_DOTNET_SUGGEST_HOME" , _testRoot ) } ;
58
- }
59
-
60
- public void Dispose ( )
61
- {
62
- if ( _testRoot != null && Directory . Exists ( _testRoot ) )
63
- {
64
- Directory . Delete ( _testRoot , recursive : true ) ;
65
- }
66
- }
67
-
68
- private static void PrepareTestHomeDirectoryToAvoidPolluteBuildMachineHome ( )
69
- {
70
- _testRoot = Path . Combine ( Path . GetTempPath ( ) , Path . GetRandomFileName ( ) ) ;
71
- Directory . CreateDirectory ( _testRoot ) ;
72
17
}
73
18
74
19
[ ReleaseBuildOnlyFact ]
75
20
public void Test_app_supplies_suggestions ( )
76
21
{
77
22
var stdOut = new StringBuilder ( ) ;
78
-
23
+
24
+ Output . WriteLine ( $ "_endToEndTestApp.FullName: { EndToEndTestApp . FullName } ") ;
25
+
79
26
Process . RunToCompletion (
80
- _endToEndTestApp . FullName ,
27
+ EndToEndTestApp . FullName ,
81
28
"[suggest:1] \" a\" " ,
82
29
stdOut : value => stdOut . AppendLine ( value ) ,
83
- environmentVariables : _environmentVariables ) ;
30
+ environmentVariables : EnvironmentVariables ) ;
84
31
85
32
stdOut . ToString ( )
86
33
. Should ( )
@@ -92,26 +39,26 @@ public void Dotnet_suggest_provides_suggestions_for_app()
92
39
{
93
40
// run "dotnet-suggest register" in explicit way
94
41
Process . RunToCompletion (
95
- _dotnetSuggest . FullName ,
96
- $ "register --command-path \" { _endToEndTestApp . FullName } \" ",
97
- stdOut : s => _output . WriteLine ( s ) ,
98
- stdErr : s => _output . WriteLine ( s ) ,
99
- environmentVariables : _environmentVariables ) . Should ( ) . Be ( 0 ) ;
42
+ DotnetSuggest . FullName ,
43
+ $ "register --command-path \" { EndToEndTestApp . FullName } \" ",
44
+ stdOut : s => Output . WriteLine ( s ) ,
45
+ stdErr : s => Output . WriteLine ( s ) ,
46
+ environmentVariables : EnvironmentVariables ) . Should ( ) . Be ( 0 ) ;
100
47
101
48
var stdOut = new StringBuilder ( ) ;
102
49
var stdErr = new StringBuilder ( ) ;
103
50
104
51
var commandLineToComplete = "a" ;
105
52
106
53
Process . RunToCompletion (
107
- _dotnetSuggest . FullName ,
108
- $ "get -e \" { _endToEndTestApp . FullName } \" --position { commandLineToComplete . Length } -- \" { commandLineToComplete } \" ",
54
+ DotnetSuggest . FullName ,
55
+ $ "get -e \" { EndToEndTestApp . FullName } \" --position { commandLineToComplete . Length } -- \" { commandLineToComplete } \" ",
109
56
stdOut : value => stdOut . AppendLine ( value ) ,
110
57
stdErr : value => stdErr . AppendLine ( value ) ,
111
- environmentVariables : _environmentVariables ) ;
58
+ environmentVariables : EnvironmentVariables ) ;
112
59
113
- _output . WriteLine ( $ "stdOut:{ NewLine } { stdOut } { NewLine } ") ;
114
- _output . WriteLine ( $ "stdErr:{ NewLine } { stdErr } { NewLine } ") ;
60
+ Output . WriteLine ( $ "stdOut:{ NewLine } { stdOut } { NewLine } ") ;
61
+ Output . WriteLine ( $ "stdErr:{ NewLine } { stdErr } { NewLine } ") ;
115
62
116
63
stdErr . ToString ( )
117
64
. Should ( )
@@ -127,26 +74,26 @@ public void Dotnet_suggest_provides_suggestions_for_app_with_only_commandname()
127
74
{
128
75
// run "dotnet-suggest register" in explicit way
129
76
Process . RunToCompletion (
130
- _dotnetSuggest . FullName ,
131
- $ "register --command-path \" { _endToEndTestApp . FullName } \" ",
132
- stdOut : s => _output . WriteLine ( s ) ,
133
- stdErr : s => _output . WriteLine ( s ) ,
134
- environmentVariables : _environmentVariables ) . Should ( ) . Be ( 0 ) ;
77
+ DotnetSuggest . FullName ,
78
+ $ "register --command-path \" { EndToEndTestApp . FullName } \" ",
79
+ stdOut : s => Output . WriteLine ( s ) ,
80
+ stdErr : s => Output . WriteLine ( s ) ,
81
+ environmentVariables : EnvironmentVariables ) . Should ( ) . Be ( 0 ) ;
135
82
136
83
var stdOut = new StringBuilder ( ) ;
137
84
var stdErr = new StringBuilder ( ) ;
138
85
139
86
var commandLineToComplete = "a " ;
140
87
141
88
Process . RunToCompletion (
142
- _dotnetSuggest . FullName ,
143
- $ "get -e \" { _endToEndTestApp . FullName } \" --position { commandLineToComplete . Length } -- \" { commandLineToComplete } \" ",
89
+ DotnetSuggest . FullName ,
90
+ $ "get -e \" { EndToEndTestApp . FullName } \" --position { commandLineToComplete . Length } -- \" { commandLineToComplete } \" ",
144
91
stdOut : value => stdOut . AppendLine ( value ) ,
145
92
stdErr : value => stdErr . AppendLine ( value ) ,
146
- environmentVariables : _environmentVariables ) ;
93
+ environmentVariables : EnvironmentVariables ) ;
147
94
148
- _output . WriteLine ( $ "stdOut:{ NewLine } { stdOut } { NewLine } ") ;
149
- _output . WriteLine ( $ "stdErr:{ NewLine } { stdErr } { NewLine } ") ;
95
+ Output . WriteLine ( $ "stdOut:{ NewLine } { stdOut } { NewLine } ") ;
96
+ Output . WriteLine ( $ "stdErr:{ NewLine } { stdErr } { NewLine } ") ;
150
97
151
98
stdErr . ToString ( )
152
99
. Should ( )
@@ -156,5 +103,40 @@ public void Dotnet_suggest_provides_suggestions_for_app_with_only_commandname()
156
103
. Should ( )
157
104
. Be ( $ "--apple{ NewLine } --banana{ NewLine } --cherry{ NewLine } --durian{ NewLine } --help{ NewLine } --version{ NewLine } -?{ NewLine } -h{ NewLine } /?{ NewLine } /h{ NewLine } ") ;
158
105
}
106
+
107
+ [ ReleaseBuildOnlyFact ]
108
+ public void Dotnet_suggest_fails_to_provide_suggestions_because_app_faulted ( )
109
+ {
110
+ // run "dotnet-suggest register" in explicit way
111
+ Process . RunToCompletion (
112
+ DotnetSuggest . FullName ,
113
+ $ "register --command-path \" { WaitAndFailTestApp . FullName } \" ",
114
+ stdOut : s => Output . WriteLine ( s ) ,
115
+ stdErr : s => Output . WriteLine ( s ) ,
116
+ environmentVariables : EnvironmentVariables ) . Should ( ) . Be ( 0 ) ;
117
+
118
+ var stdOut = new StringBuilder ( ) ;
119
+ var stdErr = new StringBuilder ( ) ;
120
+
121
+ var commandLineToComplete = "a" ;
122
+
123
+ Process . RunToCompletion (
124
+ DotnetSuggest . FullName ,
125
+ $ "get -e \" { WaitAndFailTestApp . FullName } \" --position { commandLineToComplete . Length } -- \" { commandLineToComplete } \" ",
126
+ stdOut : value => stdOut . AppendLine ( value ) ,
127
+ stdErr : value => stdErr . AppendLine ( value ) ,
128
+ environmentVariables : EnvironmentVariables ) ;
129
+
130
+ Output . WriteLine ( $ "stdOut:{ NewLine } { stdOut } { NewLine } ") ;
131
+ Output . WriteLine ( $ "stdErr:{ NewLine } { stdErr } { NewLine } ") ;
132
+
133
+ stdErr . ToString ( )
134
+ . Should ( )
135
+ . BeEmpty ( ) ;
136
+
137
+ stdOut . ToString ( )
138
+ . Should ( )
139
+ . BeEmpty ( ) ;
140
+ }
159
141
}
160
142
}
0 commit comments