diff --git a/src/include_diagram/visitor/translation_unit_visitor.cc b/src/include_diagram/visitor/translation_unit_visitor.cc index 53483b182..f20cc1442 100644 --- a/src/include_diagram/visitor/translation_unit_visitor.cc +++ b/src/include_diagram/visitor/translation_unit_visitor.cc @@ -220,8 +220,9 @@ translation_unit_visitor::include_visitor::process_source_file( const std::string implementation_suffix_prefix{".c"}; if (file_path.has_extension() && - util::starts_with( - file_path.extension().string(), implementation_suffix_prefix)) { + (util::starts_with(file_path.extension().string(), + implementation_suffix_prefix) || + file_path.extension() == ".m")) { source_file.set_type(source_file_t::kImplementation); } else diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1ae566edf..6af965a04 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,6 +1,6 @@ file(GLOB_RECURSE TEST_CASE_SOURCES t*/*.cc t*/*.c t*/src/*.c t*/*.cu) -file(GLOB_RECURSE TEST_CASES_OBJC_SOURCES t*/*.m) +file(GLOB_RECURSE TEST_CASES_OBJC_SOURCES t*/*.m t*/src/*.m) file(GLOB_RECURSE TEST_CASE_MODULE_SOURCES t*/src/*.cppm) file(GLOB_RECURSE TEST_CASE_CONFIGS t*/.clang-uml) file(GLOB_RECURSE TEST_CONFIG_YMLS test_config_data/*.yml @@ -11,7 +11,7 @@ set(TEST_CASES_REQUIRING_CXX20 t00056 t00058 t00059 t00065 t00069 t00074 t00075) set(TEST_CASES_REQUIRING_CXX20_MODULES t00070 t00071 t00072 t30012 t30013 t30014 t30015) set(TEST_CASES_REQUIRING_CUDA t20049 t20050 t20051) -set(TEST_CASES_REQUIRING_OBJC t00084 t00085 t30016) +set(TEST_CASES_REQUIRING_OBJC t00084 t00085 t30016 t40004) if(ENABLE_OBJECTIVE_C_TEST_CASES) message(STATUS "Enabling Objective-C test cases: ${TEST_CASES_OBJC_SOURCES}") @@ -113,7 +113,7 @@ foreach(TEST_NAME ${TEST_NAMES}) endif(ENABLE_CXX_MODULES_TEST_CASES) if(ENABLE_OBJECTIVE_C_TEST_CASES) add_library(test_cases_objc) - target_compile_options(test_cases_objc PUBLIC -MMD -MP -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1 -DGNU_GUI_LIBRARY=1 -DGNU_RUNTIME=1 -fno-strict-aliasing -fexceptions -fblocks -fobjc-runtime=gnustep-2.0 -fobjc-exceptions -D_NATIVE_OBJC_EXCEPTIONS -pthread -fPIC -Wall -DGSWARN -DGSDIAGNOSE -Wno-import -g -fconstant-string-class=NSConstantString -I/usr/local/include/GNUstep -I/usr/include/GNUstep) + target_compile_options(test_cases_objc PUBLIC -MMD -MP -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1 -DGNU_GUI_LIBRARY=1 -DGNU_RUNTIME=1 -fno-strict-aliasing -fexceptions -fblocks -fobjc-runtime=gnustep-2.0 -fobjc-exceptions -D_NATIVE_OBJC_EXCEPTIONS -pthread -fPIC -Wall -DGSWARN -DGSDIAGNOSE -Wno-import -g -fconstant-string-class=NSConstantString -I/usr/local/include/GNUstep -I/usr/include/GNUstep -I/usr/lib/clang/18/include -I/usr/local/include/GNUstep -I/usr/include/GNUstep -I/usr/local/include/) # Link the GNUstep libraries target_link_libraries(test_cases_objc -shared-libgcc -pthread -fexceptions -rdynamic -L/usr/local/lib -L/usr/lib -lgnustep-base -lobjc -lm) diff --git a/tests/t40004/.clang-uml b/tests/t40004/.clang-uml new file mode 100644 index 000000000..4d1bc1b15 --- /dev/null +++ b/tests/t40004/.clang-uml @@ -0,0 +1,11 @@ +diagrams: + t40004_include: + type: include + glob: + - src/lib1/lib1.m + - src/lib2/lib2.m + - src/t40004.m + include: + paths: + - include + - src \ No newline at end of file diff --git a/tests/t40004/include/lib1/lib1.h b/tests/t40004/include/lib1/lib1.h new file mode 100644 index 000000000..c7dd7e878 --- /dev/null +++ b/tests/t40004/include/lib1/lib1.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +@interface Lib1 : NSObject + +@end \ No newline at end of file diff --git a/tests/t40004/include/lib2/lib2.h b/tests/t40004/include/lib2/lib2.h new file mode 100644 index 000000000..ef7642156 --- /dev/null +++ b/tests/t40004/include/lib2/lib2.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +@interface Lib2 : NSObject + +@end \ No newline at end of file diff --git a/tests/t40004/src/lib1/lib1.m b/tests/t40004/src/lib1/lib1.m new file mode 100644 index 000000000..6b52c91a5 --- /dev/null +++ b/tests/t40004/src/lib1/lib1.m @@ -0,0 +1 @@ +#include "../../include/lib1/lib1.h" \ No newline at end of file diff --git a/tests/t40004/src/lib2/lib2.m b/tests/t40004/src/lib2/lib2.m new file mode 100644 index 000000000..e0dacd4bd --- /dev/null +++ b/tests/t40004/src/lib2/lib2.m @@ -0,0 +1 @@ +#include "../../include/lib2/lib2.h" \ No newline at end of file diff --git a/tests/t40004/src/t40004.m b/tests/t40004/src/t40004.m new file mode 100644 index 000000000..62a26e870 --- /dev/null +++ b/tests/t40004/src/t40004.m @@ -0,0 +1,12 @@ +#include "../include/lib1/lib1.h" +#include "../include/lib2/lib2.h" + + +@interface t40004_D : NSObject { +} + +@property (nonatomic, assign) Lib1 *l1; +@property (nonatomic, assign) Lib2 *l2; + + +@end \ No newline at end of file diff --git a/tests/t40004/test_case.h b/tests/t40004/test_case.h new file mode 100644 index 000000000..3a68b5315 --- /dev/null +++ b/tests/t40004/test_case.h @@ -0,0 +1,50 @@ +/** + * tests/t40004/test_case.h + * + * Copyright (c) 2021-2024 Bartek Kryza + * + * 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. + */ + +TEST_CASE("t40004") +{ + using namespace clanguml::test; + using namespace std::string_literals; + + auto [config, db, diagram, model] = + CHECK_INCLUDE_MODEL("t40004", "t40004_include"); + + CHECK_INCLUDE_DIAGRAM(*config, diagram, *model, [](const auto &src) { + REQUIRE(IsFolder(src, "src")); + REQUIRE(IsFolder(src, "src/lib1")); + REQUIRE(IsFolder(src, "src/lib2")); + REQUIRE(IsFolder(src, "include")); + REQUIRE(IsFolder(src, "include/lib1")); + REQUIRE(IsFolder(src, "include/lib2")); + + REQUIRE(IsFile(src, "include/lib1/lib1.h")); + REQUIRE(IsFile(src, "include/lib2/lib2.h")); + + REQUIRE(IsFile(src, "src/t40004.m")); + + REQUIRE(IsFile(src, "src/lib1/lib1.m")); + REQUIRE(IsFile(src, "src/lib2/lib2.m")); + + REQUIRE(IsHeaderDependency(src, "src/t40004.m", "include/lib1/lib1.h")); + REQUIRE(IsHeaderDependency(src, "src/t40004.m", "include/lib2/lib2.h")); + REQUIRE( + IsHeaderDependency(src, "src/lib1/lib1.m", "include/lib1/lib1.h")); + REQUIRE( + IsHeaderDependency(src, "src/lib2/lib2.m", "include/lib2/lib2.h")); + }); +} \ No newline at end of file diff --git a/tests/test_cases.cc b/tests/test_cases.cc index ac77c1819..b325dc0f6 100644 --- a/tests/test_cases.cc +++ b/tests/test_cases.cc @@ -664,10 +664,10 @@ void CHECK_INCLUDE_DIAGRAM(const clanguml::config::config &config, /// /// Include diagram tests /// - #include "t40001/test_case.h" #include "t40002/test_case.h" #include "t40003/test_case.h" +#include "t40004/test_case.h" /// /// Other tests (e.g. configuration file) @@ -686,8 +686,8 @@ int main(int argc, char *argv[]) clanguml::cli::cli_handler clih; - std::vector argvv = { - "clang-uml", "--config", "./test_config_data/simple.yml"}; + std::vector argvv = {"clang-uml", "--query-driver", ".", + "--config", "./test_config_data/simple.yml"}; argvv.push_back("-q"); diff --git a/tests/test_cases.yaml b/tests/test_cases.yaml index d804e70cd..c7220ae4e 100644 --- a/tests/test_cases.yaml +++ b/tests/test_cases.yaml @@ -477,6 +477,9 @@ test_cases: - name: t40003 title: Dependants and dependencies include diagram filter test description: + - name: t40004 + title: Objective C include diagram test + description: Configuration diagrams: - name: t90000 title: Basic config test