CleanupVerificationTask.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Collections;
  3. using System.IO;
  4. using System.Linq;
  5. using UnityEngine;
  6. namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
  7. {
  8. internal class CleanupVerificationTask : FileCleanupVerifierTaskBase
  9. {
  10. private const string k_Indent = " ";
  11. internal Action<object> logAction = Debug.LogWarning;
  12. public override IEnumerator Execute(TestJobData testJobData)
  13. {
  14. var currentFiles = GetAllFilesInAssetsDirectory();
  15. var existingFiles = testJobData.existingFiles;
  16. if (currentFiles.Length != existingFiles.Length)
  17. {
  18. LogWarningForFilesIfAny(currentFiles.Where(file => !testJobData.existingFiles.Contains(file)).ToArray());
  19. }
  20. yield return null;
  21. }
  22. private void LogWarningForFilesIfAny(string[] filePaths)
  23. {
  24. if (!filePaths.Any())
  25. {
  26. return;
  27. }
  28. var stringWriter = new StringWriter();
  29. stringWriter.WriteLine("Files generated by test without cleanup.");
  30. stringWriter.WriteLine(k_Indent + "Found {0} new files.", filePaths.Length);
  31. foreach (var filePath in filePaths)
  32. {
  33. stringWriter.WriteLine(k_Indent + filePath);
  34. }
  35. logAction(stringWriter.ToString());
  36. }
  37. }
  38. }