diff --git a/BUILD.bazel b/BUILD.bazel index ffd3733..09bf913 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,6 +1,5 @@ -load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") -load("@rules_ecsact//ecsact:toolchain.bzl", "ecsact_toolchain") load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") package(default_visibility = ["//:__subpackages__"]) @@ -13,16 +12,3 @@ alias( visibility = ["//visibility:public"], actual = "//ecsact/cli:ecsact", ) - -ecsact_toolchain( - name = "ecsact_toolchain", - visibility = ["//visibility:public"], - target_tool = ":ecsact_cli", -) - -toolchain( - name = "toolchain", - visibility = ["//visibility:public"], - toolchain = ":ecsact_toolchain", - toolchain_type = "@rules_ecsact//ecsact:toolchain_type", -) diff --git a/MODULE.bazel b/MODULE.bazel index f94e496..5df88de 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -16,7 +16,6 @@ bazel_dep(name = "ecsact_codegen", version = "0.1.2") bazel_dep(name = "boost.dll", version = "1.83.0.bzl.2") bazel_dep(name = "magic_enum", version = "0.9.3") bazel_dep(name = "docopt.cpp", version = "0.6.2") -bazel_dep(name = "rules_ecsact", version = "0.4.9") bazel_dep(name = "boost.process", version = "1.83.0.bzl.2") bazel_dep(name = "boost.algorithm", version = "1.83.0.bzl.1") bazel_dep(name = "toolchains_llvm", version = "0.10.3") diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 3538bc8..0554ecf 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -1,6 +1,6 @@ { "lockFileVersion": 6, - "moduleFileHash": "53a76cdb79bd175317f4bfb6f9cb480ff328f3dd30389e09dd35495ab08c0bc0", + "moduleFileHash": "496e695d075f5e57fe74e21d38acf071e68c5daa81478a91d376fef0b2e11793", "flags": { "cmdRegistries": [ "https://raw.githubusercontent.com/ecsact-dev/bazel_registry/main", @@ -39,7 +39,6 @@ "boost.dll": "boost.dll@1.83.0.bzl.2", "magic_enum": "magic_enum@0.9.3", "docopt.cpp": "docopt.cpp@0.6.2", - "rules_ecsact": "rules_ecsact@0.4.9", "boost.process": "boost.process@1.83.0.bzl.2", "boost.algorithm": "boost.algorithm@1.83.0.bzl.1", "toolchains_llvm": "toolchains_llvm@0.10.3", @@ -438,35 +437,6 @@ } } }, - "rules_ecsact@0.4.9": { - "name": "rules_ecsact", - "version": "0.4.9", - "key": "rules_ecsact@0.4.9", - "repoName": "rules_ecsact", - "executionPlatformsToRegister": [], - "toolchainsToRegister": [], - "extensionUsages": [], - "deps": { - "rules_cc": "rules_cc@0.0.9", - "bazel_skylib": "bazel_skylib@1.4.2", - "platforms": "platforms@0.0.7", - "bazel_tools": "bazel_tools@_", - "local_config_platform": "local_config_platform@_" - }, - "repoSpec": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_archive", - "attributes": { - "urls": [ - "https://github.com/ecsact-dev/rules_ecsact/releases/download/0.4.9/rules_ecsact-0.4.9.tar.gz" - ], - "integrity": "sha256-o7Q4T9JMPy93vmP3g3rehIo+0TzaxbgsgS1PT52yNzE=", - "strip_prefix": "", - "remote_patches": {}, - "remote_patch_strip": 0 - } - } - }, "boost.process@1.83.0.bzl.2": { "name": "boost.process", "version": "1.83.0.bzl.2", diff --git a/ecsact/cli/commands/build.cc b/ecsact/cli/commands/build.cc index 8221ee4..e5e5f10 100644 --- a/ecsact/cli/commands/build.cc +++ b/ecsact/cli/commands/build.cc @@ -48,8 +48,8 @@ constexpr auto USAGE = R"docopt(Ecsact Build Command // text : Human readable text format auto ecsact::cli::detail::build_command( // - int argc, - char* argv[] + int argc, + const char* argv[] ) -> int { auto args = docopt::docopt(USAGE, {argv + 1, argv + argc}); auto format = args["--format"].asString(); diff --git a/ecsact/cli/commands/build.hh b/ecsact/cli/commands/build.hh index a70aa3f..08755ad 100644 --- a/ecsact/cli/commands/build.hh +++ b/ecsact/cli/commands/build.hh @@ -7,7 +7,7 @@ namespace ecsact::cli::detail { -int build_command(int argc, char* argv[]); +int build_command(int argc, const char* argv[]); static_assert(std::is_same_v); } // namespace ecsact::cli::detail diff --git a/ecsact/cli/commands/codegen.cc b/ecsact/cli/commands/codegen.cc index e4491f4..25f31ef 100644 --- a/ecsact/cli/commands/codegen.cc +++ b/ecsact/cli/commands/codegen.cc @@ -48,7 +48,7 @@ static void file_write_fn(const char* str, int32_t str_len) { file_write_stream << std::string_view(str, str_len); } -int ecsact::cli::detail::codegen_command(int argc, char* argv[]) { +int ecsact::cli::detail::codegen_command(int argc, const char* argv[]) { using namespace std::string_literals; auto args = docopt::docopt(USAGE, {argv + 1, argv + argc}); diff --git a/ecsact/cli/commands/codegen.hh b/ecsact/cli/commands/codegen.hh index 180ca12..22e739f 100644 --- a/ecsact/cli/commands/codegen.hh +++ b/ecsact/cli/commands/codegen.hh @@ -1,12 +1,23 @@ #pragma once #include +#include +#include #include "./command.hh" namespace ecsact::cli::detail { -int codegen_command(int argc, char* argv[]); +int codegen_command(int argc, const char* argv[]); static_assert(std::is_same_v); +inline auto codegen_command(std::vector args) -> int { + auto c_args = std::vector(); + c_args.reserve(args.size()); + for(auto& arg : args) { + c_args.emplace_back(arg.c_str()); + } + return codegen_command(c_args.size(), c_args.data()); +} + } // namespace ecsact::cli::detail diff --git a/ecsact/cli/commands/command.hh b/ecsact/cli/commands/command.hh index d42c54a..b1fef63 100644 --- a/ecsact/cli/commands/command.hh +++ b/ecsact/cli/commands/command.hh @@ -2,6 +2,6 @@ namespace ecsact::cli::detail { -using command_fn_t = int (*)(int argc, char* argv[]); +using command_fn_t = int (*)(int argc, const char* argv[]); } diff --git a/ecsact/cli/commands/config.cc b/ecsact/cli/commands/config.cc index 83d7031..a6d1fee 100644 --- a/ecsact/cli/commands/config.cc +++ b/ecsact/cli/commands/config.cc @@ -44,7 +44,7 @@ constexpr auto CANNOT_FIND_PLUGIN_DIR = R"( https://github.com/ecsact-dev/ecsact_sdk/issues )"; -int ecsact::cli::detail::config_command(int argc, char* argv[]) { +int ecsact::cli::detail::config_command(int argc, const char* argv[]) { using namespace std::string_literals; auto args = docopt::docopt(USAGE, {argv + 1, argv + argc}); diff --git a/ecsact/cli/commands/config.hh b/ecsact/cli/commands/config.hh index 3101882..93ea54b 100644 --- a/ecsact/cli/commands/config.hh +++ b/ecsact/cli/commands/config.hh @@ -6,7 +6,7 @@ namespace ecsact::cli::detail { -int config_command(int argc, char* argv[]); +int config_command(int argc, const char* argv[]); static_assert(std::is_same_v); } // namespace ecsact::cli::detail diff --git a/test/.bazelrc b/test/.bazelrc index e279b9d..2c0a9b2 100644 --- a/test/.bazelrc +++ b/test/.bazelrc @@ -5,4 +5,6 @@ build --@boost.process//:use_std_fs query --@boost.dll//:use_std_fs query --@boost.process//:use_std_fs +build --nocheck_visibility + try-import %workspace%/user.bazelrc diff --git a/test/BUILD.bazel b/test/BUILD.bazel index 725b7cb..7ecd4e3 100644 --- a/test/BUILD.bazel +++ b/test/BUILD.bazel @@ -1,12 +1,10 @@ -load("@bazel_skylib//rules:build_test.bzl", "build_test") load("@ecsact_cli//bazel:copts.bzl", "copts") -load("@rules_cc//cc:defs.bzl", "cc_binary") -load("@rules_ecsact//ecsact:defs.bzl", "ecsact_codegen", "ecsact_codegen_plugin") +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_test") package(default_visibility = ["//:__subpackages__"]) cc_binary( - name = "test_codegen_plugin_bin", + name = "test_codegen_plugin", linkshared = True, copts = copts, srcs = [ @@ -15,27 +13,26 @@ cc_binary( ], deps = [ "@ecsact_codegen//:plugin", + "@ecsact_runtime//:dylib", "@ecsact_runtime//dylib:meta", "@ecsact_runtime//dylib:util", ], + defines = ["ECSACT_META_API_LOAD_AT_RUNTIME"], ) -ecsact_codegen_plugin( - name = "test_codegen_plugin", - plugin = ":test_codegen_plugin_bin", - output_extension = "txt", -) - -ecsact_codegen( - name = "codegen_test", - output_directory = "_codegen_test", - srcs = ["test.ecsact"], - plugins = [":test_codegen_plugin"], -) - -build_test( - name = "build_test", - targets = [ - ":codegen_test", +cc_test( + name = "test_codegen", + copts = copts, + srcs = ["test_codegen.cc"], + data = [ + "test.ecsact", + ":test_codegen_plugin", + ], + deps = [ + "@ecsact_interpret", + "@bazel_tools//tools/cpp/runfiles", + "@ecsact_cli//ecsact/cli/commands:codegen", + "@googletest//:gtest", + "@googletest//:gtest_main", ], ) diff --git a/test/MODULE.bazel b/test/MODULE.bazel index 916e2e0..7ae233f 100644 --- a/test/MODULE.bazel +++ b/test/MODULE.bazel @@ -6,8 +6,10 @@ bazel_dep(name = "ecsact_codegen", version = "0.1.3") bazel_dep(name = "boost.dll", version = "1.83.0.bzl.2") bazel_dep(name = "boost.process", version = "1.83.0.bzl.2") bazel_dep(name = "ecsact_runtime", version = "0.5.1") +bazel_dep(name = "ecsact_interpret", version = "0.5.0") bazel_dep(name = "toolchains_llvm", version = "0.10.3") bazel_dep(name = "hedron_compile_commands", dev_dependency = True) +bazel_dep(name = "googletest", version = "1.14.0") bazel_dep(name = "ecsact_cli") bazel_dep(name = "yaml-cpp") @@ -28,8 +30,6 @@ git_override( commit = "204aa593e002cbd177d30f11f54cff3559110bb9", ) -register_toolchains("@ecsact_cli//:all") - llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm") llvm.toolchain(llvm_version = "16.0.4") diff --git a/test/MODULE.bazel.lock b/test/MODULE.bazel.lock index 76d83a6..fe7547b 100644 --- a/test/MODULE.bazel.lock +++ b/test/MODULE.bazel.lock @@ -1,6 +1,6 @@ { "lockFileVersion": 6, - "moduleFileHash": "6e5bf5ebd2c9920717564e0a87ae400fce2dd999364a58c91db8827344d76994", + "moduleFileHash": "d37b3c71acecff3dfaa5cd9a2f1e20dffc418b5ea9c22538080d6529ed1e704b", "flags": { "cmdRegistries": [ "https://raw.githubusercontent.com/ecsact-dev/bazel_registry/main", @@ -16,7 +16,7 @@ }, "localOverrideHashes": { "bazel_tools": "1ae69322ac3823527337acf02016e8ee95813d8d356f47060255b8956fa642f0", - "ecsact_cli": "53a76cdb79bd175317f4bfb6f9cb480ff328f3dd30389e09dd35495ab08c0bc0" + "ecsact_cli": "496e695d075f5e57fe74e21d38acf071e68c5daa81478a91d376fef0b2e11793" }, "moduleDepGraph": { "": { @@ -26,7 +26,6 @@ "repoName": "ecsact_cli_test", "executionPlatformsToRegister": [], "toolchainsToRegister": [ - "@ecsact_cli//:all", "@llvm_toolchain//:all" ], "extensionUsages": [ @@ -68,8 +67,10 @@ "boost.dll": "boost.dll@1.83.0.bzl.2", "boost.process": "boost.process@1.83.0.bzl.2", "ecsact_runtime": "ecsact_runtime@0.5.1", + "ecsact_interpret": "ecsact_interpret@0.5.0", "toolchains_llvm": "toolchains_llvm@0.10.3", "hedron_compile_commands": "hedron_compile_commands@_", + "googletest": "googletest@1.14.0", "ecsact_cli": "ecsact_cli@_", "yaml-cpp": "yaml-cpp@_", "bazel_tools": "bazel_tools@_", @@ -306,6 +307,37 @@ } } }, + "ecsact_interpret@0.5.0": { + "name": "ecsact_interpret", + "version": "0.5.0", + "key": "ecsact_interpret@0.5.0", + "repoName": "ecsact_interpret", + "executionPlatformsToRegister": [], + "toolchainsToRegister": [], + "extensionUsages": [], + "deps": { + "rules_cc": "rules_cc@0.0.9", + "bazel_skylib": "bazel_skylib@1.4.2", + "magic_enum": "magic_enum@0.9.3", + "ecsact_runtime": "ecsact_runtime@0.5.1", + "ecsact_parse": "ecsact_parse@0.3.0", + "bazel_tools": "bazel_tools@_", + "local_config_platform": "local_config_platform@_" + }, + "repoSpec": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_archive", + "attributes": { + "urls": [ + "https://github.com/ecsact-dev/ecsact_interpret/releases/download/0.5.0/ecsact_interpret-0.5.0.tar.gz" + ], + "integrity": "sha256-EWeVy16rNkSbHThZIGe5PP3kwRFOlgnDLDL2gW+NKLQ=", + "strip_prefix": "", + "remote_patches": {}, + "remote_patch_strip": 0 + } + } + }, "toolchains_llvm@0.10.3": { "name": "toolchains_llvm", "version": "0.10.3", @@ -409,6 +441,37 @@ "local_config_platform": "local_config_platform@_" } }, + "googletest@1.14.0": { + "name": "googletest", + "version": "1.14.0", + "key": "googletest@1.14.0", + "repoName": "googletest", + "executionPlatformsToRegister": [], + "toolchainsToRegister": [], + "extensionUsages": [], + "deps": { + "com_google_absl": "abseil-cpp@20230802.0", + "platforms": "platforms@0.0.7", + "rules_cc": "rules_cc@0.0.9", + "bazel_tools": "bazel_tools@_", + "local_config_platform": "local_config_platform@_" + }, + "repoSpec": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_archive", + "attributes": { + "urls": [ + "https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz" + ], + "integrity": "sha256-itWYxzrXluDYKAsILOvYKmMNc+c808cAV5OKZQG7pdc=", + "strip_prefix": "googletest-1.14.0", + "remote_patches": { + "https://bcr.bazel.build/modules/googletest/1.14.0/patches/module_dot_bazel.patch": "sha256-CSomzvti38LCuURDG5EEoa3O1tQF3cKKt/mknnP1qcc=" + }, + "remote_patch_strip": 0 + } + } + }, "ecsact_cli@_": { "name": "ecsact_cli", "version": "0.2.3", @@ -430,7 +493,6 @@ "boost.dll": "boost.dll@1.83.0.bzl.2", "magic_enum": "magic_enum@0.9.3", "docopt.cpp": "docopt.cpp@0.6.2", - "rules_ecsact": "rules_ecsact@0.4.9", "boost.process": "boost.process@1.83.0.bzl.2", "boost.algorithm": "boost.algorithm@1.83.0.bzl.1", "toolchains_llvm": "toolchains_llvm@0.10.3", @@ -1467,37 +1529,6 @@ } } }, - "googletest@1.14.0": { - "name": "googletest", - "version": "1.14.0", - "key": "googletest@1.14.0", - "repoName": "googletest", - "executionPlatformsToRegister": [], - "toolchainsToRegister": [], - "extensionUsages": [], - "deps": { - "com_google_absl": "abseil-cpp@20230802.0", - "platforms": "platforms@0.0.7", - "rules_cc": "rules_cc@0.0.9", - "bazel_tools": "bazel_tools@_", - "local_config_platform": "local_config_platform@_" - }, - "repoSpec": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_archive", - "attributes": { - "urls": [ - "https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz" - ], - "integrity": "sha256-itWYxzrXluDYKAsILOvYKmMNc+c808cAV5OKZQG7pdc=", - "strip_prefix": "googletest-1.14.0", - "remote_patches": { - "https://bcr.bazel.build/modules/googletest/1.14.0/patches/module_dot_bazel.patch": "sha256-CSomzvti38LCuURDG5EEoa3O1tQF3cKKt/mknnP1qcc=" - }, - "remote_patch_strip": 0 - } - } - }, "abseil-cpp@20230802.0": { "name": "abseil-cpp", "version": "20230802.0", @@ -1531,47 +1562,17 @@ } } }, - "nlohmann_json@3.11.2": { - "name": "nlohmann_json", - "version": "3.11.2", - "key": "nlohmann_json@3.11.2", - "repoName": "nlohmann_json", - "executionPlatformsToRegister": [], - "toolchainsToRegister": [], - "extensionUsages": [], - "deps": { - "bazel_tools": "bazel_tools@_", - "local_config_platform": "local_config_platform@_" - }, - "repoSpec": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_archive", - "attributes": { - "urls": [ - "https://github.com/nlohmann/json/releases/download/v3.11.2/include.zip" - ], - "integrity": "sha256-5cep9JoWgUvifk7Q7pAOzQCSv7fb/KZbWkIbd03Mqu0=", - "strip_prefix": "", - "remote_patches": { - "https://bcr.bazel.build/modules/nlohmann_json/3.11.2/patches/add_build_file.patch": "sha256-q7pmw7dn3H7Le3BgkydhrvZG+1e75JisnM+PLaPjCI0=", - "https://bcr.bazel.build/modules/nlohmann_json/3.11.2/patches/module_dot_bazel.patch": "sha256-4E6P0FnfLJWN8VA/XZ5FYHckplxTTGMS3BZS7YtA26A=" - }, - "remote_patch_strip": 0 - } - } - }, - "rules_pkg@0.9.1": { - "name": "rules_pkg", - "version": "0.9.1", - "key": "rules_pkg@0.9.1", - "repoName": "rules_pkg", + "magic_enum@0.9.3": { + "name": "magic_enum", + "version": "0.9.3", + "key": "magic_enum@0.9.3", + "repoName": "magic_enum", "executionPlatformsToRegister": [], "toolchainsToRegister": [], "extensionUsages": [], "deps": { - "rules_license": "rules_license@0.0.7", + "rules_cc": "rules_cc@0.0.9", "bazel_skylib": "bazel_skylib@1.4.2", - "rules_python": "rules_python@0.22.1", "bazel_tools": "bazel_tools@_", "local_config_platform": "local_config_platform@_" }, @@ -1580,10 +1581,10 @@ "ruleClassName": "http_archive", "attributes": { "urls": [ - "https://github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz" + "https://github.com/Neargye/magic_enum/archive/d705e50884d9647ddff3fc1b08d96c9cd4ce530a.tar.gz" ], - "integrity": "sha256-j57i3BDBrlFO5ZmotC7Zn6Jit1cFj2WtPDhCif9wxLg=", - "strip_prefix": "", + "integrity": "sha256-Gr63VODz0fDuhOW4suocH47Mgpc5MtKLbQA7dOEQ4PI=", + "strip_prefix": "magic_enum-d705e50884d9647ddff3fc1b08d96c9cd4ce530a", "remote_patches": {}, "remote_patch_strip": 0 } @@ -1620,20 +1621,15 @@ } } }, - "ecsact_interpret@0.5.0": { - "name": "ecsact_interpret", - "version": "0.5.0", - "key": "ecsact_interpret@0.5.0", - "repoName": "ecsact_interpret", + "nlohmann_json@3.11.2": { + "name": "nlohmann_json", + "version": "3.11.2", + "key": "nlohmann_json@3.11.2", + "repoName": "nlohmann_json", "executionPlatformsToRegister": [], "toolchainsToRegister": [], "extensionUsages": [], "deps": { - "rules_cc": "rules_cc@0.0.9", - "bazel_skylib": "bazel_skylib@1.4.2", - "magic_enum": "magic_enum@0.9.3", - "ecsact_runtime": "ecsact_runtime@0.5.1", - "ecsact_parse": "ecsact_parse@0.3.0", "bazel_tools": "bazel_tools@_", "local_config_platform": "local_config_platform@_" }, @@ -1642,26 +1638,30 @@ "ruleClassName": "http_archive", "attributes": { "urls": [ - "https://github.com/ecsact-dev/ecsact_interpret/releases/download/0.5.0/ecsact_interpret-0.5.0.tar.gz" + "https://github.com/nlohmann/json/releases/download/v3.11.2/include.zip" ], - "integrity": "sha256-EWeVy16rNkSbHThZIGe5PP3kwRFOlgnDLDL2gW+NKLQ=", + "integrity": "sha256-5cep9JoWgUvifk7Q7pAOzQCSv7fb/KZbWkIbd03Mqu0=", "strip_prefix": "", - "remote_patches": {}, + "remote_patches": { + "https://bcr.bazel.build/modules/nlohmann_json/3.11.2/patches/add_build_file.patch": "sha256-q7pmw7dn3H7Le3BgkydhrvZG+1e75JisnM+PLaPjCI0=", + "https://bcr.bazel.build/modules/nlohmann_json/3.11.2/patches/module_dot_bazel.patch": "sha256-4E6P0FnfLJWN8VA/XZ5FYHckplxTTGMS3BZS7YtA26A=" + }, "remote_patch_strip": 0 } } }, - "magic_enum@0.9.3": { - "name": "magic_enum", - "version": "0.9.3", - "key": "magic_enum@0.9.3", - "repoName": "magic_enum", + "rules_pkg@0.9.1": { + "name": "rules_pkg", + "version": "0.9.1", + "key": "rules_pkg@0.9.1", + "repoName": "rules_pkg", "executionPlatformsToRegister": [], "toolchainsToRegister": [], "extensionUsages": [], "deps": { - "rules_cc": "rules_cc@0.0.9", + "rules_license": "rules_license@0.0.7", "bazel_skylib": "bazel_skylib@1.4.2", + "rules_python": "rules_python@0.22.1", "bazel_tools": "bazel_tools@_", "local_config_platform": "local_config_platform@_" }, @@ -1670,10 +1670,10 @@ "ruleClassName": "http_archive", "attributes": { "urls": [ - "https://github.com/Neargye/magic_enum/archive/d705e50884d9647ddff3fc1b08d96c9cd4ce530a.tar.gz" + "https://github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz" ], - "integrity": "sha256-Gr63VODz0fDuhOW4suocH47Mgpc5MtKLbQA7dOEQ4PI=", - "strip_prefix": "magic_enum-d705e50884d9647ddff3fc1b08d96c9cd4ce530a", + "integrity": "sha256-j57i3BDBrlFO5ZmotC7Zn6Jit1cFj2WtPDhCif9wxLg=", + "strip_prefix": "", "remote_patches": {}, "remote_patch_strip": 0 } diff --git a/test/test_codegen.cc b/test/test_codegen.cc new file mode 100644 index 0000000..a7067d2 --- /dev/null +++ b/test/test_codegen.cc @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include +#include +#include "ecsact/cli/commands/codegen.hh" +#include "tools/cpp/runfiles/runfiles.h" + +using bazel::tools::cpp::runfiles::Runfiles; +using ecsact::cli::detail::codegen_command; + +using namespace std::string_literals; +namespace fs = std::filesystem; + +TEST(Codegen, Success) { + auto runfiles_err = std::string{}; + auto runfiles = Runfiles::CreateForTest(&runfiles_err); + ASSERT_NE(runfiles, nullptr) << runfiles_err; + + auto generated_file_path = fs::path{"_test_codegen_outdir/test.ecsact.txt"}; + + if(fs::exists(generated_file_path)) { + fs::remove(generated_file_path); + } + + auto exit_code = codegen_command(std::vector{ + "ecsact"s, + "codegen"s, + runfiles->Rlocation("ecsact_cli_test/test.ecsact"), + std::format( + "--plugin={}", + runfiles->Rlocation("ecsact_cli_test/test_codegen_plugin") + ), + "--outdir=_test_codegen_outdir"s, + }); + + ASSERT_EQ(exit_code, 0); + + ASSERT_TRUE(fs::exists(generated_file_path)); + auto generated_file = std::ifstream{generated_file_path}; + auto generated_file_contents = std::string{ + std::istreambuf_iterator(generated_file), + std::istreambuf_iterator(), + }; + + ASSERT_EQ(generated_file_contents, "this is just a test, breathe!"); +}