bitwes/Gut

[Solved]: Error: 'Identifier "GutUtils" not declared in the current scope' when running tests in CI

Ajver opened this issue · 3 comments

When running unit tests in Github CI I get the following error:

SCRIPT ERROR: Parse Error: Identifier "GutUtils" not declared in the current scope.
          at: GDScript::reload (res://addons/gut/gut_cmdln.gd:326)
ERROR: Failed to load script "res://addons/gut/gut_cmdln.gd" with error "Parse error".
   at: load (modules/gdscript/gdscript.cpp:2788)
Error: Process completed with exit code 1.

When I run the unit tests on my local machine (Ubuntu 20.04), using both: Editor and CLI, all tests are passing with no problems.

To run locally I use command:

godot4 --headless --path $PWD -d -s addons/gut/gut_cmdln.gd -gexit

Where godot4 is an alias to Godot4.2.1 executable

In CI I use exactly the same line. Full CI file content:

name: "godot-ci export"
on: push

env:
  GODOT_VERSION: 4.2.1
  EXPORT_NAME: test-project
  PROJECT_PATH: project/

jobs:
  run-tests:
    name: Run unit tests
    runs-on: ubuntu-20.04
    container:
      image: barichello/godot-ci:4.2.1
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          lfs: true
      - name: Run GUT
        run: |
          cd $PROJECT_PATH
          godot --headless -s --path "$PWD" addons/gut/gut_cmdln.gd -gexit
 

As for the test project, I created empty Godot project (in Godot 4.2.1), installed latest GUT (9.2.1) and created one scene, and one very simple unit test, to make sure it's not the problem in the project itself. Sending the project zipped, in case someone wants to look at it. Also tested with GUT v9.1.1, which is setup on my other project - the same error.

project.zip

Please note, that a similar CI workflow was working fine for me, in Godot3.5, before I migrated my project to Godot4.2.1

The error is weird, because when I browse the GUT files in the editor, there isn't any problem with the GutUtils class - no syntax errors, and well-visible by the gut_cmdln.gd script

I get the same problem in Github CI and in Concourse CI.

I got it to work in Godot 4.2.2 by doing godot --headless --import before running the tests.
The import command still gives the same errors as before. But the tests seem to work fine afterwards.

This has to do with GutUtils being the class_name and Godot not knowing about it on the first launch (possibly due to how early it is used in gut_cmdln.gd). From what I've gathered from other CI issues, doing godot --headless --import once before running tests is the best workaround.

This would be great to get fixed but I haven't had any luck with it yet.

Yes, after deeper research I found that the problem is that CI is missing the .godot folder, which is generated by Godot editor the first time one opens a project. But this folder is in .gitignore and so excluded from Github.

godot --headless --import creates this folder and solves the issue, but it has just been implemented in Godot 4.2.2 (I was experiencing the issue on Godot 4.2.1).

For these who still use older version of Godot: I found that exporting project (i.e.: godot --headless --export-debug ... etc) creates the .godot folder - and that's good hack to solve the issue.

After all - this is not a problem with GUT, but Godot, and we already have a proper solution for this. I don't think it requires any changes to the Gut itself, other than maybe describing this as a potential issue in the documentation, for running from CLI