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