Skip to content

Commit 07a1ffc

Browse files
committed
Add integration test
1 parent 80257a7 commit 07a1ffc

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

src/test/py/bazel/bzlmod/bazel_module_test.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,5 +695,68 @@ def testRunfilesRepoMappingManifest(self):
695695
self.Path('bazel-bin/external/bar~2.0/bar.runfiles_manifest')) as f:
696696
self.assertIn("_repo_mapping ", f.read())
697697

698+
def testJavaRunfilesLibraryRepoMapping(self):
699+
self.main_registry.setModuleBasePath('projects')
700+
projects_dir = self.main_registry.projects
701+
702+
self.main_registry.createLocalPathModule('data', '1.0', 'data')
703+
projects_dir.joinpath('data').mkdir(exist_ok=True)
704+
scratchFile(projects_dir.joinpath('data', 'WORKSPACE'))
705+
scratchFile(projects_dir.joinpath('data', 'foo.txt'), ['hello'])
706+
scratchFile(projects_dir.joinpath('data', 'BUILD'),
707+
['exports_files(["foo.txt"])'])
708+
709+
self.main_registry.createLocalPathModule('test', '1.0', 'test',
710+
{'data': '1.0'})
711+
projects_dir.joinpath('test').mkdir(exist_ok=True)
712+
scratchFile(projects_dir.joinpath('test', 'WORKSPACE'))
713+
scratchFile(projects_dir.joinpath('test', 'BUILD'), [
714+
'java_test(',
715+
' name = "test",'
716+
' srcs = ["Test.java"],',
717+
' main_class = "com.example.Test",',
718+
' use_testrunner = False,',
719+
' data = ["@data//:foo.txt"],',
720+
' args = ["$(rlocationpath @data//:foo.txt)"],',
721+
' deps = ["@bazel_tools//tools/java/runfiles"],',
722+
')'
723+
])
724+
scratchFile(projects_dir.joinpath('test', 'Test.java'), [
725+
'package com.example;',
726+
'',
727+
'import com.google.devtools.build.runfiles.AutoBazelRepository;',
728+
'import com.google.devtools.build.runfiles.Runfiles;',
729+
'',
730+
'import java.io.File;',
731+
'import java.io.IOException;',
732+
'',
733+
'@AutoBazelRepository',
734+
'public class Test {',
735+
' public static void main(String[] args) throws IOException {',
736+
' Runfiles.Preloaded rp = Runfiles.preload();',
737+
' if (!new File(rp.unmapped().rlocation(args[0])).exists()) {',
738+
' System.exit(1);',
739+
' }',
740+
' if (!new File(rp.withSourceRepository(AutoBazelRepository_Test.NAME).rlocation("data/foo.txt")).exists()) {',
741+
' System.exit(1);',
742+
' }',
743+
' }',
744+
'}',
745+
])
746+
747+
self.ScratchFile('MODULE.bazel', ['bazel_dep(name="test",version="1.0")'])
748+
self.ScratchFile('WORKSPACE')
749+
750+
# Run sandboxed on Linux and macOS.
751+
exit_code, stderr, stdout = self.RunBazel(
752+
['test', '@test//:test', '--test_output=errors',
753+
'--test_env=RUNFILES_LIB_DEBUG=1'], allow_failure=True)
754+
self.AssertExitCode(exit_code, 0, stderr, stdout)
755+
# Run unsandboxed on all platforms.
756+
exit_code, stderr, stdout = self.RunBazel(
757+
['run', '@test//:test'], allow_failure=True,
758+
env_add={"RUNFILES_LIB_DEBUG": "1"})
759+
self.AssertExitCode(exit_code, 0, stderr, stdout)
760+
698761
if __name__ == '__main__':
699762
unittest.main()

0 commit comments

Comments
 (0)