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