Replace the broken test suite with working GdUnit4 tests

The previous tests never compiled: they used GUT's assert functions,
Godot 3 APIs and reassigned autoload functions, so no test ran.

- 90 tests: unit tests for the playlist, songs, player scoring, time
  formatting, search and the server client, plus integration tests
  that run MainWindow and SyncWindow against a fake server
- Keybind tests check that Alt+<number> and Ctrl+Alt+<number> keep
  following the player rows while players are added and removed
- run_tests.sh finds Godot and runs the suite headless (~10 seconds)
- CI runs the tests before the build job in gitea-build.yaml; the
  separate test.yml used a GitHub action that does not exist
- GdUnit4 is committed instead of ignored, since the project enables
  it, and .gitea/ is no longer ignored
- Exported builds leave out tests/ and addons/gdUnit4/
This commit is contained in:
Sansan committed 2026-10-06 08:32:56 +02:00
1 parent 56e9fe66d3
commit c985a6ce5b
559 files changed
+32474 -2100

No files matched your search

+160 -149
View File
@@ -1,173 +1,184 @@
class_name PlaylistTest
extends GdUnitTestSuite
func test_add_to_playlist_increases_size():
Playlist.clear_song_list()
var initial_size = Playlist.song_object_array.size()
var song_obj = TestHelpers.create_test_song_object()
Playlist.add_to_playlist(song_obj)
assert_eq(Playlist.song_object_array.size(), initial_size + 1)
var _server: FakeHttpTransport
var _add_to_stats: bool
var _is_debug: bool
func test_get_next_song_returns_correct_song():
Playlist.clear_song_list()
var song1 = TestHelpers.create_test_song_object(1, "Soundtrack 1", "Song 1")
var song2 = TestHelpers.create_test_song_object(2, "Soundtrack 2", "Song 2")
Playlist.add_to_playlist(song1)
Playlist.add_to_playlist(song2)
Playlist.latest_played_song = 0
var next_song = Playlist.get_next_song()
assert_eq(next_song, song1)
func before_test() -> void:
_server = FakeHttpTransport.new().install()
_add_to_stats = Settings.add_to_stats
_is_debug = Settings.is_debug
Settings.add_to_stats = false
Settings.is_debug = false
Playlist.reset_playlist()
Playlist.number_of_tracks_to_preload = 1
func test_set_latest_played_song_increments():
Playlist.clear_song_list()
var song1 = TestHelpers.create_test_song_object(1)
var song2 = TestHelpers.create_test_song_object(2)
Playlist.add_to_playlist(song1)
Playlist.add_to_playlist(song2)
Playlist.latest_played_song = 0
Playlist.set_latest_played_song()
assert_eq(Playlist.latest_played_song, 1)
func after_test() -> void:
Playlist.reset_playlist()
Settings.add_to_stats = _add_to_stats
Settings.is_debug = _is_debug
_server.uninstall()
func test_set_latest_played_song_does_not_exceed_bounds():
Playlist.clear_song_list()
var song1 = TestHelpers.create_test_song_object(1)
Playlist.add_to_playlist(song1)
Playlist.latest_played_song = 0
Playlist.set_latest_played_song()
Playlist.set_latest_played_song()
assert_eq(Playlist.latest_played_song, 0)
func _add_songs(count: int) -> Array[SongObject]:
var songs: Array[SongObject] = []
for i: int in count:
var song: SongObject = SongObject.new()
song.song_number = i
song.soundtrack_title = "Soundtrack %d" % i
song.song_title = "Song %d" % i
Playlist.add_to_playlist(song)
songs.append(song)
return songs
func test_get_preloaded_songs_returns_correct_count():
Playlist.clear_song_list()
var song1 = TestHelpers.create_test_song_object(1)
var song2 = TestHelpers.create_test_song_object(2)
var song3 = TestHelpers.create_test_song_object(3)
song1.has_played = true
song2.has_played = false
song3.has_played = false
Playlist.add_to_playlist(song1)
Playlist.add_to_playlist(song2)
Playlist.add_to_playlist(song3)
assert_eq(Playlist.get_preloaded_songs(), 2)
func test_set_latest_played_song_advances() -> void:
_add_songs(3)
Playlist.set_latest_played_song()
assert_int(Playlist.latest_played_song).is_equal(1)
func test_should_preload_more_songs():
Playlist.clear_song_list()
Playlist.number_of_tracks_to_preload = 2
var song1 = TestHelpers.create_test_song_object(1)
var song2 = TestHelpers.create_test_song_object(2)
song1.has_played = true
song2.has_played = false
Playlist.add_to_playlist(song1)
Playlist.add_to_playlist(song2)
assert_true(Playlist.should_preload_more_songs())
var song3 = TestHelpers.create_test_song_object(3)
Playlist.add_to_playlist(song3)
assert_false(Playlist.should_preload_more_songs())
func test_set_latest_played_song_stops_at_last_song() -> void:
_add_songs(2)
Playlist.set_latest_played_song()
Playlist.set_latest_played_song()
Playlist.set_latest_played_song()
assert_int(Playlist.latest_played_song).is_equal(1)
func test_song_is_answered_sets_flag():
Playlist.clear_song_list()
var song = TestHelpers.create_test_song_object(1)
Playlist.add_to_playlist(song)
Playlist.currently_playing_song = 0
assert_false(song.is_answered)
Playlist.song_is_answered()
assert_true(song.is_answered)
func test_get_next_song_returns_latest_played() -> void:
var songs: Array[SongObject] = _add_songs(3)
Playlist.latest_played_song = 2
assert_object(Playlist.get_next_song()).is_same(songs[2])
func test_add_point_to_song():
Playlist.clear_song_list()
var song = TestHelpers.create_test_song_object(1)
Playlist.add_to_playlist(song)
Playlist.currently_playing_song = 0
Playlist.add_point(0)
assert_true(song.players_given_point.has(0))
func test_update_last_played_song_points_past_existing_songs() -> void:
_add_songs(4)
Playlist.update_last_played_song()
assert_int(Playlist.latest_played_song).is_equal(4)
func test_remove_point_from_song():
Playlist.clear_song_list()
var song = TestHelpers.create_test_song_object(1)
Playlist.add_to_playlist(song)
Playlist.currently_playing_song = 0
Playlist.add_point(0)
Playlist.remove_point(0)
assert_false(song.players_given_point.has(0))
func test_preloaded_songs_counts_unplayed_songs() -> void:
var songs: Array[SongObject] = _add_songs(3)
songs[0].has_played = true
assert_int(Playlist.get_preloaded_songs()).is_equal(2)
func test_get_song_returns_correct_stream():
Playlist.clear_song_list()
var expected_stream = TestHelpers.create_mock_audio_stream()
var song = TestHelpers.create_test_song_object(1)
song.song = expected_stream
Playlist.add_to_playlist(song)
var retrieved_stream = Playlist.get_song(0)
assert_eq(retrieved_stream, expected_stream)
func test_should_preload_more_songs_when_below_target() -> void:
var songs: Array[SongObject] = _add_songs(1)
songs[0].has_played = true
assert_bool(Playlist.should_preload_more_songs()).is_true()
func test_reset_playlist_clears_all():
Playlist.clear_song_list()
var song = TestHelpers.create_test_song_object(1)
Playlist.add_to_playlist(song)
Playlist.latest_played_song = 1
Playlist.currently_playing_song = 0
Playlist.reset_playlist()
assert_eq(Playlist.song_object_array.size(), 0)
assert_eq(Playlist.latest_played_song, 0)
assert_eq(Playlist.currently_playing_song, -1)
func test_should_not_preload_more_songs_when_target_reached() -> void:
_add_songs(1)
assert_bool(Playlist.should_preload_more_songs()).is_false()
func test_clear_song_list_removes_all():
Playlist.clear_song_list()
Playlist.add_to_playlist(TestHelpers.create_test_song_object(1))
Playlist.add_to_playlist(TestHelpers.create_test_song_object(2))
Playlist.clear_song_list()
assert_eq(Playlist.song_object_array.size(), 0)
func test_get_playlist_hides_unplayed_songs() -> void:
var songs: Array[SongObject] = _add_songs(3)
songs[0].has_played = true
assert_array(Playlist.get_playlist()).contains_exactly([songs[0]])
func test_get_playlist_shows_everything_in_debug() -> void:
Settings.is_debug = true
var songs: Array[SongObject] = _add_songs(2)
assert_array(Playlist.get_playlist()).contains_exactly(songs)
func test_song_is_answered_marks_song() -> void:
var songs: Array[SongObject] = _add_songs(2)
Playlist.song_is_answered(1)
assert_bool(songs[1].is_answered).is_true()
assert_bool(songs[0].is_answered).is_false()
func test_song_is_answered_reports_to_stats_when_enabled() -> void:
Settings.add_to_stats = true
_add_songs(2)
Playlist.song_is_answered(1)
assert_array(_server.requested_paths).contains_exactly(["/music/played?song=1"])
func test_song_is_answered_does_not_report_when_stats_disabled() -> void:
_add_songs(2)
Playlist.song_is_answered(1)
assert_array(_server.requested_paths).is_empty()
func test_points_are_recorded_on_current_song() -> void:
var songs: Array[SongObject] = _add_songs(2)
Playlist.set_currently_playing_song(1)
Playlist.add_point("lucca-id")
Playlist.add_point("crono-id")
assert_array(songs[1].players_given_point).contains_exactly(["lucca-id", "crono-id"])
assert_array(songs[0].players_given_point).is_empty()
func test_remove_point_from_current_song() -> void:
var songs: Array[SongObject] = _add_songs(1)
Playlist.set_currently_playing_song(0)
Playlist.add_point("crono-id")
Playlist.add_point("marle-id")
Playlist.remove_point("crono-id")
assert_array(songs[0].players_given_point).contains_exactly(["marle-id"])
func test_remove_player_removes_only_that_players_points() -> void:
var songs: Array[SongObject] = _add_songs(2)
songs[0].players_given_point.assign(["crono-id", "marle-id"])
songs[1].players_given_point.assign(["crono-id"])
Playlist.remove_player_from_list("marle-id")
assert_array(songs[0].players_given_point).contains_exactly(["crono-id"])
assert_array(songs[1].players_given_point).contains_exactly(["crono-id"])
func test_reset_playlist_clears_songs_and_position() -> void:
_add_songs(3)
Playlist.latest_played_song = 2
Playlist.set_currently_playing_song(1)
Playlist.reset_playlist()
assert_array(Playlist.song_object_array).is_empty()
assert_int(Playlist.latest_played_song).is_equal(0)
assert_int(Playlist.currently_playing_song).is_equal(-1)
func test_current_titles_are_hidden_until_answered() -> void:
var songs: Array[SongObject] = _add_songs(1)
Playlist.set_currently_playing_song(0)
assert_str(Playlist.get_current_soundtrack_title()).is_equal("????????")
songs[0].is_answered = true
assert_str(Playlist.get_current_soundtrack_title()).is_equal("Soundtrack 0")
assert_str(Playlist.get_current_song_title()).is_equal("Song 0")