Skip to content

Commit

Permalink
Make the apsect tests proper integration tests
Browse files Browse the repository at this point in the history
Incorporating bzlmod and creating the examples showed us that we overlooked
problems due to the old test setup not being real integration tests.
Now DWYU is a proper external dependency for the integration tests, as it is
in the examples.
  • Loading branch information
martis42 committed Jan 4, 2024
1 parent 204e576 commit f0012be
Show file tree
Hide file tree
Showing 104 changed files with 350 additions and 235 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Integration tests - Aspect
run: ./test/aspect/execute_tests.py
run: |
cd test/aspect
./execute_tests.py
integration-tests-apply-fixes:
runs-on: ubuntu-22.04
Expand Down
20 changes: 0 additions & 20 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,6 @@ non_module_dev_dependencies = use_extension(
)
use_repo(non_module_dev_dependencies, "mypy_integration")

bazel_dep(
name = "external_test_repo",
version = "0.0.0",
dev_dependency = True,
)
local_path_override(
module_name = "external_test_repo",
path = "test/aspect/external_repo/repo",
)

bazel_dep(
name = "complex_includes_test_repo",
version = "0.0.0",
dev_dependency = True,
)
local_path_override(
module_name = "complex_includes_test_repo",
path = "test/aspect/complex_includes/ext_repo",
)

###
### The Migration phase using WORKSPACE.bzlmod and MODULE.bazel together does not support properly loading the implicit
### Bazel dependencies. Thus, we need to load some basic things directly. This should become superfluous when we are
Expand Down
8 changes: 0 additions & 8 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,3 @@ dev_setup_step_2()
load("//:dev_setup_step_3.bzl", "dev_setup_step_3")

dev_setup_step_3()

#
# Testing
#

load("//test/aspect:test.bzl", "test_setup")

test_setup()
14 changes: 14 additions & 0 deletions test/aspect/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# When working with hermetic Python toolchains, supporting the legacy runfiles layout is needlessly wasting resources.
# See https://github.com/bazelbuild/rules_python/issues/1653
common --nolegacy_external_runfiles

# The symlinks are annoying
common --experimental_convenience_symlinks=clean

# The performance gains offered by the lockfile are minimal for us.
# Pinning the dependencies should be superfluous from a reproducibility perspective as the central registry is supposed
# to be immutable for a module X in version Y after it has ben registered with the registry (ignoring the possibility of
# yanking a module). Furthermore, the module resolution is deterministic.
# However, there are several open issues suggesting the lock file will change in one way or another.
# Thus, we don't use the bzlmod locking yet.
common --lockfile_mode=off
93 changes: 93 additions & 0 deletions test/aspect/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
module(
name = "dwyu_aspect_integration_tests",
compatibility_level = 0,
)

bazel_dep(
name = "depend_on_what_you_use",
version = "0.0.0",
dev_dependency = True,
)
local_path_override(
module_name = "depend_on_what_you_use",
path = "../../",
)

##
## Python toolchains for testing compatibility to various Python versions
##

bazel_dep(
name = "rules_python",
version = "0.27.0",
dev_dependency = True,
)

# Update with each rules_python update for easy lookup until specifying the patch version for toolchain is possible again
# Keep in syc with execute_tests.py
# PATCH_MAPPING:
# "3.8": "3.8.18"
# "3.9": "3.9.18"
# "3.10": "3.10.13"
# "3.11": "3.11.6"
# "3.12": "3.12.0"
# Choose different version via: --@rules_python//python/config_settings:python_version=Major.Minor.Patch mathing one of
# the registered toolchains below.
python = use_extension(
"@rules_python//python/extensions:python.bzl",
"python",
dev_dependency = True,
)
python.toolchain(
is_default = True,
python_version = "3.8",
)
python.toolchain(
python_version = "3.9",
)
python.toolchain(
python_version = "3.10",
)
python.toolchain(
python_version = "3.11",
)
python.toolchain(
python_version = "3.12",
)

##
## Workspaces for test purposes
##

bazel_dep(
name = "external_test_repo",
version = "0.0.0",
dev_dependency = True,
)
local_path_override(
module_name = "external_test_repo",
path = "external_repo/repo",
)

bazel_dep(
name = "complex_includes_test_repo",
version = "0.0.0",
dev_dependency = True,
)
local_path_override(
module_name = "complex_includes_test_repo",
path = "complex_includes/ext_repo",
)

##
## The Migration phase using WORKSPACE.bzlmod and MODULE.bazel together does not support properly loading the implicit
## Bazel dependencies. Thus, we need to load some basic things directly. This should become superfluous when we are
## only using bzlmod eventually
## Reference https://github.com/bazelbuild/bazel/blob/master/src/MODULE.tools
##

bazel_dep(
name = "platforms",
version = "0.0.7",
dev_dependency = True,
)
54 changes: 54 additions & 0 deletions test/aspect/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
workspace(name = "dwyu_aspect_integration_tests")

local_repository(
name = "depend_on_what_you_use",
path = "../../",
)

load("@depend_on_what_you_use//:setup_step_1.bzl", "setup_step_1")

setup_step_1()

load("@depend_on_what_you_use//:setup_step_2.bzl", "setup_step_2")

setup_step_2()

##
## Python toolchains for testing compatibility to various Python versions
##

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

maybe(
http_archive,
name = "rules_python",
sha256 = "9acc0944c94adb23fba1c9988b48768b1bacc6583b52a2586895c5b7491e2e31",
strip_prefix = "rules_python-0.27.0",
urls = ["https://github.com/bazelbuild/rules_python/releases/download/0.27.0/rules_python-0.27.0.tar.gz"],
)

load("@rules_python//python:repositories.bzl", "python_register_multi_toolchains")

# Choose different version via: --@rules_python//python/config_settings:python_version=X
python_register_multi_toolchains(
name = "python",
default_version = "3.8",
python_versions = [
"3.9",
"3.10",
"3.11",
"3.12",
],
)

##
## Workspaces for test purposes
##

load("//complex_includes:ext_repo.bzl", "load_complex_includes_repo")
load("//external_repo:repo.bzl", "load_external_repo")

load_external_repo()

load_complex_includes_repo()
Empty file added test/aspect/WORKSPACE.bzlmod
Empty file.
2 changes: 1 addition & 1 deletion test/aspect/alias/b.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef B_H
#define B_H

#include "test/aspect/alias/a.h"
#include "alias/a.h"

int doB()
{
Expand Down
4 changes: 2 additions & 2 deletions test/aspect/alias/test_invalid_dependency_through_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class TestCase(TestCaseBase):
def execute_test_logic(self) -> Result:
expected = ExpectedResult(
success=False,
invalid_includes=["File='test/aspect/alias/use_a_and_b.cpp', include='test/aspect/alias/a.h'"],
invalid_includes=["File='alias/use_a_and_b.cpp', include='alias/a.h'"],
)
actual = self._run_dwyu(target="//test/aspect/alias:use_a_transitively", aspect=self.default_aspect)
actual = self._run_dwyu(target="//alias:use_a_transitively", aspect=self.default_aspect)

return self._check_result(actual=actual, expected=expected)
4 changes: 2 additions & 2 deletions test/aspect/alias/test_unused_dependency_through_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class TestCase(TestCaseBase):
def execute_test_logic(self) -> Result:
expected = ExpectedResult(success=False, unused_public_deps=["//test/aspect/alias:lib_a"])
actual = self._run_dwyu(target="//test/aspect/alias:unused_dependency", aspect=self.default_aspect)
expected = ExpectedResult(success=False, unused_public_deps=["//alias:lib_a"])
actual = self._run_dwyu(target="//alias:unused_dependency", aspect=self.default_aspect)

return self._check_result(actual=actual, expected=expected)
2 changes: 1 addition & 1 deletion test/aspect/alias/test_use_dependency_through_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
class TestCase(TestCaseBase):
def execute_test_logic(self) -> Result:
expected = ExpectedResult(success=True)
actual = self._run_dwyu(target="//test/aspect/alias:use_a_directly", aspect=self.default_aspect)
actual = self._run_dwyu(target="//alias:use_a_directly", aspect=self.default_aspect)

return self._check_result(actual=actual, expected=expected)
4 changes: 2 additions & 2 deletions test/aspect/alias/use_a_and_b.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "test/aspect/alias/a.h"
#include "test/aspect/alias/b.h"
#include "alias/a.h"
#include "alias/b.h"

int main()
{
Expand Down
2 changes: 1 addition & 1 deletion test/aspect/aspect.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//:defs.bzl", "dwyu_aspect_factory")
load("@depend_on_what_you_use//:defs.bzl", "dwyu_aspect_factory")

dwyu = dwyu_aspect_factory()
dwyu_impl_deps = dwyu_aspect_factory(use_implementation_deps = True)
2 changes: 1 addition & 1 deletion test/aspect/complex_includes/ext_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
def load_complex_includes_repo():
native.local_repository(
name = "complex_includes_test_repo",
path = "test/aspect/complex_includes/ext_repo",
path = "complex_includes/ext_repo",
)
2 changes: 1 addition & 1 deletion test/aspect/complex_includes/test_complex_includes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def execute_test_logic(self) -> Result:
"""
expected = ExpectedResult(success=True)
actual = self._run_dwyu(
target=["//test/aspect/complex_includes:all", "@complex_includes_test_repo//..."],
target=["//complex_includes:all", "@complex_includes_test_repo//..."],
aspect=self.default_aspect,
)

Expand Down
22 changes: 11 additions & 11 deletions test/aspect/defines/BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cc_library(
name = "in_file_defines",
hdrs = ["in_file_defines.h"],
deps = ["//test/aspect/defines/support:lib_a"],
deps = ["//defines/support:lib_a"],
)

cc_library(
Expand All @@ -10,35 +10,35 @@ cc_library(
copts = ["-DSOME_COPT 42"],
defines = ["SOME_DEFINE"],
local_defines = ["LOCAL_DEFINE"],
deps = ["//test/aspect/defines/support:lib_a"],
deps = ["//defines/support:lib_a"],
)

cc_library(
name = "transitive_defines_from_bazel_target",
hdrs = ["transitive_defines_from_bazel_target.h"],
deps = [
"//test/aspect/defines/support:lib_a",
"//test/aspect/defines/support:transitive_define",
"//defines/support:lib_a",
"//defines/support:transitive_define",
],
)

cc_library(
name = "use_defines_from_dependency_header",
hdrs = ["use_defines_from_dependency_header.h"],
deps = [
"//test/aspect/defines/support:conditional_defines",
"//test/aspect/defines/support:lib_b",
"//defines/support:conditional_defines",
"//defines/support:lib_b",
],
)

cc_library(
name = "include_using_pre_processor_token",
hdrs = ["include_using_pre_processor_token.h"],
copts = ['-DCONDITIONAL_DEFINES_HEADER=\"test/aspect/defines/support/conditional_defines.h\"'],
copts = ['-DCONDITIONAL_DEFINES_HEADER=\"defines/support/conditional_defines.h\"'],
deps = [
"//test/aspect/defines/support:conditional_defines",
"//test/aspect/defines/support:lib_a",
"//test/aspect/defines/support:lib_b",
"//test/aspect/defines/support:some_defines",
"//defines/support:conditional_defines",
"//defines/support:lib_a",
"//defines/support:lib_b",
"//defines/support:some_defines",
],
)
12 changes: 6 additions & 6 deletions test/aspect/defines/defines_from_bazel_target.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#ifdef SOME_DEFINE
#include "test/aspect/defines/support/a.h"
#include "defines/support/a.h"
#else
#include "test/aspect/defines/support/b.h"
#include "defines/support/b.h"
#endif

#ifdef LOCAL_DEFINE
#include "test/aspect/defines/support/a.h"
#include "defines/support/a.h"
#else
#include "test/aspect/defines/support/b.h"
#include "defines/support/b.h"
#endif

#if SOME_COPT > 40
#include "test/aspect/defines/support/a.h"
#include "defines/support/a.h"
#else
#include "test/aspect/defines/support/b.h"
#include "defines/support/b.h"
#endif
10 changes: 5 additions & 5 deletions test/aspect/defines/in_file_defines.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#define USE_A

#ifdef USE_A
#include "test/aspect/defines/support/a.h"
#include "defines/support/a.h"
#else
#include "test/aspect/defines/support/b.h"
#include "defines/support/b.h"
#endif

#ifdef NON_EXISTING_DEFINE
#include "test/aspect/defines/support/b.h"
#include "defines/support/b.h"
#endif

#define SOME_VALUE 42

#if SOME_VALUE > 40
#include "test/aspect/defines/support/a.h"
#include "defines/support/a.h"
#else
#include "test/aspect/defines/support/b.h"
#include "defines/support/b.h"
#endif
Loading

0 comments on commit f0012be

Please sign in to comment.