From 4d17285415ce6cb73c5d272cf196d38bc5804794 Mon Sep 17 00:00:00 2001 From: tengtengh Date: Mon, 1 Sep 2025 15:17:00 +0800 Subject: [PATCH] Fix empty relative paths Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICVRJ9 Signed-off-by: tengtengh --- ets2panda/parser/ETSparser.cpp | 1 + ets2panda/test/unit/CMakeLists.txt | 1 + .../unit/source_file_message/CMakeLists.txt | 16 +++++++ .../source_file_message_test.cpp | 46 +++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 ets2panda/test/unit/source_file_message/CMakeLists.txt create mode 100644 ets2panda/test/unit/source_file_message/source_file_message_test.cpp diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index e4b25915ea..f8ec301d0a 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -472,6 +472,7 @@ parser::Program *ETSParser::ParseSource(const SourceFile &sourceFile) ES2PANDA_ASSERT(program != nullptr); auto esp = ExternalSourceParser(this, program); auto lexer = InitLexer(sourceFile); + program->SetRelativeFilePath(importPathManager_->FormRelativePath(program->SourceFile())); lexer::SourcePosition startLoc = Lexer()->GetToken().Start(); Lexer()->NextToken(); diff --git a/ets2panda/test/unit/CMakeLists.txt b/ets2panda/test/unit/CMakeLists.txt index 80624e7ddd..15df73ea9f 100644 --- a/ets2panda/test/unit/CMakeLists.txt +++ b/ets2panda/test/unit/CMakeLists.txt @@ -28,6 +28,7 @@ add_subdirectory(annotations) add_subdirectory(lsp) add_subdirectory(relative_path) add_subdirectory(any_ins_test) +add_subdirectory(source_file_message) ets2panda_add_gtest(es2panda_astdumper_tests CPP_SOURCES ast_dumper_test.cpp diff --git a/ets2panda/test/unit/source_file_message/CMakeLists.txt b/ets2panda/test/unit/source_file_message/CMakeLists.txt new file mode 100644 index 0000000000..ba65bb8bfe --- /dev/null +++ b/ets2panda/test/unit/source_file_message/CMakeLists.txt @@ -0,0 +1,16 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +ets2panda_add_gtest(es2panda_source_file_message_test + CPP_SOURCES source_file_message_test.cpp +) \ No newline at end of file diff --git a/ets2panda/test/unit/source_file_message/source_file_message_test.cpp b/ets2panda/test/unit/source_file_message/source_file_message_test.cpp new file mode 100644 index 0000000000..f09554d639 --- /dev/null +++ b/ets2panda/test/unit/source_file_message/source_file_message_test.cpp @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include "assembly-program.h" +#include "test/utils/asm_test.h" + +namespace ark::es2panda::compiler::test { +class SourceFileMsgTest : public ::test::utils::AsmTest { +public: + SourceFileMsgTest() = default; + + ~SourceFileMsgTest() override = default; + +private: + NO_COPY_SEMANTIC(SourceFileMsgTest); + NO_MOVE_SEMANTIC(SourceFileMsgTest); +}; + +TEST_F(SourceFileMsgTest, source_file_msg_test) +{ + std::string_view text = R"( + class A {} + )"; + + auto program = GetCurrentProgram(text); + const auto &recordTable = program.get()->recordTable; + auto sourceFile = recordTable.find("ETSGLOBAL"); + ASSERT_EQ(sourceFile->second.sourceFile, "dummy.ets"); +} + +} // namespace ark::es2panda::compiler::test \ No newline at end of file -- Gitee