A Godot Engine app to help streamers organize Majority Judgment polls in their streams.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
4.3 KiB

  1. [gd_scene load_steps=2 format=2]
  2. [sub_resource type="GDScript" id=1]
  3. script/source = "extends Node
  4. const RUN_ALL: String = \"-run_all\"
  5. const RUN_DIRECTORY: String = \"-run_dir\"
  6. const RUN_SCRIPT: String = \"-run_script\"
  7. const RUN_TAG: String = \"-run_tag\"
  8. const RUN_METHOD: String = \"-run_method\"
  9. const RUN_FAILURES: String = \"-rerun_failed\"
  10. const LIST_ALL: String = \"-list_all\"
  11. const LIST_DIR: String = \"-list_dir\"
  12. const PASSED: int = 0
  13. const FAILED: int = 1
  14. const TestRunner: PackedScene = preload(\"res://addons/WAT/core/test_runner/TestRunner.tscn\")
  15. const FileSystem: Reference = preload(\"res://addons/WAT/system/filesystem.gd\")
  16. var _runner: Node
  17. var _start_time: float
  18. func _ready() -> void:
  19. parse(arguments())
  20. func arguments() -> Array:
  21. return Array(OS.get_cmdline_args()).pop_back().split(\"=\") as Array
  22. func repeat(args) -> int:
  23. if not args.empty() and args.back().is_valid_integer():
  24. return args.back() as int
  25. else:
  26. return 1
  27. func parse(arguments: Array) -> void:
  28. ProjectSettings.set(\"WAT/TestStrategy\", {})
  29. ProjectSettings.save()
  30. var command: String = arguments.pop_front()
  31. match command:
  32. RUN_ALL:
  33. var strat = strategy()
  34. strat[\"strategy\"] = \"RunAll\"
  35. strat[\"repeat\"] = repeat(arguments)
  36. ProjectSettings.set(\"WAT/TestStrategy\", strat)
  37. _run()
  38. RUN_DIRECTORY:
  39. var strat = strategy()
  40. strat[\"strategy\"] = \"RunDirectory\"
  41. strat[\"directory\"] = arguments.front()
  42. strat[\"repeat\"] = repeat(arguments)
  43. ProjectSettings.set(\"WAT/TestStrategy\", strat)
  44. _run()
  45. RUN_SCRIPT:
  46. var strat = strategy()
  47. strat[\"strategy\"] = \"RunScript\"
  48. strat[\"script\"] = arguments.front()
  49. strat[\"repeat\"] = repeat(arguments)
  50. ProjectSettings.set(\"WAT/TestStrategy\", strat)
  51. _run()
  52. RUN_TAG:
  53. var strat = strategy()
  54. strat[\"strategy\"] = \"RunTag\"
  55. strat[\"tag\"] = arguments.front()
  56. print(strat[\"tag\"])
  57. strat[\"repeat\"] = repeat(arguments)
  58. ProjectSettings.set(\"WAT/TestStrategy\", strat)
  59. _run()
  60. RUN_METHOD:
  61. var strat = strategy()
  62. strat[\"strategy\"] = \"RunMethod\"
  63. strat[\"script\"] = arguments[0]
  64. strat[\"method\"] = arguments[1]
  65. strat[\"repeat\"] = repeat(arguments)
  66. ProjectSettings.set(\"WAT/TestStrategy\", strat)
  67. _run()
  68. RUN_FAILURES:
  69. var strat = strategy()
  70. strat[\"strategy\"] = \"RerunFailures\"
  71. strat[\"repeat\"] = repeat(arguments)
  72. ProjectSettings.set(\"WAT/TestStrategy\", strat)
  73. _run()
  74. LIST_ALL:
  75. _list()
  76. get_tree().quit()
  77. LIST_DIR:
  78. _list(arguments.pop_front())
  79. get_tree().quit()
  80. _:
  81. push_error(\"Invalid Argument\")
  82. get_tree().quit()
  83. func strategy() -> Dictionary:
  84. return ProjectSettings.get_setting(\"WAT/TestStrategy\")
  85. func test_directory() -> String:
  86. return ProjectSettings.get_setting(\"WAT/Test_Directory\")
  87. func _list(path: String = test_directory()):
  88. print()
  89. print(FileSystem.scripts(path))
  90. func _run() -> void:
  91. _runner = TestRunner.instance()
  92. _runner.connect(\"ended\", self, \"_on_testrunner_ended\")
  93. _start_time = OS.get_ticks_msec()
  94. add_child(_runner)
  95. static func set_run_path(path: String) -> void:
  96. ProjectSettings.set(\"WAT/ActiveRunPath\", path)
  97. func _on_testrunner_ended() -> void:
  98. _runner.queue_free()
  99. var caselist: Array = WAT.Results.withdraw()
  100. var cases = {passed = 0, total = 0, crashed = 0}
  101. for case in caselist:
  102. cases.total += 1
  103. if case.success:
  104. cases.passed += 1
  105. else:
  106. display_failures(case)
  107. display_summary(cases)
  108. set_exit_code(cases)
  109. func display_failures(case) -> void:
  110. print(\"%s (%s)\" % [case.context, case.path])
  111. for method in case.methods:
  112. if not method.success:
  113. print(\"\\n %s\" % method.context)
  114. for assertion in method.assertions:
  115. if not assertion.success:
  116. print(\"\\t%s\" % assertion.context, \"\\n\\t (EXPECTED: %s) | (RESULTED: %s)\" % [assertion.expected, assertion.actual])
  117. func display_summary(cases: Dictionary) -> void:
  118. cases.seconds = (OS.get_ticks_msec() - _start_time) / 1000
  119. print(\"\"\"
  120. -------RESULTS-------
  121. Took {seconds} seconds
  122. {crashed} Tests Crashed
  123. {passed} / {total} Tests Passed
  124. -------RESULTS-------
  125. \"\"\".format(cases).dedent())
  126. func set_exit_code(cases: Dictionary) -> void:
  127. OS.exit_code = PASSED if cases.total > 0 and cases.total == cases.passed and cases.crashed == 0 else FAILED
  128. "
  129. [node name="cli" type="Node"]
  130. script = SubResource( 1 )