Skip to content

Commit

Permalink
Put test MMLs into temporary files to avoid problems from passing the…
Browse files Browse the repository at this point in the history
…m via CLI arguments

Because it breaks on Linux and thus on CI. I was
expecting as much...
  • Loading branch information
YuriSizov committed Nov 11, 2024
1 parent 8c11d9d commit 72e3b98
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
1 change: 0 additions & 1 deletion .github/actions/run-godot-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ runs:
- name: Run the project script
shell: bash
continue-on-error: true # Temporarily ignore the exit code and just continue.
run: |
godot --headless --path ${{ inputs.project-path }} --script ${{ inputs.run-script }} --verbose
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ example/.references/
example/bin/
example/export/
tests/bin/
tests/run/mml-compilation/inputs/
tests/run/voices-sound-consistency/graphs/
src/**/*.gen.cpp

Expand Down
18 changes: 17 additions & 1 deletion tests/run/mml-compilation.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ signal loading_completed()

const TUNES_URL := "https://raw.githubusercontent.com/YuriSizov/SiONMML/refs/heads/master/mmltalks_mml.json"
const OUTPUTS_PATH := "./run/mml-compilation/outputs"
const INPUTS_PATH := "./run/mml-compilation/inputs"

var _tunes: Array[TuneItem] = []

Expand All @@ -31,12 +32,20 @@ func run(scene_tree: SceneTree) -> void:
if _assert_equal("request sent", error, OK):
await loading_completed

# Ensure that the folder exists.
var fs := DirAccess.open(".")
fs.make_dir_recursive(INPUTS_PATH)

for tune_item in _tunes:
var tune_hash := tune_item.mml_string.hash()
var input_path := INPUTS_PATH.path_join("%d.mml" % [ tune_hash ])
var output_path := OUTPUTS_PATH.path_join("%d.txt" % [ tune_hash ])

# Store the MML in a file to avoid any weirdness from passing it via CLI arguments.
_store_tune_mml(input_path, tune_item.mml_string)

# This is painfully slow, but allows us to read the errors and match them against the expected result.
var received := _run_subscript("./run/mml-compilation/compile-mml-song.gd", [ tune_item.mml_string ])
var received := _run_subscript("./run/mml-compilation/compile-mml-song.gd", [ tune_hash ])
received = _extract_godot_errors(received)
var expected := _load_tune_output(output_path)
expected = _extract_godot_errors(expected)
Expand Down Expand Up @@ -95,6 +104,13 @@ func _load_tunes_completed(result: int, response_code: int, _headers: PackedStri
loading_completed.emit()


func _store_tune_mml(file_name: String, mml: String) -> void:
var file := FileAccess.open(file_name, FileAccess.WRITE)
file.resize(0)

file.store_string(mml)


func _store_tune_output(file_name: String, output: String) -> void:
if output.is_empty():
return
Expand Down
10 changes: 9 additions & 1 deletion tests/run/mml-compilation/compile-mml-song.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

extends SceneTree

const INPUTS_PATH := "./run/mml-compilation/inputs"


func _init():
# Delay everything by one frame so the initialization is complete before we run tests.
Expand All @@ -30,4 +32,10 @@ func _get_mml_string() -> String:
if args.is_empty():
return ""

return args[0]
var input_path := INPUTS_PATH.path_join("%s.mml" % [ args[0] ])
var file := FileAccess.open(input_path, FileAccess.READ)
if not file:
return ""

file.seek(0)
return file.get_as_text(true)

0 comments on commit 72e3b98

Please sign in to comment.