11"""Tests for the java_binary rule"""
22
33load ("@rules_testing//lib:analysis_test.bzl" , "analysis_test" , "test_suite" )
4+ load ("@rules_testing//lib:truth.bzl" , "matching" )
45load ("@rules_testing//lib:util.bzl" , "util" )
56load ("//java:java_binary.bzl" , "java_binary" )
67load ("//java/test/testutil:java_info_subject.bzl" , "java_info_subject" )
@@ -21,10 +22,42 @@ def _test_java_binary_provides_binary_java_info_impl(env, target):
2122 assert_java_info .compilation_args ().equals (None )
2223 assert_java_info .is_binary ().equals (True )
2324
25+ def _test_stamp_conversion_does_not_override_int (name ):
26+ util .helper_target (
27+ java_binary ,
28+ name = name + "/bin" ,
29+ srcs = ["Main.java" ],
30+ stamp = - 1 ,
31+ )
32+
33+ analysis_test (
34+ name = name ,
35+ impl = _test_stamp_conversion_does_not_override_int_impl ,
36+ target = name + "/bin" ,
37+ config_settings = {
38+ "//command_line_option:stamp" : False ,
39+ },
40+ # deploy jars are in a separate rule in Bazel 7, Bazel 6 generated build-info differently
41+ attr_values = {"tags" : ["min_bazel_8" ]},
42+ )
43+
44+ def _test_stamp_conversion_does_not_override_int_impl (env , target ):
45+ assert_deploy_jar_action = env .expect .that_target (target ).action_generating (
46+ "{package}/{name}_deploy.jar" ,
47+ )
48+
49+ assert_deploy_jar_action .inputs ().not_contains_predicate (
50+ matching .file_basename_equals ("non_volatile_file.properties" ),
51+ )
52+ assert_deploy_jar_action .inputs ().contains_predicate (
53+ matching .file_basename_equals ("redacted_file.properties" ),
54+ )
55+
2456def java_binary_tests (name ):
2557 test_suite (
2658 name = name ,
2759 tests = [
2860 _test_java_binary_provides_binary_java_info ,
61+ _test_stamp_conversion_does_not_override_int ,
2962 ],
3063 )
0 commit comments