1
- using Dotnet . Script . DependencyModel . Environment ;
1
+ using Dotnet . Script . Core ;
2
+ using Dotnet . Script . DependencyModel . Environment ;
3
+ using Dotnet . Script . DependencyModel . Logging ;
4
+ using Dotnet . Script . DependencyModel . Process ;
2
5
using System . IO ;
3
6
using Xunit ;
4
7
@@ -7,10 +10,12 @@ namespace Dotnet.Script.Tests
7
10
public class ScriptPublisherTests
8
11
{
9
12
private readonly ScriptEnvironment _scriptEnvironment ;
13
+ private readonly CommandRunner _commandRunner ;
10
14
11
15
public ScriptPublisherTests ( )
12
16
{
13
17
_scriptEnvironment = ScriptEnvironment . Default ;
18
+ _commandRunner = new CommandRunner ( GetLogFactory ( ) ) ;
14
19
}
15
20
16
21
[ Fact ]
@@ -22,9 +27,13 @@ public void SimplePublishTest()
22
27
var mainPath = Path . Combine ( scriptFolder . Path , "main.csx" ) ;
23
28
File . WriteAllText ( mainPath , code ) ;
24
29
var args = new string [ ] { "publish" , mainPath } ;
25
- var result = Execute ( string . Join ( " " , args ) , scriptFolder . Path ) ;
26
- Assert . Equal ( 0 , result . exitCode ) ;
27
- Assert . True ( File . Exists ( Path . Combine ( scriptFolder . Path , "publish" , "script.exe" ) ) ) ;
30
+ var publishResult = Execute ( string . Join ( " " , args ) , scriptFolder . Path ) ;
31
+ Assert . Equal ( 0 , publishResult . exitCode ) ;
32
+
33
+ var exePath = Path . Combine ( scriptFolder . Path , "publish" , "script" ) ;
34
+ var executableRunResult = _commandRunner . Execute ( exePath ) ;
35
+
36
+ Assert . Equal ( 0 , executableRunResult ) ;
28
37
}
29
38
}
30
39
@@ -38,9 +47,13 @@ public void SimplePublishToOtherFolderTest()
38
47
var mainPath = Path . Combine ( workspaceFolder . Path , "main.csx" ) ;
39
48
File . WriteAllText ( mainPath , code ) ;
40
49
var args = new string [ ] { "publish" , mainPath , "-o" , publishRootFolder . Path } ;
41
- var result = Execute ( string . Join ( " " , args ) , workspaceFolder . Path ) ;
42
- Assert . Equal ( 0 , result . exitCode ) ;
43
- Assert . True ( File . Exists ( Path . Combine ( publishRootFolder . Path , "script.exe" ) ) ) ;
50
+ var publishResult = Execute ( string . Join ( " " , args ) , workspaceFolder . Path ) ;
51
+ Assert . Equal ( 0 , publishResult . exitCode ) ;
52
+
53
+ var exePath = Path . Combine ( publishRootFolder . Path , "script" ) ;
54
+ var executableRunResult = _commandRunner . Execute ( exePath ) ;
55
+
56
+ Assert . Equal ( 0 , executableRunResult ) ;
44
57
}
45
58
}
46
59
@@ -53,9 +66,13 @@ public void SimplePublishFromCurrentDirectoryTest()
53
66
var mainPath = Path . Combine ( workspaceFolder . Path , "main.csx" ) ;
54
67
File . WriteAllText ( mainPath , code ) ;
55
68
var args = new string [ ] { "publish" , "main.csx" } ;
56
- var result = Execute ( string . Join ( " " , args ) , workspaceFolder . Path ) ;
57
- Assert . Equal ( 0 , result . exitCode ) ;
58
- Assert . True ( File . Exists ( Path . Combine ( workspaceFolder . Path , "publish" , "script.exe" ) ) ) ;
69
+ var publishResult = Execute ( string . Join ( " " , args ) , workspaceFolder . Path ) ;
70
+ Assert . Equal ( 0 , publishResult . exitCode ) ;
71
+
72
+ var exePath = Path . Combine ( workspaceFolder . Path , "publish" , "script" ) ;
73
+ var executableRunResult = _commandRunner . Execute ( exePath ) ;
74
+
75
+ Assert . Equal ( 0 , executableRunResult ) ;
59
76
}
60
77
}
61
78
@@ -68,9 +85,13 @@ public void SimplePublishFromCurrentDirectoryToOtherFolderTest()
68
85
var mainPath = Path . Combine ( workspaceFolder . Path , "main.csx" ) ;
69
86
File . WriteAllText ( mainPath , code ) ;
70
87
var args = new string [ ] { "publish" , "main.csx" , "-o" , "publish" } ;
71
- var result = Execute ( string . Join ( " " , args ) , workspaceFolder . Path ) ;
72
- Assert . Equal ( 0 , result . exitCode ) ;
73
- Assert . True ( File . Exists ( Path . Combine ( workspaceFolder . Path , "publish" , "script.exe" ) ) ) ;
88
+ var publishResult = Execute ( string . Join ( " " , args ) , workspaceFolder . Path ) ;
89
+ Assert . Equal ( 0 , publishResult . exitCode ) ;
90
+
91
+ var exePath = Path . Combine ( workspaceFolder . Path , "publish" , "script" ) ;
92
+ var executableRunResult = _commandRunner . Execute ( exePath ) ;
93
+
94
+ Assert . Equal ( 0 , executableRunResult ) ;
74
95
}
75
96
}
76
97
@@ -98,5 +119,21 @@ private string[] GetDotnetScriptArguments(string args)
98
119
#endif
99
120
return new [ ] { "exec" , Path . Combine ( Directory . GetCurrentDirectory ( ) , ".." , ".." , ".." , ".." , "Dotnet.Script" , "bin" , configuration , _scriptEnvironment . TargetFramework , "dotnet-script.dll" ) , args } ;
100
121
}
122
+
123
+ private LogFactory GetLogFactory ( )
124
+ {
125
+ var logger = new ScriptLogger ( ScriptConsole . Default . Error , true ) ;
126
+ return type => ( ( level , message ) =>
127
+ {
128
+ if ( level == LogLevel . Debug )
129
+ {
130
+ logger . Verbose ( message ) ;
131
+ }
132
+ if ( level == LogLevel . Info )
133
+ {
134
+ logger . Log ( message ) ;
135
+ }
136
+ } ) ;
137
+ }
101
138
}
102
139
}
0 commit comments