Skip to content

Commit

Permalink
test(aspect): Add test for providing defines via cxxopt
Browse files Browse the repository at this point in the history
  • Loading branch information
martis42 committed Jan 5, 2025
1 parent 823dc9d commit 2843e18
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/aspect/defines/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,10 @@ cc_library(
"//defines/support:some_defines",
],
)

# This target can only be analyzed by setting the correct defines via the command line
cc_library(
name = "use_command_line_defines",
hdrs = ["use_command_line_defines.h"],
tags = ["manual"],
)
26 changes: 26 additions & 0 deletions test/aspect/defines/test_command_line_defines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from platform import system

from expected_result import ExpectedResult
from test_case import TestCaseBase

from test.support.result import Result


def make_define(flag: str) -> str:
"""
MVSC on Windows has another syntax than gcc and clang
"""
control_character = "/" if system() == "Windows" else "-"
return f"{control_character}D{flag}"


class TestCase(TestCaseBase):
def execute_test_logic(self) -> Result:
expected = ExpectedResult(success=True)
actual = self._run_dwyu(
target="//defines:use_command_line_defines",
aspect=self.default_aspect,
extra_args=[f"--cxxopt={make_define('SOME_FLAG')}", f"--cxxopt={make_define('SOME_VALUE=42')}"],
)

return self._check_result(actual=actual, expected=expected)
11 changes: 11 additions & 0 deletions test/aspect/defines/use_command_line_defines.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifdef SOME_FLAG
// do some things irrelevant for DWYU
#else
#include "not/extsting/header.h"
#endif

#if SOME_VALUE > 40
// do some things irrelevant for DWYU
#else
#include "not/extsting/header.h"
#endif

0 comments on commit 2843e18

Please sign in to comment.