@@ -39,20 +39,25 @@ public void Snapshot(string inputDirectory)
39
39
}
40
40
else
41
41
{
42
- var files = new List < string > ( ) ;
43
- RecursivelyListFiles ( outputDirectory , files ) ;
44
42
Assert . Multiple ( ( ) =>
45
43
{
44
+ var files = GitLsFiles ( outputDirectory ) ;
46
45
foreach ( var file in files )
47
46
{
47
+ if ( ! file . EndsWith ( ".cs" ) )
48
+ {
49
+ continue ;
50
+ }
51
+
48
52
var relativePath = Path . GetRelativePath ( outputDirectory , file ) ;
49
53
var obtained = snapshots . GetValueOrDefault ( relativePath , "" ) ;
50
54
var expected = File . ReadAllText ( file ) ;
51
55
var diff = DiffStrings ( obtained , expected ) ;
52
56
if ( diff . Length > 0 )
53
57
{
54
- Assert . Fail ( "(+ expected, - obtained). To update the expected output to match the obtained behavior, run: " +
55
- "SCIP_UPDATE_SNAPSHOTS=true dotnet test\n \n " + diff , file ) ;
58
+ Assert . Fail (
59
+ "(+ expected, - obtained). To update the expected output to match the obtained behavior, run: " +
60
+ "SCIP_UPDATE_SNAPSHOTS=true dotnet test\n \n " + diff , file ) ;
56
61
}
57
62
}
58
63
@@ -111,16 +116,6 @@ private static string[] ListSnapshotInputDirectories()
111
116
return Directory . GetDirectories ( inputs ) ;
112
117
}
113
118
114
- private static void RecursivelyListFiles ( string path , List < string > result )
115
- {
116
- if ( ! Directory . Exists ( path ) ) return ;
117
- result . AddRange ( Directory . GetFiles ( path ) ) ;
118
- foreach ( var directory in Directory . GetDirectories ( path ) )
119
- {
120
- RecursivelyListFiles ( directory , result ) ;
121
- }
122
- }
123
-
124
119
private static string IndexDirectory ( string directory )
125
120
{
126
121
var include = Environment . GetEnvironmentVariable ( "SCIP_INCLUDE" ) ;
@@ -151,6 +146,27 @@ private static string IndexDirectory(string directory)
151
146
return Path . Join ( directory , "index.scip" ) ;
152
147
}
153
148
149
+ private static string [ ] GitLsFiles ( string directory )
150
+ {
151
+ var process = new Process ( )
152
+ {
153
+ StartInfo = new ProcessStartInfo ( )
154
+ {
155
+ // The working directory of `dotnet test` is not the root directory of the project
156
+ // so we infer it by invoking `git rev-parse --show-toplevel`. It would be cleaner
157
+ // to get the root directory from MSBuild but I wasn't able to figure out how to do it
158
+ // after searching for ~20 minutes. This works for now and unblocks writing tests.
159
+ FileName = "git" ,
160
+ Arguments = "rev-parse --show-toplevel" ,
161
+ UseShellExecute = false ,
162
+ RedirectStandardOutput = true ,
163
+ WorkingDirectory = directory
164
+ }
165
+ } ;
166
+ process . Start ( ) ;
167
+ return process . StandardOutput . ReadToEnd ( ) . Trim ( ) . Split ( "\n " ) ;
168
+ }
169
+
154
170
private static string RootDirectory ( )
155
171
{
156
172
var process = new Process ( )
0 commit comments