Skip to content

Commit 28de6d6

Browse files
authored
[xtro] Improve AUTO_SANITIZE behavior. (#23394)
* Make it clear when logging that a failure was sanitized. * Fail if there were any failures that weren't sanitized.
1 parent 7759996 commit 28de6d6

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

tests/xtro-sharpie/xtro-sanity/Sanitizer.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static void NoFixedTodo ()
128128
if (!IsEntry (entry))
129129
continue;
130130
if (!specific.Contains (entry)) {
131-
Log ($"?fixed-todo? Entry '{entry}' in '{Path.GetFileName (file)}' is not found in corresponding '{Path.GetFileName (raw)}' file");
131+
LogSanitizable ($"?fixed-todo? Entry '{entry}' in '{Path.GetFileName (file)}' is not found in corresponding '{Path.GetFileName (raw)}' file");
132132
failures.Add (entry);
133133
}
134134
}
@@ -137,7 +137,7 @@ static void NoFixedTodo ()
137137
foreach (var entry in entries) {
138138
if (!IsEntry (entry))
139139
continue;
140-
Log ($"?fixed-todo? Entry '{entry}' in '{Path.GetFileName (file)}' might be fixed since there's no corresponding '{Path.GetFileName (raw)}' file");
140+
LogSanitizable ($"?fixed-todo? Entry '{entry}' in '{Path.GetFileName (file)}' might be fixed since there's no corresponding '{Path.GetFileName (raw)}' file");
141141
failures.Add (entry);
142142
}
143143
}
@@ -160,7 +160,7 @@ static void NoEmptyTodo ()
160160
if (!IsIncluded (file))
161161
continue;
162162
if (!(File.ReadLines (file).Count () > 0)) {
163-
Log ($"?empty-todo? File '{Path.GetFileName (file)}' is empty. Empty todo files should be removed.");
163+
LogSanitizable ($"?empty-todo? File '{Path.GetFileName (file)}' is empty. Empty todo files should be removed.");
164164
if (Autosanitize)
165165
File.Delete (file);
166166
}
@@ -177,6 +177,15 @@ public static void Log (string s)
177177
count++;
178178
}
179179

180+
public static void LogSanitizable (string s)
181+
{
182+
if (Autosanitize) {
183+
Console.WriteLine ($"(sanitized) {s}");
184+
return;
185+
}
186+
Log (s);
187+
}
188+
180189
public static int Main (string [] args)
181190
{
182191
directory = args.Length == 0 ? "." : args [0];
@@ -250,11 +259,11 @@ public static int Main (string [] args)
250259
var foundRaws = raws.Where (v => v.Entries.Contains (entry));
251260
var rawCount = foundRaws.Count ();
252261
if (rawCount == 0) {
253-
Log ($"?unknown-entry? {entry} in '{Path.Combine (directory, $"common-{fx}.ignore")}'");
262+
LogSanitizable ($"?unknown-entry? {entry} in '{Path.Combine (directory, $"common-{fx}.ignore")}'");
254263
unknownFailures.Add (entry);
255264
} else if (rawCount < GetPlatformCount (fx)) {
256265
var notFound = raws.Where (v => !v.Entries.Contains (entry));
257-
Log ($"?not-common? {entry} in '{Path.Combine (directory, $"common-{fx}.ignore")}': not in {string.Join (", ", notFound.Select (v => v.Platform))}");
266+
LogSanitizable ($"?not-common? {entry} in '{Path.Combine (directory, $"common-{fx}.ignore")}': not in {string.Join (", ", notFound.Select (v => v.Platform))}");
258267
unknownFailures.Add (entry);
259268
if (Autosanitize) {
260269
foreach (var nf in foundRaws) {
@@ -294,7 +303,7 @@ public static int Main (string [] args)
294303
continue;
295304
if (raws.Contains (entry))
296305
continue;
297-
Log ($"?unknown-entry? {entry} in '{shortname}'");
306+
LogSanitizable ($"?unknown-entry? {entry} in '{shortname}'");
298307
failures.Add (entry);
299308
}
300309
if (failures.Count > 0 && Autosanitize) {
@@ -327,8 +336,7 @@ public static int Main (string [] args)
327336

328337
// useful when updating stuff locally - we report but we don't fail
329338
var sanitizedOrSkippedSanity =
330-
!string.IsNullOrEmpty (Environment.GetEnvironmentVariable ("XTRO_SANITY_SKIP"))
331-
|| Autosanitize;
339+
!string.IsNullOrEmpty (Environment.GetEnvironmentVariable ("XTRO_SANITY_SKIP"));
332340
return sanitizedOrSkippedSanity ? 0 : count;
333341
}
334342

0 commit comments

Comments
 (0)