Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unit tests were disabled #209

Merged
merged 9 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

Make sure to follow the PR preparation steps in [CONTRIBUTING.md](https://github.com/godotjs/javascript/blob/master/CONTRIBUTING.md#preparing-your-pr) before submitting your PR:

- [ ] format the codebase: from the root, run `bash ./clang_format.sh`.
- [ ] format C++: from the root, run `bash ./misc/formatting/clang_format.sh`.
26 changes: 1 addition & 25 deletions .github/workflows/static_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Checkout workaround
run: |
mv tmp/misc/scripts misc/scripts
cp clang_format.sh misc/scripts/clang_format.sh
cp misc/formatting/clang_format.sh misc/scripts/clang_format.sh

- name: Install APT dependencies
uses: awalsh128/cache-apt-pkgs-action@latest
Expand Down Expand Up @@ -66,14 +66,6 @@ jobs:
run: |
bash ./misc/scripts/header_guards.sh changed.txt

- name: Python style checks via black (black_format.sh)
run: |
if grep -qE '\.py$|SConstruct|SCsub' changed.txt || [ -z "$(cat changed.txt)" ]; then
bash ./misc/scripts/black_format.sh
else
echo "Skipping Python formatting as no Python files were changed."
fi

- name: Python scripts static analysis (mypy_check.sh)
run: |
if grep -qE '\.py$|SConstruct|SCsub' changed.txt || [ -z "$(cat changed.txt)" ]; then
Expand All @@ -86,19 +78,3 @@ jobs:
run: |
clang-format --version
bash ./misc/scripts/clang_format.sh changed.txt

- name: Style checks via dotnet format (dotnet_format.sh)
run: |
if grep -q "modules/mono" changed.txt || [ -z "$(cat changed.txt)" ]; then
bash ./misc/scripts/dotnet_format.sh
else
echo "Skipping dotnet format as no C# files were changed."
fi

- name: Spell checks via codespell
if: github.event_name == 'pull_request' && env.CHANGED_FILES != ''
uses: codespell-project/actions-codespell@v2
with:
skip: "./bin,./thirdparty,*.desktop,*.svg,*.gen.*,*.po,*.pot,*.rc,./AUTHORS.md,./COPYRIGHT.txt,./DONORS.md,./core/input/gamecontrollerdb.txt,./core/string/locales.h,./editor/project_converter_3_to_4.cpp,./misc/scripts/codespell.sh,./platform/android/java/lib/src/com,./platform/web/node_modules,./platform/web/package-lock.json"
ignore_words_list: "breaked,checkin,curvelinear,doubleclick,expct,findn,gird,hel,inout,labelin,lod,mis,nd,numer,ot,pointin,requestor,te,textin,thirdparty,vai"
path: ${{ env.CHANGED_FILES }}
2 changes: 1 addition & 1 deletion .github/workflows/windows_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
run: |
${{ matrix.bin }} --version
${{ matrix.bin }} --help
${{ matrix.bin }} --test
${{ matrix.bin }} --test --force-colors

- name: Prepare artifact
run: |
Expand Down
23 changes: 21 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,30 @@

## Project Structure

TODO
- [Clang](https://clang.llvm.org/): Code formatting
- ``.clang-format``
- ``.clang-tidy``
- ``clang-format.sh``
- [Custom Modules in C++](https://docs.godotengine.org/en/stable/contributing/development/core_and_modules/custom_modules_in_cpp.html#custom-modules-in-c)
- ``config.py``: Configs for this module
- ``doc``: For showing documentation in editor
- ``doc_classes``: For showing documentation in editor
- ``icons``: For showing icons in editor
- ``SCsub``: Will be called from Godots `SConstruct` during build
- ``editor``: Custom `.cpp` only bundled for `target=editor`
- ``misc``: Scripts and other files, which aren't related to `c++`
- ``tests``: Some testcases to run in CICD
- ``thirdparty``: Dependencies or libraries which shouldn't be analysed by static checks
- GodotJS custom data
- ``.github``: Runs custom CI/CD in GitHub
- ``docs``: Add some additional stuff for README.md
- ``src``: Contains custom C++ code


## Preparing your PR

The project is using [`clang-format`](https://clang.llvm.org/docs/ClangFormat.html) to format most files. You need to run `bash ./clang_format.sh` before your PR for a successful pipeline.
The project is using [`clang-format`](https://clang.llvm.org/docs/ClangFormat.html) to format C++ files.
You need to run `bash ./misc/formatting/clang_format.sh` before your PR for a successful pipeline.

Furthermore, there is an `utf-8` and `LF` checker to fix file formats. Additionally, some spellchecks run inside the [pipeline](.github/workflows/static_checks.yml).

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Download the binaries from the [release page](https://github.com/GodotExplorer/E
- Use `scons` with those additional options `warnings=extra werror=yes module_text_server_fb_enabled=yes` to show all potential errors:
- Windows: `scons platform=windows warnings=extra werror=yes module_text_server_fb_enabled=yes`
- MacOS: `scons platform=macos arch=arm64 warnings=extra werror=yes module_text_server_fb_enabled=yes`
- **Hint**: To enable unit tests you need to add ``tests=true`` to `scons` arguments

## Documentation, Tutorials & Demos

Expand Down
115 changes: 50 additions & 65 deletions SCsub
Original file line number Diff line number Diff line change
@@ -1,47 +1,32 @@
#!/usr/bin/env python
import platform, os, sys
import os

from misc.generate.generate_files import generate

Import("env")
Import("env_modules")
env_module = env_modules.Clone()

env_javascript = env_modules.Clone()

# Default engine to use we might add some more in the future like node or v8
JS_ENGINE = "quickjs"
TOOLS = "editor" == env_module["target"]
javascript_dir = os.path.join(GetLaunchDir(), "modules", os.path.basename(os.getcwd()))

# Windows workaround
if env["platform"] == "windows":
if env["use_mingw"]:
env.Append(LIBS=["pthread"])


def open_file(path, mode):
if platform.python_version() > "3":
return open(path, mode, encoding="utf8")
else:
return open(path, mode)


def dump_text_file_to_cpp(file):
source = open_file(file, "r").read()
lines = source.split("\n")
source = ""
length = len(lines)
for i in range(length):
line = lines[i].replace('"', '\\"')
line = '\t"' + line + '\\n"'
if i < length - 1:
line += "\n"
source += line
return source


# Add required files for quickjs into godot
if JS_ENGINE == "quickjs":
import generate_builtin_api

generate_builtin_api.generate_api_json(os.path.join(GetLaunchDir(), "modules", os.path.basename(os.getcwd())))
generate_builtin_api.generate_api_json(javascript_dir)
import thirdparty.quickjs.builtin_binding_generator

thirdparty.quickjs.builtin_binding_generator.generate_builtin_bindings()
version = open("thirdparty/quickjs/quickjs/VERSION.txt", "r").read().split("\n")[0]
quickjs_env = env_modules.Clone()
quickjs_env = env_javascript.Clone()
quickjs_env.Append(CPPDEFINES={"QUICKJS_CONFIG_VERSION": '"' + version + '"'})
quickjs_env.Append(CPPDEFINES=["CONFIG_BIGNUM"])
if "release" not in (quickjs_env["target"] or ""):
Expand All @@ -55,50 +40,50 @@ if JS_ENGINE == "quickjs":
quickjs_env.add_source_files(env.modules_sources, "thirdparty/quickjs/*.cpp")
quickjs_env.add_source_files(env.modules_sources, "thirdparty/quickjs/quickjs/*.c")

# Binding script to run at engine initializing
with open("misc/godot.binding_script.gen.cpp", "w") as f:
text = '/* THIS FILE IS GENERATED DO NOT EDIT */\n#include "../javascript_binder.h"\nString JavaScriptBinder::BINDING_SCRIPT_CONTENT = \n${source};'
f.write(text.replace("${source}", dump_text_file_to_cpp("misc/binding_script.js")))
# If target=editor is provided via scons
if env.editor_build:
env_javascript.add_source_files(env.modules_sources, "editor/workarounds/*.cpp")
env_javascript.add_source_files(env.modules_sources, "editor/*.cpp")

# --- Generate editor tool files ---
from misc.generate.editor_tools import get_editor_tools_files
from misc.generate.editor_tools import get_editor_tools_header

files = get_editor_tools_files()
generate(javascript_dir, get_editor_tools_header(), files)
env_javascript.add_source_files(env.modules_sources, files.keys())

# If tests=yes flag is provided via scons
if env["tests"]:
env_javascript.Append(CPPDEFINES=["TESTS_ENABLED"])

# --- Generate test files ---
from misc.generate.test_manager import get_test_files
from misc.generate.test_manager import get_test_manager_header

files = get_test_files()
generate(javascript_dir, get_test_manager_header(), files)
env_javascript.add_source_files(env.modules_sources, files.keys())

# --- Files inside editor & targets ---

sources = [
"register_types.cpp",
"javascript_language.cpp",
"javascript_instance.cpp",
"javascript.cpp",
"misc/godot.binding_script.gen.cpp",
]

if TOOLS:
base_text = (
'/* THIS FILE IS GENERATED DO NOT EDIT */\n#include "editor_tools.h"\nString JavaScriptPlugin::{} = \n{};'
)
tool_fns = {
"editor/godot.d.ts.gen.cpp": (
"BUILTIN_DECLARATION_TEXT",
dump_text_file_to_cpp("misc/godot.d.ts"),
),
"editor/tsconfig.json.gen.cpp": (
"TSCONFIG_CONTENT",
dump_text_file_to_cpp("misc/tsconfig.json"),
),
"editor/decorators.ts.gen.cpp": (
"TS_DECORATORS_CONTENT",
dump_text_file_to_cpp("misc/decorators.ts"),
),
"editor/package.json.gen.cpp": (
"PACKAGE_JSON_CONTENT",
dump_text_file_to_cpp("misc/package.json"),
),
}
for fn, subs in tool_fns.items():
with open_file(fn, "w") as fh:
fh.write(base_text.format(*subs))
env_module.add_source_files(env.modules_sources, fn)


env_module.Append(CPPPATH=["#modules/javascript"])
env_module.add_source_files(env.modules_sources, sources)
# Add all required files for "Javascript" language into godot
env_javascript.Append(CPPPATH=["#modules/javascript"])
env_javascript.add_source_files(env.modules_sources, sources)

if env.editor_build:
env_module.add_source_files(env.modules_sources, "editor/workarounds/*.cpp")
env_module.add_source_files(env.modules_sources, "editor/*.cpp")
# --- Generate binding files ---
# Binding script to run at engine initializing
# The bindings add some functionality for `this.connect(...)`
from misc.generate.bindings import get_bindings_header
from misc.generate.bindings import get_binding_files

files = get_binding_files()
generate(javascript_dir, get_bindings_header(), files)
env_javascript.add_source_files(env.modules_sources, files.keys())
6 changes: 3 additions & 3 deletions generate_builtin_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,11 @@ def parse_class(cls):
)


def generate_api_json(MODULE_DIR):
DOCS_DIR = os.path.abspath(os.path.join(MODULE_DIR, "../../doc/classes"))
def generate_api_json(MODULES_DIR):
DOCS_DIR = os.path.abspath(os.path.join(MODULES_DIR, "../../doc/classes"))
if not os.path.isdir(DOCS_DIR) and len(sys.argv) > 1:
DOCS_DIR = sys.argv[-1]
OUTPUT_FILE = os.path.join(MODULE_DIR, "builtin_api.gen.json")
OUTPUT_FILE = os.path.join(MODULES_DIR, "builtin_api.gen.json")

classes = []
for cls in BUILTIN_CLASSES:
Expand Down
11 changes: 3 additions & 8 deletions javascript_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ JavaScriptLanguage::~JavaScriptLanguage() {
void JavaScriptLanguage::init() {
ERR_FAIL_NULL(main_binder);
main_binder->initialize();
execute_file("modules/javascript/tests/UnitTest.js");
}

void JavaScriptLanguage::finish() {
Expand All @@ -65,14 +64,10 @@ void JavaScriptLanguage::finish() {
main_binder->language_finalize();
}

Error JavaScriptLanguage::execute_file(const String &p_path) {
Error JavaScriptLanguage::execute_file(const String &code) {
ERR_FAIL_NULL_V(main_binder, ERR_BUG);
Error err;
String code = FileAccess::get_file_as_string(p_path, &err);
if (err == OK) {
JavaScriptGCHandler eval_ret;
err = main_binder->eval_string(code, JavaScriptBinder::EVAL_TYPE_GLOBAL, p_path, eval_ret);
}
JavaScriptGCHandler eval_ret;
const Error err = main_binder->eval_string(code, JavaScriptBinder::EVAL_TYPE_GLOBAL, "test.js", eval_ret);
return err;
}

Expand Down
8 changes: 7 additions & 1 deletion javascript_language.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ class JavaScriptLanguage : public ScriptLanguage {

virtual void init() override;
virtual void finish() override;
virtual Error execute_file(const String &p_path);

/**
* Executes a js file with JavaScriptBinder - currently used via init() for testing the editor in cicd
* @param code Code as string which should be executed
* @return
*/
virtual Error execute_file(const String &code);

virtual void get_reserved_words(List<String> *p_words) const override;
virtual bool is_control_flow_keyword(String p_keywords) const override;
Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions misc/generate/bindings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def get_bindings_header():
return (
'/* THIS FILE IS GENERATED DO NOT EDIT */\n#include "../javascript_binder.h"\nString JavaScriptBinder::{} = \n{};'
)


def get_binding_files():
return {
"misc/godot.binding_script.gen.cpp": (
"BINDING_SCRIPT_CONTENT",
"misc/binding_script.js",
),
}
25 changes: 25 additions & 0 deletions misc/generate/editor_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
def get_editor_tools_header():
return (
'/* THIS FILE IS GENERATED DO NOT EDIT */\n#include "editor_tools.h"\nString JavaScriptPlugin::{} = \n{};'
)


def get_editor_tools_files():
return {
"editor/godot.d.ts.gen.cpp": (
"BUILTIN_DECLARATION_TEXT",
"misc/typescript/godot.d.ts",
),
"editor/tsconfig.json.gen.cpp": (
"TSCONFIG_CONTENT",
"misc/typescript/tsconfig.json",
),
"editor/decorators.ts.gen.cpp": (
"TS_DECORATORS_CONTENT",
"misc/typescript/decorators.ts",
),
"editor/package.json.gen.cpp": (
"PACKAGE_JSON_CONTENT",
"misc/typescript/package.json",
),
}
37 changes: 37 additions & 0 deletions misc/generate/generate_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import platform, os


def get_path(javascript_dir, path):
return os.path.abspath(os.path.join(javascript_dir, path))


def open_file(javascript_dir, path, mode):
file = get_path(javascript_dir, path)
if platform.python_version() > "3":
return open(file, mode, encoding="utf8")
else:
return open(file, mode)


def dump_text_file_to_cpp(javascript_dir, path):
source = open_file(javascript_dir, path, "r").read()
lines = source.split("\n")
source = ""
length = len(lines)
for i in range(length):
line = lines[i].replace('"', '\\"')
line = '\t"' + line + '\\n"'
if i < length - 1:
line += "\n"
source += line
return source


def generate(javascript_dir, header, tool_fns):
for fn, subs in tool_fns.items():
with open_file(javascript_dir, fn, "w") as fh:
name = subs[0]
file = dump_text_file_to_cpp(javascript_dir, subs[1])
fh.write(header.format(name, file))


13 changes: 13 additions & 0 deletions misc/generate/test_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def get_test_manager_header():
return (
'/* THIS FILE IS GENERATED DO NOT EDIT */\n#include "test_manager.h"\nString TestManager::{} = \n{};'
)


def get_test_files():
return {
"src/tests/godot.unit_test.gen.cpp": (
"UNIT_TEST",
"src/tests/UnitTest.js",
),
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Loading