1
1
using System . IO ;
2
- using Xunit ;
3
- using Newtonsoft . Json ;
4
- using Newtonsoft . Json . Linq ;
5
2
using Dotnet . Script . DependencyModel . Environment ;
3
+ using Newtonsoft . Json . Linq ;
4
+ using Xunit ;
6
5
7
6
8
7
namespace Dotnet . Script . Tests
@@ -20,9 +19,10 @@ public ScaffoldingTests()
20
19
public void ShouldInitializeScriptFolder ( )
21
20
{
22
21
using ( var scriptFolder = new DisposableFolder ( ) )
23
- {
24
- var result = Execute ( "init" , scriptFolder . Path ) ;
25
- Assert . Equal ( 0 , result . exitCode ) ;
22
+ {
23
+ var ( output , exitCode ) = ScriptTestRunner . Default . Execute ( "init" , scriptFolder . Path ) ;
24
+
25
+ Assert . Equal ( 0 , exitCode ) ;
26
26
Assert . True ( File . Exists ( Path . Combine ( scriptFolder . Path , "main.csx" ) ) ) ;
27
27
Assert . True ( File . Exists ( Path . Combine ( scriptFolder . Path , "omnisharp.json" ) ) ) ;
28
28
Assert . True ( File . Exists ( Path . Combine ( scriptFolder . Path , ".vscode" , "launch.json" ) ) ) ;
@@ -34,9 +34,12 @@ public void ShouldCreateEnableScriptNugetReferencesSetting()
34
34
{
35
35
using ( var scriptFolder = new DisposableFolder ( ) )
36
36
{
37
- var result = Execute ( "init" , scriptFolder . Path ) ;
38
- Assert . Equal ( 0 , result . exitCode ) ;
37
+ var ( output , exitCode ) = ScriptTestRunner . Default . Execute ( "init" , scriptFolder . Path ) ;
38
+
39
+ Assert . Equal ( 0 , exitCode ) ;
40
+
39
41
dynamic settings = JObject . Parse ( File . ReadAllText ( Path . Combine ( scriptFolder . Path , "omnisharp.json" ) ) ) ;
42
+
40
43
Assert . True ( settings . script . enableScriptNuGetReferences . Value ) ;
41
44
}
42
45
}
@@ -46,9 +49,12 @@ public void ShouldCreateDefaultTargetFrameworkSetting()
46
49
{
47
50
using ( var scriptFolder = new DisposableFolder ( ) )
48
51
{
49
- var result = Execute ( "init" , scriptFolder . Path ) ;
52
+ var result = ScriptTestRunner . Default . Execute ( "init" , scriptFolder . Path ) ;
53
+
50
54
Assert . Equal ( 0 , result . exitCode ) ;
55
+
51
56
dynamic settings = JObject . Parse ( File . ReadAllText ( Path . Combine ( scriptFolder . Path , "omnisharp.json" ) ) ) ;
57
+
52
58
Assert . Equal ( _scriptEnvironment . TargetFramework , settings . script . defaultTargetFramework . Value ) ;
53
59
}
54
60
}
@@ -58,9 +64,9 @@ public void ShouldCreateNewScript()
58
64
{
59
65
using ( var scriptFolder = new DisposableFolder ( ) )
60
66
{
61
- var result = Execute ( "new script.csx" , scriptFolder . Path ) ;
62
-
63
- Assert . Equal ( 0 , result . exitCode ) ;
67
+ var ( output , exitCode ) = ScriptTestRunner . Default . Execute ( "new script.csx" , scriptFolder . Path ) ;
68
+
69
+ Assert . Equal ( 0 , exitCode ) ;
64
70
Assert . True ( File . Exists ( Path . Combine ( scriptFolder . Path , "script.csx" ) ) ) ;
65
71
}
66
72
}
@@ -70,9 +76,9 @@ public void ShouldCreateNewScriptWithExtension()
70
76
{
71
77
using ( var scriptFolder = new DisposableFolder ( ) )
72
78
{
73
- var result = Execute ( "new anotherScript" , scriptFolder . Path ) ;
74
-
75
- Assert . Equal ( 0 , result . exitCode ) ;
79
+ var ( output , exitCode ) = ScriptTestRunner . Default . Execute ( "new anotherScript" , scriptFolder . Path ) ;
80
+
81
+ Assert . Equal ( 0 , exitCode ) ;
76
82
Assert . True ( File . Exists ( Path . Combine ( scriptFolder . Path , "anotherScript.csx" ) ) ) ;
77
83
}
78
84
}
@@ -82,9 +88,9 @@ public void ShouldInitFolderWithCustomFileName()
82
88
{
83
89
using ( var scriptFolder = new DisposableFolder ( ) )
84
90
{
85
- var result = Execute ( "init custom.csx" , scriptFolder . Path ) ;
91
+ var ( output , exitCode ) = ScriptTestRunner . Default . Execute ( "init custom.csx" , scriptFolder . Path ) ;
86
92
87
- Assert . Equal ( 0 , result . exitCode ) ;
93
+ Assert . Equal ( 0 , exitCode ) ;
88
94
Assert . True ( File . Exists ( Path . Combine ( scriptFolder . Path , "custom.csx" ) ) ) ;
89
95
}
90
96
}
@@ -94,9 +100,9 @@ public void ShouldInitFolderWithCustomFileNameAndExtension()
94
100
{
95
101
using ( var scriptFolder = new DisposableFolder ( ) )
96
102
{
97
- var result = Execute ( "init anotherCustom" , scriptFolder . Path ) ;
103
+ var ( output , exitCode ) = ScriptTestRunner . Default . Execute ( "init anotherCustom" , scriptFolder . Path ) ;
98
104
99
- Assert . Equal ( 0 , result . exitCode ) ;
105
+ Assert . Equal ( 0 , exitCode ) ;
100
106
Assert . True ( File . Exists ( Path . Combine ( scriptFolder . Path , "anotherCustom.csx" ) ) ) ;
101
107
}
102
108
}
@@ -106,8 +112,8 @@ public void ShouldNotCreateDefaultFileForFolderWithExistingScriptFiles()
106
112
{
107
113
using ( var scriptFolder = new DisposableFolder ( ) )
108
114
{
109
- Execute ( "init custom.csx" , scriptFolder . Path ) ;
110
- Execute ( "init" , scriptFolder . Path ) ;
115
+ ScriptTestRunner . Default . Execute ( "init custom.csx" , scriptFolder . Path ) ;
116
+ ScriptTestRunner . Default . Execute ( "init" , scriptFolder . Path ) ;
111
117
Assert . False ( File . Exists ( Path . Combine ( scriptFolder . Path , "main.csx" ) ) ) ;
112
118
}
113
119
}
@@ -116,46 +122,21 @@ public void ShouldNotCreateDefaultFileForFolderWithExistingScriptFiles()
116
122
public void ShouldUpdatePathToDotnetScript ( )
117
123
{
118
124
using ( var scriptFolder = new DisposableFolder ( ) )
119
- {
120
- Execute ( "init" , scriptFolder . Path ) ;
125
+ {
126
+ ScriptTestRunner . Default . Execute ( "init" , scriptFolder . Path ) ;
121
127
var pathToLaunchConfiguration = Path . Combine ( scriptFolder . Path , ".vscode/launch.json" ) ;
122
128
var config = JObject . Parse ( File . ReadAllText ( pathToLaunchConfiguration ) ) ;
123
129
124
130
config . SelectToken ( "configurations[0].args[1]" ) . Replace ( "InvalidPath/dotnet-script.dll," ) ;
125
131
126
132
File . WriteAllText ( pathToLaunchConfiguration , config . ToString ( ) ) ;
127
133
128
- var result = Execute ( "init" , scriptFolder . Path ) ;
134
+ ScriptTestRunner . Default . Execute ( "init" , scriptFolder . Path ) ;
129
135
130
136
config = JObject . Parse ( File . ReadAllText ( pathToLaunchConfiguration ) ) ;
131
137
Assert . NotEqual ( "InvalidPath/dotnet-script.dll" , config . SelectToken ( "configurations[0].args[1]" ) . Value < string > ( ) ) ;
132
138
}
133
139
}
134
-
135
- /// <summary>
136
- /// Use this if you need to debug.
137
- /// </summary>
138
- private static int ExecuteInProcess ( params string [ ] args )
139
- {
140
- return Program . Main ( args ) ;
141
- }
142
-
143
- private ( string output , int exitCode ) Execute ( string args , string workingDirectory )
144
- {
145
- var result = ProcessHelper . RunAndCaptureOutput ( "dotnet" , GetDotnetScriptArguments ( args ) , workingDirectory ) ;
146
- return result ;
147
- }
148
-
149
- private string [ ] GetDotnetScriptArguments ( string args )
150
- {
151
- string configuration ;
152
- #if DEBUG
153
- configuration = "Debug" ;
154
- #else
155
- configuration = "Release" ;
156
- #endif
157
- return new [ ] { "exec" , Path . Combine ( Directory . GetCurrentDirectory ( ) , ".." , ".." , ".." , ".." , "Dotnet.Script" , "bin" , configuration , _scriptEnvironment . TargetFramework , "dotnet-script.dll" ) , args } ;
158
- }
159
140
}
160
141
161
142
}
0 commit comments