M1b: Brücke und Hülle #6
@@ -39,7 +39,7 @@ Drei Wächter prüfen das. `core/clippy.toml` sperrt Pfade wie `std::collections
|
||||
- GDScript mit Typangaben schreiben (`var x := …`, Rückgabetypen an jeder Funktion).
|
||||
- Eingabeaktionen legt `game/scripts/input_setup.gd` an, nicht `project.godot`.
|
||||
- Alle Texte, die Spieler sehen, stehen in `game/i18n/texts.csv` (Deutsch und Englisch) und werden über `tr()` geholt.
|
||||
- Tests, die Dateien schreiben, nutzen `TestFiles.temporary_dir()`, nie den echten Benutzerordner.
|
||||
- Tests, die Dateien schreiben, nutzen `TestFiles.temporary_dir()` (Ordner unter `user://tests`), nie die echten Dateien des Spielers.
|
||||
- Godot erzeugt beim Import zu jedem Skript eine `.uid`-Datei. Sie gehört ins Archiv. Der Ordner `game/.godot/` gehört nicht hinein.
|
||||
|
||||
## Prüfen
|
||||
|
||||
@@ -44,6 +44,11 @@ func _initialize() -> void:
|
||||
|
||||
|
||||
func _run_all() -> void:
|
||||
# Remove what runs that stopped early left behind, before the error
|
||||
# counter starts. Only if the folder exists, because Godot reports an
|
||||
# error when it lists a missing one.
|
||||
if DirAccess.dir_exists_absolute(TestFiles.ROOT):
|
||||
TestFiles.remove_dir(TestFiles.ROOT)
|
||||
var counter := ErrorCounter.new()
|
||||
OS.add_logger(counter)
|
||||
var passed := 0
|
||||
|
||||
@@ -1,18 +1,29 @@
|
||||
class_name TestFiles
|
||||
extends RefCounted
|
||||
## Temporary folders below user://tests for tests that write files, so that
|
||||
## tests never touch the player's real key, save or recordings.
|
||||
## Temporary folders below user://tests for tests that write files. That
|
||||
## folder lies inside the game's real user folder, next to the player's own
|
||||
## key, save and recordings, so nothing outside it may be deleted here.
|
||||
|
||||
## The only folder the tests write to and remove_dir deletes from.
|
||||
const ROOT := "user://tests"
|
||||
|
||||
|
||||
static func temporary_dir(label: String) -> String:
|
||||
var path := "user://tests".path_join("%s-%d" % [label, Time.get_ticks_usec()])
|
||||
var path := ROOT.path_join("%s-%d" % [label, Time.get_ticks_usec()])
|
||||
DirAccess.make_dir_recursive_absolute(path)
|
||||
return path
|
||||
|
||||
|
||||
## Deletes the folder `path` with everything in it. Refuses every path that is
|
||||
## not ROOT or below it, with an error and without deleting anything: a wrong
|
||||
## argument must never delete the player's real files.
|
||||
static func remove_dir(path: String) -> void:
|
||||
for file in DirAccess.get_files_at(path):
|
||||
DirAccess.remove_absolute(path.path_join(file))
|
||||
for directory in DirAccess.get_directories_at(path):
|
||||
remove_dir(path.path_join(directory))
|
||||
DirAccess.remove_absolute(path)
|
||||
var clean := path.simplify_path()
|
||||
if clean != ROOT and not clean.begins_with(ROOT + "/"):
|
||||
push_error("TestFiles.remove_dir refuses %s: it is not %s or below it" % [path, ROOT])
|
||||
return
|
||||
for file in DirAccess.get_files_at(clean):
|
||||
DirAccess.remove_absolute(clean.path_join(file))
|
||||
for directory in DirAccess.get_directories_at(clean):
|
||||
remove_dir(clean.path_join(directory))
|
||||
DirAccess.remove_absolute(clean)
|
||||
|
||||
Reference in New Issue
Block a user