diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index e4b25915ea843bfd0b9febf3a5945ebebd39ad08..f8ec301d0aa37933a653dbf686feab4303066cde 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 80624e7dddba2d16652860b3aa9de304712c058a..15df73ea9f898e7ad047badf3866abb203f71c71 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 0000000000000000000000000000000000000000..ba65bb8bfee8cbb5eeecab1da3e5f4b1ce88c166 --- /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 0000000000000000000000000000000000000000..f09554d6395248d65fcce0199dd55c73a3ff9fa4 --- /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