Skip to content

Commit 8f4b5f2

Browse files
tests for artifact with plus (#1053)
Related to #962, reproducing base case that works. Added maven_install stanzas for an artifact that contains plus in its version. Also fixed some test issues related to deleting generated files. File names changed after switching to bzlmod. Added a sanity check in expect_not_in_file() to ensure it's being called for a good file (and not reporting missing string due to missing file). Moved around one test for proper grouping.
1 parent 99795b4 commit 8f4b5f2

File tree

5 files changed

+153
-14
lines changed

5 files changed

+153
-14
lines changed

MODULE.bazel

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module(
22
name = "rules_jvm_external",
3-
version = "6.0",
43
compatibility_level = 2,
4+
version = "6.0",
55
)
66

77
bazel_dep(
@@ -349,6 +349,27 @@ dev_maven.install(
349349
],
350350
)
351351

352+
dev_maven.install(
353+
name = "artifact_with_plus",
354+
artifacts = [
355+
"ch.epfl.scala:compiler-interface:1.3.0-M4+47-d881fa2f",
356+
],
357+
repositories = [
358+
"https://repo1.maven.org/maven2",
359+
],
360+
)
361+
362+
dev_maven.install(
363+
name = "artifact_with_plus_repin",
364+
artifacts = [
365+
"ch.epfl.scala:compiler-interface:1.3.0-M4+47-d881fa2f",
366+
],
367+
lock_file = "//tests/custom_maven_install:artifact_with_plus_repin_install.json",
368+
repositories = [
369+
"https://repo1.maven.org/maven2",
370+
],
371+
)
372+
352373
dev_maven.install(
353374
name = "manifest_stamp_testing",
354375
artifacts = [
@@ -635,6 +656,9 @@ use_repo(
635656
"m2local_testing_repin",
636657
"m2local_testing_without_checksum",
637658
"unpinned_m2local_testing_repin",
659+
"artifact_with_plus",
660+
"artifact_with_plus_repin",
661+
"unpinned_artifact_with_plus_repin",
638662

639663
# Pinned repo
640664
"maven",

WORKSPACE

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,9 @@ maven_install(
538538
],
539539
)
540540

541-
load("@m2local_testing_repin//:defs.bzl", "pinned_maven_install")
541+
load("@m2local_testing_repin//:defs.bzl", m2local_testing_repin_maven_install = "pinned_maven_install")
542542

543-
pinned_maven_install()
543+
m2local_testing_repin_maven_install()
544544

545545
maven_install(
546546
name = "m2local_testing_without_checksum",
@@ -588,6 +588,35 @@ maven_install(
588588
],
589589
)
590590

591+
load("@m2local_testing_ignore_empty_files_repin//:defs.bzl", m2local_testing_ignore_empty_files_repin_maven_install = "pinned_maven_install")
592+
593+
m2local_testing_ignore_empty_files_repin_maven_install()
594+
595+
maven_install(
596+
name = "artifact_with_plus",
597+
artifacts = [
598+
"ch.epfl.scala:compiler-interface:1.3.0-M4+47-d881fa2f",
599+
],
600+
repositories = [
601+
"https://repo1.maven.org/maven2",
602+
],
603+
)
604+
605+
maven_install(
606+
name = "artifact_with_plus_repin",
607+
artifacts = [
608+
"ch.epfl.scala:compiler-interface:1.3.0-M4+47-d881fa2f",
609+
],
610+
maven_install_json = "//tests/custom_maven_install:artifact_with_plus_repin_install.json",
611+
repositories = [
612+
"https://repo1.maven.org/maven2",
613+
],
614+
)
615+
616+
load("@artifact_with_plus_repin//:defs.bzl", artifact_with_plus_maven_install = "pinned_maven_install")
617+
618+
artifact_with_plus_maven_install()
619+
591620
maven_install(
592621
name = "v1_lock_file_format",
593622
artifacts = [

tests/bazel_run_tests.sh

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,24 @@ function test_dependency_aggregation() {
2121

2222
function test_duplicate_version_warning() {
2323
bazel run @duplicate_version_warning//:pin >> "$TEST_LOG" 2>&1
24-
rm -f duplicate_version_warning_install.json
24+
rm -f *duplicate_version_warning_install.json
2525

2626
expect_log "Found duplicate artifact versions"
2727
expect_log "com.fasterxml.jackson.core:jackson-annotations has multiple versions"
2828
expect_log "com.github.jnr:jffi:native has multiple versions"
2929
expect_log "Successfully pinned resolved artifacts"
3030
}
3131

32+
function test_duplicate_version_warning_same_version() {
33+
bazel run @duplicate_version_warning_same_version//:pin >> "$TEST_LOG" 2>&1
34+
rm -f *duplicate_version_warning_same_version_install.json
35+
36+
expect_not_log "Found duplicate artifact versions"
37+
expect_not_log "com.fasterxml.jackson.core:jackson-annotations has multiple versions"
38+
expect_not_log "com.github.jnr:jffi:native has multiple versions"
39+
expect_log "Successfully pinned resolved artifacts"
40+
}
41+
3242
function test_m2local_testing_ignore_empty_files() {
3343
# Testing ignore_empty_files with m2local, as it's the easiest way to imitate an empty jar file.
3444
m2local_dir="${HOME}/.m2/repository"
@@ -47,9 +57,9 @@ function test_m2local_testing_ignore_empty_files() {
4757
force_bzlmod_lock_file_to_be_regenerated
4858

4959
bazel run @m2local_testing_ignore_empty_files//:pin >> "$TEST_LOG" 2>&1
50-
expect_not_in_file '"sources": "' m2local_testing_ignore_empty_files_install.json
60+
expect_not_in_file '"sources": "' *m2local_testing_ignore_empty_files_install.json
5161

52-
rm -f m2local_testing_ignore_empty_files_install.json
62+
rm -f *m2local_testing_ignore_empty_files_install.json
5363
rm -rf ${jar_dir}
5464

5565
expect_log "Assuming maven local for artifact: com.example:kt:1.0.0"
@@ -95,7 +105,7 @@ function test_m2local_testing_found_local_artifact_through_pin_and_build() {
95105
force_bzlmod_lock_file_to_be_regenerated
96106

97107
bazel build @m2local_testing//:com_example_kt >> "$TEST_LOG" 2>&1
98-
rm -f m2local_testing_install.json
108+
rm -f *m2local_testing_install.json
99109
rm -rf ${jar_dir}
100110

101111
expect_log "Assuming maven local for artifact: com.example:kt:1.0.0"
@@ -118,7 +128,6 @@ function test_unpinned_m2local_testing_found_local_artifact_through_pin_and_buil
118128
force_bzlmod_lock_file_to_be_regenerated
119129

120130
bazel build @m2local_testing_repin//:com_example_kt >> "$TEST_LOG" 2>&1
121-
rm -f m2local_testing_install.json
122131
rm -rf ${jar_dir}
123132

124133
expect_log "Assuming maven local for artifact: com.example:kt:1.0.0"
@@ -174,13 +183,28 @@ function test_m2local_testing_found_local_artifact_after_build_copy() {
174183
expect_log "Assuming maven local for artifact: com.example:kt:1.0.0"
175184
}
176185

177-
function test_duplicate_version_warning_same_version() {
178-
bazel run @duplicate_version_warning_same_version//:pin >> "$TEST_LOG" 2>&1
179-
rm -f duplicate_version_warning_same_version_install.json
186+
function test_found_artifact_with_plus_through_pin_and_build() {
187+
bazel clean --expunge >> "$TEST_LOG" 2>&1 # for https://github.com/bazelbuild/rules_jvm_external/issues/800
188+
bazel run @artifact_with_plus//:pin >> "$TEST_LOG" 2>&1
189+
190+
force_bzlmod_lock_file_to_be_regenerated
191+
192+
bazel build @artifact_with_plus//:ch_epfl_scala_compiler_interface >> "$TEST_LOG" 2>&1
193+
rm -f *artifact_with_plus_install.json
194+
195+
expect_log "Successfully pinned resolved artifacts"
196+
}
197+
198+
function test_unpinned_found_artifact_with_plus_through_pin_and_build() {
199+
# Force the repo rule to be evaluated again. Without this, the "assuming maven local..." message will not be printed
200+
bazel clean --expunge >/dev/null 2>&1
201+
202+
bazel run @unpinned_artifact_with_plus_repin//:pin >> "$TEST_LOG" 2>&1
203+
204+
force_bzlmod_lock_file_to_be_regenerated
205+
206+
bazel build @artifact_with_plus_repin//:ch_epfl_scala_compiler_interface >> "$TEST_LOG" 2>&1
180207

181-
expect_not_log "Found duplicate artifact versions"
182-
expect_not_log "com.fasterxml.jackson.core:jackson-annotations has multiple versions"
183-
expect_not_log "com.github.jnr:jffi:native has multiple versions"
184208
expect_log "Successfully pinned resolved artifacts"
185209
}
186210

@@ -223,6 +247,8 @@ TESTS=(
223247
"test_m2local_testing_found_local_artifact_after_build_copy"
224248
"test_m2local_testing_ignore_empty_files"
225249
"test_unpinned_m2local_testing_ignore_empty_files"
250+
"test_found_artifact_with_plus_through_pin_and_build"
251+
"test_unpinned_found_artifact_with_plus_through_pin_and_build"
226252
"test_v1_lock_file_format"
227253
"test_dependency_pom_exclusion"
228254
)
@@ -243,6 +269,11 @@ function run_tests() {
243269
function expect_not_in_file() {
244270
local pattern=$1
245271
local file=$2
272+
if [ ! -f $file ]; then
273+
printf "NOT FOUND: $file (most probably wrong test configuration)\n"
274+
return 1
275+
fi
276+
246277
local message=${3:-Expected not to find regexp \""$pattern"\", but it was found}
247278
grep -sq -- "$pattern" $file || return 0
248279

tests/custom_maven_install/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ exports_files([
44
"policy_pinned_testing_install.json",
55
"regression_testing_install.json",
66
"m2local_testing_with_pinned_file_install.json",
7+
"artifact_with_plus_repin_install.json",
78
])
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL",
3+
"__INPUT_ARTIFACTS_HASH": -1776930339,
4+
"__RESOLVED_ARTIFACTS_HASH": 1980085895,
5+
"artifacts": {
6+
"ch.epfl.scala:compiler-interface": {
7+
"shasums": {
8+
"jar": "d27afc405d935ba055d10f2c8aa2b884e5a090961bc9d1b0af596b3b547238e5"
9+
},
10+
"version": "1.3.0-M4+47-d881fa2f"
11+
},
12+
"com.google.protobuf:protobuf-java": {
13+
"shasums": {
14+
"jar": "dc7f93e3a3dc2c11be5ba9672af3e26410f0a3289312dbf2260d4d8a0c711a51"
15+
},
16+
"version": "3.7.0"
17+
},
18+
"org.scala-sbt:util-interface": {
19+
"shasums": {
20+
"jar": "adb18e5f79a028f2b33506ccc6a4b24500dd985628b05308a7af5acbd1ee2cd7"
21+
},
22+
"version": "1.2.2"
23+
}
24+
},
25+
"dependencies": {
26+
"ch.epfl.scala:compiler-interface": [
27+
"com.google.protobuf:protobuf-java",
28+
"org.scala-sbt:util-interface"
29+
]
30+
},
31+
"packages": {
32+
"ch.epfl.scala:compiler-interface": [
33+
"xsbti",
34+
"xsbti.api",
35+
"xsbti.compile",
36+
"xsbti.compile.analysis"
37+
],
38+
"com.google.protobuf:protobuf-java": [
39+
"com.google.protobuf",
40+
"com.google.protobuf.compiler"
41+
],
42+
"org.scala-sbt:util-interface": [
43+
"xsbti"
44+
]
45+
},
46+
"repositories": {
47+
"https://repo1.maven.org/maven2/": [
48+
"ch.epfl.scala:compiler-interface",
49+
"com.google.protobuf:protobuf-java",
50+
"org.scala-sbt:util-interface"
51+
]
52+
},
53+
"version": "2"
54+
}

0 commit comments

Comments
 (0)