diff --git a/.github/workflows/addon.yml b/.github/workflows/addon.yml index 844b0d1..44e3c0e 100644 --- a/.github/workflows/addon.yml +++ b/.github/workflows/addon.yml @@ -5,9 +5,9 @@ on: workflow_dispatch: env: - GODOT_MAJOR: 4 - TARGET: template_release - GODOT_REF: 4.0.2-stable + GODOT_MAJOR: 3 + TARGET: release + GODOT_REF: 3.5.2-stable LIBRARY_PATH: addons/godot-wasm/bin WASMER_VERSION: v3.1.1 @@ -17,11 +17,11 @@ jobs: strategy: fail-fast: false matrix: - platform: [linux, macos, windows] + platform: [linux, osx, windows] include: - platform: linux os: ubuntu-latest - - platform: macos + - platform: osx os: macos-11 - platform: windows os: windows-latest @@ -61,11 +61,11 @@ jobs: strategy: fail-fast: false matrix: - platform: [linux, macos, windows] + platform: [linux, osx, windows] include: - platform: linux os: ubuntu-latest - - platform: macos + - platform: osx os: macos-11 - platform: windows os: windows-latest diff --git a/examples/wasm-test/Main.tscn b/examples/wasm-test/Main.tscn index e8a9dc0..0d223f8 100644 --- a/examples/wasm-test/Main.tscn +++ b/examples/wasm-test/Main.tscn @@ -1,15 +1,10 @@ -[gd_scene load_steps=2 format=3 uid="uid://d40co37swb17"] +[gd_scene load_steps=2 format=2] -[ext_resource type="Script" path="res://utils/TestRunner.gd" id="1_hns0s"] +[ext_resource path="res://utils/TestRunner.gd" type="Script" id=1] [node name="Main" type="RichTextLabel"] -anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 -theme_override_font_sizes/normal_font_size = 24 -theme_override_font_sizes/bold_font_size = 24 bbcode_enabled = true scroll_following = true -script = ExtResource("1_hns0s") +script = ExtResource( 1 ) diff --git a/examples/wasm-test/TestGeneral.gd b/examples/wasm-test/TestGeneral.gd index 6dc3985..fe27f94 100644 --- a/examples/wasm-test/TestGeneral.gd +++ b/examples/wasm-test/TestGeneral.gd @@ -43,7 +43,7 @@ func test_load(): func test_invalid_binary(): var wasm = Wasm.new() - var buffer = "asdf".to_utf8_buffer() + var buffer = "asdf".to_utf8() var error = wasm.compile(buffer) expect_eq(error, ERR_INVALID_DATA) expect_error("Invalid binary") diff --git a/examples/wasm-test/project.godot b/examples/wasm-test/project.godot index 32f0a04..fd994ef 100644 --- a/examples/wasm-test/project.godot +++ b/examples/wasm-test/project.godot @@ -6,30 +6,75 @@ ; [section] ; section goes between [] ; param=value ; assign values to parameters -config_version=5 +config_version=4 + +_global_script_classes=[ { +"base": "TestSuite", +"class": "GodotWasmTestSuite", +"language": "GDScript", +"path": "res://utils/GodotWasmTestSuite.gd" +}, { +"base": "Node", +"class": "TestRunner", +"language": "GDScript", +"path": "res://utils/TestRunner.gd" +}, { +"base": "Resource", +"class": "TestSuite", +"language": "GDScript", +"path": "res://utils/TestSuite.gd" +}, { +"base": "Object", +"class": "Utils", +"language": "GDScript", +"path": "res://utils/Utils.gd" +}, { +"base": "", +"class": "Wasm", +"language": "NativeScript", +"path": "res://addons/godot-wasm/Wasm.gdns" +}, { +"base": "", +"class": "WasmMemory", +"language": "NativeScript", +"path": "res://addons/godot-wasm/WasmMemory.gdns" +} ] +_global_script_class_icons={ +"GodotWasmTestSuite": "", +"TestRunner": "", +"TestSuite": "", +"Utils": "", +"Wasm": "", +"WasmMemory": "" +} [application] config/name="Wasm Test" run/main_scene="res://Main.tscn" -config/features=PackedStringArray("4.0", "GL Compatibility") [debug] -file_logging/enable_file_logging=true -file_logging/log_path="user://logs/test.log" -file_logging/max_log_files=1 +gdscript/warnings/return_value_discarded=false [display] -window/size/viewport_width=512 -window/size/viewport_height=512 +window/size/width=512 +window/size/height=512 [editor] -run/main_run_args="--keepalive=yes -- --key=val" +main_run_args="--keepalive=yes" + +[gui] + +common/drop_mouse_on_gui_input_disabled=true + +[logging] + +file_logging/enable_file_logging=true +file_logging/log_path="user://logs/test.log" -[rendering] +[physics] -renderer/rendering_method="gl_compatibility" -renderer/rendering_method.mobile="gl_compatibility" +common/enable_pause_aware_picking=true diff --git a/examples/wasm-test/utils/GodotWasmTestSuite.gd b/examples/wasm-test/utils/GodotWasmTestSuite.gd index 365e241..daae570 100644 --- a/examples/wasm-test/utils/GodotWasmTestSuite.gd +++ b/examples/wasm-test/utils/GodotWasmTestSuite.gd @@ -1,25 +1,28 @@ extends TestSuite class_name GodotWasmTestSuite +const TYPE_FLOAT: int = TYPE_REAL const PAGE_SIZE: int = 0b1 << 16 const PAGES_MAX: int = PAGE_SIZE * (PAGE_SIZE - 1) # Test suite overrides func expect_error(s: String): - super.expect_error("(Godot Wasm: )?" + s) + .expect_error("(Godot Wasm: )?" + s) # General utils -func load_wasm(f: String, imports: Dictionary = {}, e: Error = OK) -> Wasm: +func load_wasm(f: String, imports: Dictionary = {}, e: int = OK) -> Wasm: var wasm = Wasm.new() var buffer = read_file(f) var error = wasm.load(buffer, imports) expect_eq(error, e) return wasm -func read_file(f: String) -> PackedByteArray: - return FileAccess.get_file_as_bytes("res://wasm/%s.wasm" % f) +func read_file(f: String) -> PoolByteArray: + var file = File.new() + file.open("res://wasm/%s.wasm" % f, File.READ) + return file.get_buffer(file.get_len()) # Dummy import to supply to Wasm modules static func dummy(a = "", b = "", c = "", d = ""): @@ -33,7 +36,7 @@ func dummy_imports(functions: Array = []) -> Dictionary: return imports func make_bytes(data: Array): - return PackedByteArray(data) + return PoolByteArray(data) func get_cmdline_user_args() -> Array: - return OS.get_cmdline_user_args() + return [] diff --git a/examples/wasm-test/utils/TestRunner.gd b/examples/wasm-test/utils/TestRunner.gd index 2e1cdc8..743636a 100644 --- a/examples/wasm-test/utils/TestRunner.gd +++ b/examples/wasm-test/utils/TestRunner.gd @@ -4,27 +4,33 @@ class_name TestRunner enum LogLevel { Default, Success, Error, Title } enum LogDestination { All, UI } -@onready var _log_label: RichTextLabel = get_tree().get_current_scene() as RichTextLabel -@onready var _log_file = FileAccess.open("user://logs/test.log", FileAccess.READ) +onready var _log_label: RichTextLabel = get_tree().get_current_scene() as RichTextLabel +onready var _log_file = File.new() func _ready(): record("Log dir: %s" % OS.get_user_data_dir()) + _log_file.open("user://logs/test.log", File.READ) + var results = Results.new() var regex = Utils.make_regex("^Test\\w+\\.gd") - for file in DirAccess.get_files_at("res://"): - # Find relevant test suites + var dir = Directory.new() + if dir.open("res://") != OK: return get_tree().quit(1) + dir.list_dir_begin() + while true: + var file = dir.get_next() + if !file: break if regex.search(file) == null: continue var script = load(file) as Script if !inherits(script, TestSuite): continue var suite: TestSuite = script.new() # Run suite record("Running test suite: %s" % file) - suite.connect("test_start", self.handle_test_start.bind(results)) - suite.connect("test_error", self.handle_test_error) - suite.connect("test_pass", self.handle_test_pass.bind(results)) - suite.connect("test_fail", self.handle_test_fail.bind(results)) + suite.connect("test_start", self, "handle_test_start", [results]) + suite.connect("test_error", self, "handle_test_error") + suite.connect("test_pass", self, "handle_test_pass", [results]) + suite.connect("test_fail", self, "handle_test_fail", [results]) suite.run(_log_file) record("Tests complete", LogLevel.Title) @@ -81,4 +87,4 @@ func record_ui(s, l: int): if l == LogLevel.Success: s = "[color=green]%s[/color]" % s elif l == LogLevel.Error: s = "[color=red]%s[/color]" % s elif l == LogLevel.Title: s = "[b]%s[/b]" % s - _log_label.append_text("%s\n" % s) + _log_label.bbcode_text += "%s\n" % s diff --git a/examples/wasm-test/utils/TestSuite.gd b/examples/wasm-test/utils/TestSuite.gd index 2049a81..4564932 100644 --- a/examples/wasm-test/utils/TestSuite.gd +++ b/examples/wasm-test/utils/TestSuite.gd @@ -39,7 +39,7 @@ func expect_error(s: String): # Account for error stack trace var regex = Utils.make_regex("^\\s+at:\\s") var position = _log_file.get_position() - while _log_file.get_position() < _log_file.get_length(): + while _log_file.get_position() < _log_file.get_len(): if !regex.search(_log_file.get_line()): break position = _log_file.get_position() _log_file.seek(position)