Newer
Older
dub_jkp / test / run-unittest.d
@Jan Jurzitza Jan Jurzitza on 15 Feb 2022 2 KB Fix interactive run-unittest.d
  1. #!/usr/bin/env dub
  2. /+dub.sdl:
  3. name: run_unittest
  4. targetName: run-unittest
  5. dependency "common" path="./common"
  6. +/
  7. module run_unittest;
  8.  
  9. import common;
  10.  
  11. int main(string[] args)
  12. {
  13. import std.algorithm : among, endsWith;
  14. import std.file : dirEntries, DirEntry, exists, getcwd, readText, SpanMode;
  15. import std.format : format;
  16. import std.stdio : File, writeln;
  17. import std.path : absolutePath, buildNormalizedPath, baseName, dirName;
  18. import std.process : environment, spawnProcess, wait;
  19.  
  20. //** if [ -z ${DUB:-} ]; then
  21. //** die $LINENO 'Variable $DUB must be defined to run the tests.'
  22. //** fi
  23. auto dub = environment.get("DUB", "");
  24. if (dub == "")
  25. {
  26. logError(`Environment variable "DUB" must be defined to run the tests.`);
  27. return 1;
  28. }
  29.  
  30. //** if [ -z ${DC:-} ]; then
  31. //** log '$DC not defined, assuming dmd...'
  32. //** DC=dmd
  33. //** fi
  34. auto dc = environment.get("DC", "");
  35. if (dc == "")
  36. {
  37. log(`Environment variable "DC" not defined, assuming dmd...`);
  38. dc = "dmd";
  39. }
  40.  
  41. // Clear log file
  42. {
  43. File(logFile, "w");
  44. }
  45.  
  46. //** DC_BIN=$(basename "$DC")
  47. //** CURR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
  48. //** FRONTEND="${FRONTEND:-}"
  49. const dc_bin = baseName(dc);
  50. const curr_dir = __FILE_FULL_PATH__.dirName();
  51. const frontend = environment.get("FRONTEND", "");
  52.  
  53. //** if [ "$#" -gt 0 ]; then FILTER=$1; else FILTER=".*"; fi
  54. auto filter = (args.length > 1) ? args[1] : "*";
  55.  
  56. version (Posix)
  57. {
  58. //** for script in $(ls $CURR_DIR/*.sh); do
  59. //** if [[ ! "$script" =~ $FILTER ]]; then continue; fi
  60. //** if [ "$script" = "$(gnureadlink ${BASH_SOURCE[0]})" ] || [ "$(basename $script)" = "common.sh" ]; then continue; fi
  61. //** if [ -e $script.min_frontend ] && [ ! -z "$FRONTEND" ] && [ ${FRONTEND} \< $(cat $script.min_frontend) ]; then continue; fi
  62. //** log "Running $script..."
  63. //** DUB=$DUB DC=$DC CURR_DIR="$CURR_DIR" $script || logError "Script failure."
  64. //** done
  65. foreach(DirEntry script; dirEntries(curr_dir, (args.length > 1) ? args[1] : "*.sh", SpanMode.shallow))
  66. {
  67. if (!script.name.endsWith(".sh"))
  68. continue;
  69. if (baseName(script.name).among("run-unittest.sh", "common.sh")) continue;
  70. const min_frontend = script.name ~ ".min_frontend";
  71. if (exists(min_frontend) && frontend.length && frontend < min_frontend.readText) continue;
  72. log("Running " ~ script ~ "...");
  73. if (spawnProcess(script.name, ["DUB":dub, "DC":dc, "CURR_DIR":curr_dir]).wait)
  74. logError("Script failure.");
  75. }
  76. }
  77.  
  78. foreach (DirEntry script; dirEntries(curr_dir, (args.length > 1) ? args[1] : "*.script.d", SpanMode.shallow))
  79. {
  80. if (!script.name.endsWith(".d"))
  81. continue;
  82. const min_frontend = script.name ~ ".min_frontend";
  83. if (frontend.length && exists(min_frontend) && frontend < min_frontend.readText) continue;
  84. log("Running " ~ script ~ "...");
  85. if (spawnProcess([dub, script.name], ["DUB":dub, "DC":dc, "CURR_DIR":curr_dir]).wait)
  86. logError("Script failure.");
  87. else
  88. log(script.name, " status: Ok");
  89. }
  90.  
  91. return any_errors;
  92. }