@@ -10,7 +10,7 @@ namespace Test.FAKECore
10
10
{
11
11
public class when_running_script
12
12
{
13
-
13
+
14
14
static string RunExplicit ( string scriptFilePath , string arguments , bool useCache )
15
15
{
16
16
var stdOut = Console . Out ;
@@ -19,8 +19,10 @@ static string RunExplicit(string scriptFilePath, string arguments, bool useCache
19
19
var outStream = new StringWriter ( sbOut ) ;
20
20
Console . SetOut ( outStream ) ;
21
21
Tuple < bool , Microsoft . FSharp . Collections . FSharpList < ProcessHelper . ConsoleMessage > > result ;
22
+
22
23
try
23
24
{
25
+
24
26
result = FSIHelper . executeBuildScriptWithArgsAndReturnMessages ( scriptFilePath , new string [ ] { } , useCache , false ) ;
25
27
}
26
28
finally
@@ -40,10 +42,14 @@ static string RunExplicit(string scriptFilePath, string arguments, bool useCache
40
42
Console . WriteLine ( x . Message ) ;
41
43
}
42
44
var messages = result . Item2 . Where ( x => ! x . IsError ) . Select ( x => x . Message ) ;
43
- return sbOut . ToString ( ) ;
45
+ return
46
+ sbOut . ToString ( )
47
+ . Replace ( "Running Buildscript: " + scriptFilePath , "" )
48
+ . Replace ( "\n " , "" ) . Replace ( "\r " , "" ) ;
44
49
}
45
50
46
- static string Run ( string script , string arguments , bool useCache ) {
51
+ static string Run ( string script , string arguments , bool useCache )
52
+ {
47
53
var scriptFilePath = Path . GetTempFileName ( ) + ".fsx" ;
48
54
string result ;
49
55
try
@@ -55,12 +61,14 @@ static string Run(string script, string arguments, bool useCache) {
55
61
{
56
62
File . Delete ( scriptFilePath ) ;
57
63
}
58
-
64
+
59
65
return result ;
60
66
}
61
67
62
68
static string nl = System . Environment . NewLine ;
63
- static Tuple < string , string > sc ( string path , string contents ) {
69
+
70
+ static Tuple < string , string > sc ( string path , string contents )
71
+ {
64
72
return new Tuple < string , string > ( path . Replace ( "\\ " , "/" ) , contents ) ;
65
73
}
66
74
@@ -73,32 +81,44 @@ static Tuple<string, string> sc(string path, string contents) {
73
81
try
74
82
{
75
83
File . WriteAllText ( scriptFilePath , "printf \" foobar\" " ) ;
76
- var scriptHash = FSIHelper . getScriptHash ( new Tuple < string , string > [ ] { sc ( scriptFilePath , "printf \" foobar\" " ) } ) ;
77
- var cacheFilePath = "./.fake/" + scriptFileName + "_" + scriptHash + ".dll" ;
84
+ var scriptHash =
85
+ FSIHelper . getScriptHash ( new Tuple < string , string > [ ] { sc ( scriptFilePath , "printf \" foobar\" " ) } ) ;
86
+
87
+ var cacheFilePath = Path . Combine ( "." , ".fake" , scriptFileName + "_" + scriptHash + ".dll" ) ;
78
88
79
89
File . Exists ( cacheFilePath ) . ShouldEqual ( false ) ;
80
90
81
- RunExplicit ( scriptFilePath , arguments , false ) . ShouldEqual ( "foobar" ) ;
91
+ RunExplicit ( scriptFilePath , arguments , false )
92
+ . ShouldEqual ( "foobar" ) ;
93
+
82
94
File . Exists ( cacheFilePath ) . ShouldEqual ( false ) ;
83
95
84
- RunExplicit ( scriptFilePath , arguments , true ) . ShouldEqual (
85
- "Cache doesnt exist" + nl + "foobar" + nl + "Saved cache" + nl ) ;
96
+ RunExplicit ( scriptFilePath , arguments , true )
97
+ . ShouldEqual (
98
+ ( "Cache doesnt exist" + nl + "foobar" + nl + "Saved cache" + nl )
99
+ . Replace ( "\n " , "" ) . Replace ( "\r " , "" ) ) ;
100
+
86
101
File . Exists ( cacheFilePath ) . ShouldEqual ( true ) ;
87
102
88
- RunExplicit ( scriptFilePath , arguments , true ) . ShouldEqual ( "Using cache" + nl + "foobar" ) ;
103
+ RunExplicit ( scriptFilePath , arguments , true )
104
+ . ShouldEqual (
105
+ ( "Using cache" + nl + "foobar" )
106
+ . Replace ( "\n " , "" ) . Replace ( "\r " , "" ) ) ;
89
107
90
108
File . WriteAllText ( scriptFilePath , "printf \" foobarbaz\" " ) ;
91
109
92
110
var changedScriptHash = FSIHelper . getScriptHash ( new Tuple < string , string > [ ] { sc ( scriptFilePath , "printf \" foobarbaz\" " ) } ) ;
93
- RunExplicit ( scriptFilePath , arguments , true ) . ShouldEqual ( "Cache is invalid, recompiling" + nl + "foobarbaz" + nl + "Saved cache" + nl ) ;
94
- //File.Exists(cacheFilePath).ShouldEqual(false);
95
- File . Exists ( "./.fake/" + scriptFileName + "_" + changedScriptHash + ".dll" ) . ShouldEqual ( true ) ;
111
+ RunExplicit ( scriptFilePath , arguments , true )
112
+ . ShouldEqual (
113
+ ( "Cache is invalid, recompiling" + nl + "foobarbaz" + nl + "Saved cache" + nl )
114
+ . Replace ( "\n " , "" ) . Replace ( "\r " , "" ) ) ;
96
115
116
+ File . Exists ( "./.fake/" + scriptFileName + "_" + changedScriptHash + ".dll" ) . ShouldEqual ( true ) ;
97
117
}
98
118
finally
99
119
{
100
- if ( File . Exists ( scriptFilePath ) ) File . Delete ( scriptFilePath ) ;
101
- //if (Directory.Exists("./.fake")) Directory .Delete("./.fake" );
120
+ if ( File . Exists ( scriptFilePath ) )
121
+ File . Delete ( scriptFilePath ) ;
102
122
}
103
123
} ;
104
124
@@ -109,19 +129,23 @@ static Tuple<string, string> sc(string path, string contents) {
109
129
var loadedPath = Path . GetTempFileName ( ) + ".fsx" ;
110
130
try
111
131
{
112
- var mainScript = "printf \" main\" \n #load \" " + loadedPath . ToString ( ) . Replace ( "\\ " , "/" ) + "\" " ;
132
+ var mainScript =
133
+ "printf \" main\" \n #load \" " +
134
+ loadedPath . ToString ( ) . Replace ( "\\ " , "/" ) + "\" " ;
113
135
var loadedScript = "printf \" loaded;\" " ;
114
- File . WriteAllText ( mainPath , mainScript ) ;
115
- File . WriteAllText ( loadedPath , loadedScript ) ;
136
+ File . WriteAllText ( mainPath , mainScript . Replace ( " \r \n " , " \n " ) . Replace ( " \r " , " \n " ) . Replace ( " \r " , nl ) ) ;
137
+ File . WriteAllText ( loadedPath , loadedScript . Replace ( " \r \n " , " \n " ) . Replace ( " \r " , " \n " ) . Replace ( " \r " , nl ) ) ;
116
138
117
- RunExplicit ( mainPath , "" , false ) . ShouldEqual ( "loaded;main" ) ;
139
+ RunExplicit ( mainPath , "" , false )
140
+ . ShouldEqual ( "loaded;main" ) ;
118
141
}
119
142
finally
120
143
{
121
- File . Delete ( mainPath ) ;
122
- File . Delete ( loadedPath ) ;
144
+ if ( File . Exists ( mainPath ) )
145
+ File . Delete ( mainPath ) ;
146
+ if ( File . Exists ( loadedPath ) )
147
+ File . Delete ( loadedPath ) ;
123
148
}
124
-
125
149
} ;
126
150
127
151
It should_change_hash_when_loaded_file_changes =
@@ -150,16 +174,17 @@ static Tuple<string, string> sc(string path, string contents) {
150
174
var hash = FSIHelper . getScriptHash ( scriptContents ) ;
151
175
152
176
File . WriteAllText ( lastPath , "printfn \" foobarbaz\" " ) ;
153
-
177
+
154
178
scriptContents = FSIHelper . getAllScripts ( mainPath ) ;
155
179
var newHash = FSIHelper . getScriptHash ( scriptContents ) ;
156
180
hash . ShouldNotEqual ( newHash ) ;
157
181
} ;
182
+
158
183
It should_get_included_assemblies =
159
184
( ) =>
160
185
{
161
- var script =
162
- "#r \" justname\" \n " +
186
+ var script =
187
+ "#r \" justname\" \n " +
163
188
"#r \" ./relative/path\" \n " +
164
189
"#r \" C:/absolute/path\" " ;
165
190
@@ -168,5 +193,4 @@ static Tuple<string, string> sc(string path, string contents) {
168
193
included . ShouldEqual ( new string [ ] { "justname" , "./relative/path" , "C:/absolute/path" } ) ;
169
194
} ;
170
195
}
171
-
172
- }
196
+ }
0 commit comments