mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 12:09:14 +00:00
Add tests for automatic module names
This commit is contained in:
parent
057daed8cd
commit
9ca4567d27
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -23,12 +23,8 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8345431
|
||||
* @bug 8345431 8375433
|
||||
* @summary test validator to report malformed jar file
|
||||
* @library /test/lib
|
||||
* @modules jdk.jartool
|
||||
* @build jdk.test.lib.Platform
|
||||
* jdk.test.lib.util.FileUtils
|
||||
* @run junit/othervm ValidatorTest
|
||||
*/
|
||||
|
||||
@ -59,13 +55,15 @@ import java.util.stream.Stream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import jdk.test.lib.util.FileUtils;
|
||||
|
||||
class ValidatorTest {
|
||||
private static final ToolProvider JAR_TOOL = ToolProvider.findFirst("jar")
|
||||
.orElseThrow(() ->
|
||||
new RuntimeException("jar tool not found")
|
||||
);
|
||||
private static final ToolProvider JAVAC_TOOL = ToolProvider.findFirst("javac")
|
||||
.orElseThrow(() ->
|
||||
new RuntimeException("javac tool not found")
|
||||
);
|
||||
|
||||
private final String nl = System.lineSeparator();
|
||||
private final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
@ -310,6 +308,52 @@ class ValidatorTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidAutomaticModuleName() throws Exception {
|
||||
System.out.printf("%n%n*****Creating Jar with invalid Automatic-Module-Name in Manifest*****%n%n");
|
||||
var file = Path.of("InvalidAutomaticModuleName.jar");
|
||||
var manifest = Path.of("MANIFEST.MF");
|
||||
Files.writeString(manifest,
|
||||
"""
|
||||
Automatic-Module-Name: default
|
||||
""");
|
||||
jar("--create --file " + file + " --manifest " + manifest);
|
||||
try {
|
||||
jar("--validate --file " + file.toString());
|
||||
fail("Expecting non-zero exit code");
|
||||
} catch (IOException e) {
|
||||
var err = e.getMessage();
|
||||
System.out.println(err);
|
||||
assertTrue(err.contains("invalid module name of Automatic-Module-Name entry in manifest: default"), "missing warning for: default");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongAutomaticModuleName() throws Exception {
|
||||
System.out.printf("%n%n*****Creating Jar with wrong Automatic-Module-Name in Manifest*****%n%n");
|
||||
var file = Path.of("WrongAutomaticModuleName.jar");
|
||||
var foo = Path.of("module-info.java");
|
||||
Files.writeString(foo,
|
||||
"""
|
||||
module foo {}
|
||||
""");
|
||||
var manifest = Path.of("MANIFEST.MF");
|
||||
Files.writeString(manifest,
|
||||
"""
|
||||
Automatic-Module-Name: bar
|
||||
""");
|
||||
JAVAC_TOOL.run(System.out, System.err, foo.toString());
|
||||
jar("--create --file " + file + " --manifest " + manifest + " module-info.class");
|
||||
try {
|
||||
jar("--validate --file " + file.toString());
|
||||
fail("Expecting non-zero exit code");
|
||||
} catch (IOException e) {
|
||||
var err = e.getMessage();
|
||||
System.out.println(err);
|
||||
assertTrue(err.contains("expected module name is: foo - but found Automatic-Module-Name entry in manifest: bar"), "missing warning for: foo/bar");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that base manifest-related entries are at expected LOC positions.
|
||||
* <p>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user