A game about forced loneliness, made by TACStudios
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.IO;
5using System.Linq;
6using UnityEngine;
7using UnityEngine.TestRunner.NUnitExtensions.Runner;
8
9namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
10{
11 internal class CleanupVerificationTask : FileCleanupVerifierTaskBase
12 {
13 private const string k_Indent = " ";
14
15 internal Action<object> logWarning = Debug.LogWarning;
16 internal Action<object> logError = Debug.LogError;
17
18 public override IEnumerator Execute(TestJobData testJobData)
19 {
20 var currentFiles = GetAllFilesInAssetsDirectory();
21 var existingFiles = testJobData.existingFiles;
22
23 if (currentFiles.Length != existingFiles.Length)
24 {
25 var existingFilesHashSet = new HashSet<string>(existingFiles);
26 var newFiles = currentFiles.Where(file => !existingFilesHashSet.Contains(file)).ToArray();
27 LogWarningForFilesIfAny(newFiles, testJobData.executionSettings.featureFlags.fileCleanUpCheck);
28 }
29
30 yield return null;
31 }
32
33 private void LogWarningForFilesIfAny(string[] filePaths, bool fileCleanUpCheck)
34 {
35 if (filePaths.Length == 0)
36 {
37 return;
38 }
39
40 var stringWriter = new StringWriter();
41 stringWriter.WriteLine("Files generated by test without cleanup.");
42 stringWriter.WriteLine(k_Indent + "Found {0} new files.", filePaths.Length);
43
44 foreach (var filePath in filePaths)
45 {
46 stringWriter.WriteLine(k_Indent + filePath);
47 }
48
49 if (fileCleanUpCheck)
50 {
51 logError(stringWriter.ToString());
52 }
53 else
54 {
55 logWarning(stringWriter.ToString());
56 }
57 }
58 }
59}