Advertisement
Guest User

better std.package unittest

a guest
Apr 29th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.13 KB | None | 0 0
  1. diff --git a/std/package.d b/std/package.d
  2. index 8298837c4..a4d44adc9 100644
  3. --- a/std/package.d
  4. +++ b/std/package.d
  5. @@ -28,7 +28,65 @@ module std;
  6.      assert(10.iota.map!(partial!(pow, 2)).sum == 1023);
  7.  }
  8.  
  9. +///Warning: EXTREMELY hacky code below.
  10. +unittest
  11. +{
  12. +    import std.file;
  13. +    import std.path;
  14. +    import std.array;
  15. +    import std.algorithm;
  16. +
  17. +    string[] importedPackages = import("package.d").splitLines
  18. +        .retro.until("//++=MARK=++//").array
  19. +        .map!"a.stripLeft[0 .. $-1]".array;
  20. +    string[][] modules;
  21. +    foreach (i; dirEntries(".", SpanMode.breadth))
  22. +    {
  23. +        string[] pathSections = pathSplitter(i.name)
  24. +            .retro.until("std", No.openRight).array.retro.array;
  25. +        if (i.attributes.attrIsFile && pathSections.canFind("std")
  26. +                && !pathSections.canFind("experimental")
  27. +                && !pathSections.canFind("internal")
  28. +                && !pathSections.canFind("windows")
  29. +                && pathSections != ["std", "package.d"])
  30. +        {
  31. +            pathSections[$-1] = pathSections[$-1][0 .. $-2];//strip ".d"
  32. +            modules ~= pathSections;
  33. +        }
  34. +    }
  35. +
  36. +    string[][] packageModules = modules.filter!`a[$-1] == "package"`.array;
  37. +    string[] uniqueModules;
  38. +
  39. +    foreach (i; modules)
  40. +    {
  41. +        bool included = false;
  42. +
  43. +        foreach (j; packageModules) {
  44. +            if (i.canFind(j[0 .. $-1]))
  45. +            {
  46. +                if (!uniqueModules.canFind(j[0 .. $-1].join(".")))
  47. +                    uniqueModules ~= j[0 .. $-1].join(".");
  48. +                included = true;
  49. +            }
  50. +        }
  51. +        if (!included)
  52. +            uniqueModules ~= i.join(".");
  53. +    }
  54. +
  55. +    bool notAllImported = false;
  56. +    foreach (i; uniqueModules)
  57. +    {
  58. +        if (!importedPackages.canFind(i)) {
  59. +            stderr.writeln(i, " is not imported in std.package.");
  60. +            notAllImported = true;
  61. +        }
  62. +    }
  63. +    assert(!notAllImported, "Not all modules are imported in std.package (see above messages).");
  64. +}
  65. +
  66.  public import
  67. +//++=MARK=++//
  68.   std.algorithm,
  69.   std.array,
  70.   std.ascii,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement