Newer
Older
dub_jkp / test / environment-variables.script.d
  1. /+ dub.json: {
  2. "name": "environment_variables"
  3. } +/
  4. module environment_variables;
  5. import std;
  6.  
  7. void main()
  8. {
  9. auto currDir = environment.get("CURR_DIR", __FILE_FULL_PATH__.dirName());
  10. // preGenerateCommands uses system.environments < settings.environments < deppkg.environments < root.environments < deppkg.preGenerateEnvironments < root.preGenerateEnvironments
  11. // preBuildCommands uses system.environments < settings.environments < deppkg.environments < root.environments < deppkg.buildEnvironments < root.buildEnvironments < deppkg.preBuildEnvironments < root.preBuildEnvironments
  12. // Build tools uses system.environments < settings.environments < deppkg.environments < root.environments < deppkg.buildEnvironments < root.buildEnvironments
  13. // postBuildCommands uses system.environments < settings.environments < deppkg.environments < root.environments < deppkg.buildEnvironments < root.buildEnvironments < deppkg.postBuildEnvironments < root.postBuildEnvironments
  14. // postGenerateCommands uses system.environments < settings.environments < deppkg.environments < root.environments < deppkg.postGenerateEnvironments < root.postGenerateEnvironments
  15. // preRunCommands uses system.environments < settings.environments < deppkg.environments < root.environments < deppkg.runEnvironments < root.runEnvironments < deppkg.preRunEnvironments < root.preRunEnvironments
  16. // User application uses system.environments < settings.environments < deppkg.environments < root.environments < deppkg.runEnvironments < root.runEnvironments
  17. // postRunCommands uses system.environments < settings.environments < deppkg.environments < root.environments < deppkg.runEnvironments < root.runEnvironments < deppkg.postRunEnvironments < root.postRunEnvironments
  18. // Test cases covers:
  19. // preGenerateCommands [in root]
  20. // priority check: system.environments < settings.environments
  21. // priority check: settings.environments < deppkg.environments
  22. // priority check: deppkg.environments < root.environments
  23. // priority check: root.environments < deppkg.preGenerateEnvironments
  24. // priority check: deppkg.preGenerateEnvironments < root.preGenerateEnvironments
  25. // postGenerateCommands [in root]
  26. // expantion check: deppkg.VAR4
  27. // preBuildCommands [in deppkg]
  28. // root.environments < deppkg.buildEnvironments
  29. // deppkg.buildEnvironments < root.buildEnvironments
  30. // root.buildEnvironments < deppkg.postBuildEnvironments
  31. // deppkg.preBuildEnvironments < root.preBuildEnvironments
  32. // postBuildCommands [in deppkg]
  33. // expantion check: deppkg.VAR4
  34. // preRunCommands [in deppkg][in root]
  35. // expantion check: deppkg.VAR4
  36. // Application run
  37. // expantion check: root.VAR1
  38. // expantion check: settings.VAR2
  39. // expantion check: root.VAR3
  40. // expantion check: deppkg.VAR4
  41. // expantion check: system.VAR5
  42. // expantion check: system.SYSENVVAREXPCHECK
  43. // postRunCommands [in deppkg][in root]
  44. // expantion check: deppkg.VAR4
  45. auto res = execute([environment.get("DUB", "dub"), "run", "-f"], [
  46. "PRIORITYCHECK_SYS_SET": "system.PRIORITYCHECK_SYS_SET",
  47. "SYSENVVAREXPCHECK": "system.SYSENVVAREXPCHECK",
  48. "VAR5": "system.VAR5"
  49. ], Config.none, size_t.max, currDir.buildPath("environment-variables"));
  50. scope (failure)
  51. writeln("environment-variables test failed... Testing stdout is:\n-----\n", res.output);
  52. // preGenerateCommands [in root]
  53. assert(res.output.canFind("root.preGenerate: setting.PRIORITYCHECK_SYS_SET"), "preGenerate environment variables priority check is failed.");
  54. assert(res.output.canFind("root.preGenerate: deppkg.PRIORITYCHECK_SET_DEP"), "preGenerate environment variables priority check is failed.");
  55. assert(res.output.canFind("root.preGenerate: deppkg.PRIORITYCHECK_DEP_ROOT"), "preGenerate environment variables priority check is failed.");
  56. assert(res.output.canFind("root.preGenerate: deppkg.PRIORITYCHECK_ROOT_DEPSPEC"), "preGenerate environment variables priority check is failed.");
  57. assert(res.output.canFind("root.preGenerate: root.PRIORITYCHECK_DEPSPEC_ROOTSPEC"), "preGenerate environment variables priority check is failed.");
  58. // postGenerateCommands [in root]
  59. assert(res.output.canFind("root.postGenerate: deppkg.VAR4", "postGenerate environment variables expantion check is failed."));
  60. // preBuildCommands [in deppkg]
  61. assert(res.output.canFind("deppkg.preBuild: deppkg.PRIORITYCHECK_ROOT_DEPBLDSPEC"), "preBuild environment variables priority check is failed.");
  62. assert(res.output.canFind("deppkg.preBuild: root.PRIORITYCHECK_DEPBLDSPEC_ROOTBLDSPEC"), "preBuild environment variables priority check is failed.");
  63. assert(res.output.canFind("deppkg.preBuild: deppkg.PRIORITYCHECK_ROOTBLDSPEC_DEPSPEC"), "preBuild environment variables priority check is failed.");
  64. assert(res.output.canFind("deppkg.preBuild: root.PRIORITYCHECK_DEPSPEC_ROOTSPEC"), "preBuild environment variables priority check is failed.");
  65. // postBuildCommands [in deppkg]
  66. assert(res.output.canFind("deppkg.postBuild: deppkg.VAR4"), "postBuild environment variables expantion check is failed.");
  67. // preRunCommands [in deppkg][in root]
  68. assert(!res.output.canFind("deppkg.preRun: deppkg.VAR4"), "preRun that is defined dependent library does not call.");
  69. assert(res.output.canFind("root.preRun: deppkg.VAR4"), "preRun environment variables expantion check is failed.");
  70. // Application run
  71. assert(res.output.canFind("app.run: root.VAR1"), "run environment variables expantion check is failed.");
  72. assert(res.output.canFind("app.run: settings.VAR2"), "run environment variables expantion check is failed.");
  73. assert(res.output.canFind("app.run: root.VAR3"), "run environment variables expantion check is failed.");
  74. assert(res.output.canFind("app.run: deppkg.VAR4"), "run environment variables expantion check is failed.");
  75. assert(res.output.canFind("app.run: system.VAR5"), "run environment variables expantion check is failed.");
  76. assert(res.output.canFind("app.run: system.SYSENVVAREXPCHECK"), "run environment variables expantion check is failed.");
  77. // postRunCommands [in deppkg][in root]
  78. assert(!res.output.canFind("deppkg.postRun: deppkg.VAR4"), "postRunCommands that is defined dependent library does not call.");
  79. assert(res.output.canFind("root.postRun: deppkg.VAR4"), "postRun environment variables expantion check is failed.");
  80. }