Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
415d31e
test: initial build statement testing
Mar 19, 2026
b071dad
test: move to export_e2e build rule
Mar 19, 2026
451ecdf
test: add test for custom build def and rework build stmt checked
Mar 20, 2026
6066dce
test: targets with deps, multiple targets, export outputs and notrim
Mar 23, 2026
db74e8a
test: export go binary including rework of build_def for multiple plz…
Mar 24, 2026
55756b9
test: genrule with go subrepo and go binary with go dependency
Mar 24, 2026
10aa8f3
test: build def with children targets
Mar 24, 2026
b561575
test: preload build def
Mar 24, 2026
7bf2255
lint: run plz format
Mar 24, 2026
58bf895
fix: plz command replacement for tests cmd
Mar 24, 2026
9b19c4a
nit comments
Mar 25, 2026
de23d20
test export build def
Mar 25, 2026
451f4eb
first golden-master test and moved export_e2e to generic test
Mar 25, 2026
51a1c24
update test simple custom build def to use repo diff
Mar 25, 2026
9544043
update test build defs for in file and extra child
Mar 25, 2026
c1e5e51
update deps test
Mar 25, 2026
6e3c11b
update multiple targets and preload tests
Mar 25, 2026
0a24446
update go tests
Mar 25, 2026
622797d
update generic tests
Mar 25, 2026
0c0c68a
remove old repos
Mar 25, 2026
468f5cd
doc string
Mar 26, 2026
14c93bc
linter
Mar 26, 2026
501a82f
rename test_repo to source_repo
Apr 7, 2026
6b6b182
enforce differences between source and expected repo
Apr 7, 2026
60b1fa4
include trimable target for all tests
Apr 7, 2026
2560764
build all targets in the exported repo
Apr 7, 2026
621ec1a
move tests into each test dir
Apr 7, 2026
3d18551
rename child to adjacent
Apr 7, 2026
54adcb1
reduce go_binary test
Apr 16, 2026
a14d7f9
output test as golden-master
Apr 17, 2026
9d703d7
move go config and binary to source_repo
Apr 17, 2026
c09f60a
notrim test as golden-master
Apr 17, 2026
4f142bc
format
Apr 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion test/build_defs/test.build_defs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ def please_repo_e2e_test(
name: str,
plz_command: str,
repo: str,
defer_cmd: list = [],
data: dict={},
deps: list=[],
tools: dict={},
Expand All @@ -12,7 +13,6 @@ def please_repo_e2e_test(
expect_output_doesnt_contain: dict = {},
labels: list = [],
):
plz_command = plz_command.replace("plz ", "$TOOLS_PLEASE ")
if expected_failure:
plz_command += "; [ ! $? -eq 0 ]"

Expand All @@ -31,7 +31,11 @@ def please_repo_e2e_test(
if expect_output_doesnt_contain:
test_cmd += [f'_STR="$(cat {o})" _SUBSTR="{c}" && if [ -z "${_STR##*$_SUBSTR*}" ]; then echo "$_STR"; exit 1; fi' for o, c in expect_output_doesnt_contain.items()]

# defer commands should be added last
test_cmd += defer_cmd

test_cmd = ' && '.join(test_cmd)
test_cmd = test_cmd.replace("plz ", "$TOOLS_PLEASE ")

data["REPO"] = [repo]
data["BASE_CONFIG"] = ["//test/build_defs:base_config"]
Expand Down
9 changes: 8 additions & 1 deletion test/export/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
subinclude("//test/build_defs")
subinclude("//test/build_defs:build_defs")

filegroup(
name = "export_e2e_test_build_def",
srcs = ["please_export_e2e_test.build_defs"],
visibility = ["//test/export/..."],
)

# Generic catch-all test on internal repo.
plz_e2e_test(
name = "export_src_please_test",
cmd = "plz export --output plz-out/plzexport //src/core && plz --repo_root=$(plz query reporoot)/plz-out/plzexport build //src/core",
Expand Down
72 changes: 72 additions & 0 deletions test/export/please_export_e2e_test.build_defs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
subinclude("//test/build_defs:build_defs")

def please_export_e2e_test(
name:str,
export_targets:list,
cmd_on_export:list=[],
source_repo:str="source_repo",
expected_repo:str="expected_repo",
flags:str="",
enforce_different_repos:bool=True):
"""
Runs an export e2e test. To use it, create a directory with both a `source_repo` with the targets
to be exported and an `expected_repo` with the expected resulting files.
The validation steps for the e2e test are:
* It performs a repo-wide diff between the exported files and the `expected_repo`
* Builds the exported target to ensure the exported repo, and consequently the
`expected_repo`, include valid sources and dependencies to build the target.
* Optionally you can specify additional commands to run on the exported directory by
passing them to `cmd_on_export`.

Args:
name (str): Name of the test.
export_targets (list): Targets to export as part of the test.
cmd_on_export (list): Optional. Additional commands to run on the exported directory.
source_repo (str): Optional. Repository to export targets from. Defaults to "source_repo".
expected_repo (str): Optional. Repository containing the expected results for golden-master
validation. Defaults to "expected_repo".
flags (str): Optional. Additional flags for the export command.
enforce_different_repos (bool): Optional. Ensures we test the trimming capabilities of the
export by enforcing that the source and expected repos differ in content. Default to True.
"""
EXPORT_DIR = "plz-out/plzexport"
exported_repo = f"$DATA_SOURCE_REPO/{EXPORT_DIR}"
data = {}
tools = {}

targets = " ".join(export_targets)

test_cmd = []
if enforce_different_repos:
test_cmd += [
# Enforce source_repo and expected_repo differences
f'(diff -rq "$DATA_SOURCE_REPO" "$DATA_EXPECTED_REPO" && \
echo "Source and Expected repos must differ" && exit 1 || true)',
]

test_cmd += [
# Export
f'plz --repo_root="$DATA_SOURCE_REPO" export --output "{EXPORT_DIR}" {flags} {targets}',
# Golden-Master validation with expected repo. Done before any building to avoid plz-out
f'diff -ru "{exported_repo}" "$DATA_EXPECTED_REPO"',
# Tests building the exported repo which in turn ensures the sources are included
f'plz --repo_root="{exported_repo}" build //...',
] + [f'plz --repo_root="{exported_repo}" {cmd}' for cmd in cmd_on_export]

test_cmd = [cmd.replace("plz ", "$TOOLS_PLEASE ") for cmd in test_cmd]
test_cmd = " && ".join(test_cmd)

data["SOURCE_REPO"] = [source_repo]
data["EXPECTED_REPO"] = [expected_repo]

tools["PLEASE"] = ["//package:installed_files|please"]

return gentest(
name = name,
data = data,
labels = ["plz_e2e_test", "e2e"],
no_test_output = True,
sandbox = False,
test_cmd = test_cmd,
test_tools = tools,
)
8 changes: 8 additions & 0 deletions test/export/test_builtins/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
subinclude("//test/export:export_e2e_test_build_def")

# Export a target generated by a native genrule target and trim unused
# build statements.
please_export_e2e_test(
name = "export_native_genrule",
export_targets = ["//:native_genrule"],
)
3 changes: 3 additions & 0 deletions test/export/test_builtins/expected_repo/.plzconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Parse]

BuildFileName = BUILD_FILE
6 changes: 6 additions & 0 deletions test/export/test_builtins/expected_repo/BUILD_FILE
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
genrule(
name = "native_genrule",
srcs = ["file.txt"],
outs = ["file.wordcount"],
cmd = "wc $SRCS > $OUT",
)
1 change: 1 addition & 0 deletions test/export/test_builtins/expected_repo/file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test source file
3 changes: 3 additions & 0 deletions test/export/test_builtins/source_repo/.plzconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Parse]

BuildFileName = BUILD_FILE
13 changes: 13 additions & 0 deletions test/export/test_builtins/source_repo/BUILD_FILE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
genrule(
name = "native_genrule",
srcs = ["file.txt"],
outs = ["file.wordcount"],
cmd = "wc $SRCS > $OUT",
)

genrule(
name = "dummy_target_to_be_trimmed",
srcs = ["dummy.txt"],
outs = ["dummy"],
cmd = "cat $SRCS > $OUT",
)
Empty file.
1 change: 1 addition & 0 deletions test/export/test_builtins/source_repo/file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test source file
7 changes: 7 additions & 0 deletions test/export/test_custom_def/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
subinclude("//test/export:export_e2e_test_build_def")

# Export a target generated by a custom build def.
please_export_e2e_test(
name = "export_simple_custom_target",
export_targets = ["//:simple_custom_target"],
)
3 changes: 3 additions & 0 deletions test/export/test_custom_def/expected_repo/.plzconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Parse]

BuildFileName = BUILD_FILE
7 changes: 7 additions & 0 deletions test/export/test_custom_def/expected_repo/BUILD_FILE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
subinclude("//build_defs:simple_build_def")

simple_custom_target(
name = "simple_custom_target",
srcs = ["file.txt"],
outs = ["file_simple.out"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
filegroup(
Comment thread
DuBento marked this conversation as resolved.
name = "simple_build_def",
srcs = ["simple.build_defs"],
visibility = ["PUBLIC"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def simple_custom_target(
name:str,
srcs:list=[],
outs:list=[]):
return genrule(
name = name,
srcs = srcs,
outs = outs,
cmd = "cat $SRCS > $OUT",
)
1 change: 1 addition & 0 deletions test/export/test_custom_def/expected_repo/file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test source file
3 changes: 3 additions & 0 deletions test/export/test_custom_def/source_repo/.plzconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Parse]

BuildFileName = BUILD_FILE
13 changes: 13 additions & 0 deletions test/export/test_custom_def/source_repo/BUILD_FILE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
subinclude("//build_defs:simple_build_def")

simple_custom_target(
name = "simple_custom_target",
srcs = ["file.txt"],
outs = ["file_simple.out"],
)

simple_custom_target(
name = "dummy",
srcs = ["file.txt"],
outs = ["dummy.out"],
)
11 changes: 11 additions & 0 deletions test/export/test_custom_def/source_repo/build_defs/BUILD_FILE
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
filegroup(
name = "simple_build_def",
srcs = ["simple.build_defs"],
visibility = ["PUBLIC"],
)

filegroup(
name = "dummy_build_def",
srcs = ["dummy.build_defs"],
visibility = ["PUBLIC"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def dummy_target(
name:str,
outs:list=[]):
return genrule(
name = name,
outs = outs,
cmd = "echo dummy > $OUT",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def simple_custom_target(
name:str,
srcs:list=[],
outs:list=[]):
return genrule(
name = name,
srcs = srcs,
outs = outs,
cmd = "cat $SRCS > $OUT",
)
1 change: 1 addition & 0 deletions test/export/test_custom_def/source_repo/file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test source file
11 changes: 11 additions & 0 deletions test/export/test_custom_def_children/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
subinclude("//test/export:export_e2e_test_build_def")

# Export a target generated by a custom build def.
please_export_e2e_test(
name = "export_custom_with_adjacent_target",
cmd_on_export = [
# Adjacent target of build def
"build //:custom_target#adjacent",
],
export_targets = ["//:custom_target"],
)
3 changes: 3 additions & 0 deletions test/export/test_custom_def_children/expected_repo/.plzconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Parse]

BuildFileName = BUILD_FILE
8 changes: 8 additions & 0 deletions test/export/test_custom_def_children/expected_repo/BUILD_FILE
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
subinclude("//build_defs:custom_build_def")

custom_target(
name = "custom_target",
srcs = ["file.txt"],
outs = ["file.out"],
outs_adjacent = ["file_adjacent.out"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
filegroup(
name = "custom_build_def",
srcs = ["custom.build_defs"],
visibility = ["PUBLIC"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def custom_target(
name:str,
srcs:list=[],
outs:list=[],
outs_adjacent:list=[]):
genrule(
name = f"{name}#adjacent",
srcs = srcs,
outs = outs_adjacent,
cmd = "echo 'adjacent' > $OUT && cat $SRCS >> $OUT ",
)
return genrule(
name = name,
srcs = srcs,
outs = outs,
cmd = "echo 'main' > $OUT && cat $SRCS >> $OUT ",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test source file
3 changes: 3 additions & 0 deletions test/export/test_custom_def_children/source_repo/.plzconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Parse]

BuildFileName = BUILD_FILE
15 changes: 15 additions & 0 deletions test/export/test_custom_def_children/source_repo/BUILD_FILE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
subinclude("//build_defs:custom_build_def")

custom_target(
name = "custom_target",
srcs = ["file.txt"],
outs = ["file.out"],
outs_adjacent = ["file_adjacent.out"],
)

custom_target(
name = "dummy",
srcs = ["file.txt"],
outs = ["dummy.out"],
outs_adjacent = ["dummy_adjacent.out"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
filegroup(
name = "custom_build_def",
srcs = ["custom.build_defs"],
visibility = ["PUBLIC"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def custom_target(
name:str,
srcs:list=[],
outs:list=[],
outs_adjacent:list=[]):
genrule(
name = f"{name}#adjacent",
srcs = srcs,
outs = outs_adjacent,
cmd = "echo 'adjacent' > $OUT && cat $SRCS >> $OUT ",
)
return genrule(
name = name,
srcs = srcs,
outs = outs,
cmd = "echo 'main' > $OUT && cat $SRCS >> $OUT ",
)
1 change: 1 addition & 0 deletions test/export/test_custom_def_children/source_repo/file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test source file
8 changes: 8 additions & 0 deletions test/export/test_custom_in_file_def/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
subinclude("//test/export:export_e2e_test_build_def")

# Export a target generated by a custom build def defined in the same
# BUILD file.
please_export_e2e_test(
name = "export_custom_target_in_file",
export_targets = ["//:simple_custom_target"],
)
3 changes: 3 additions & 0 deletions test/export/test_custom_in_file_def/expected_repo/.plzconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Parse]

BuildFileName = BUILD_FILE
13 changes: 13 additions & 0 deletions test/export/test_custom_in_file_def/expected_repo/BUILD_FILE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
filegroup(
name = "simple_build_def",
srcs = ["simple.build_defs"],
visibility = ["//test_custom_defs/..."],
)

subinclude(":simple_build_def")

simple_custom_target(
name = "simple_custom_target",
srcs = ["file.txt"],
outs = ["file_simple.out"],
)
1 change: 1 addition & 0 deletions test/export/test_custom_in_file_def/expected_repo/file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test source file
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def simple_custom_target(
name:str,
srcs:list=[],
outs:list=[]):
return genrule(
name = name,
srcs = srcs,
outs = outs,
cmd = "cat $SRCS > $OUT",
)
3 changes: 3 additions & 0 deletions test/export/test_custom_in_file_def/source_repo/.plzconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Parse]

BuildFileName = BUILD_FILE
Loading