Skip to content

Commit

Permalink
Merge pull request #41826 from gayaldassanayake/fix-pack-tests
Browse files Browse the repository at this point in the history
Update PackCommandTest to fix failures
  • Loading branch information
azinneera authored Dec 18, 2023
2 parents 690c82e + e066665 commit d0afe8d
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 23 deletions.
2 changes: 2 additions & 0 deletions cli/ballerina-cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ dependencies {
compilerPluginJar project(':project-api-test-artifact:log-creator-pkg-provided-code-modifier')
compilerPluginJar project(':project-api-test-artifact:log-creator-pkg-provided-code-generator')
compilerPluginJar project(':project-api-test-artifact:log-creator-pkg-provided-code-analyzer')
compilerPluginJar project(':project-api-test-artifact:init-function-code-modify-compiler-plugin')
compilerPluginJar project(':project-api-test-artifact:diagnostic-utils-lib')
}

task createTestDistributionCache(type: Copy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import org.wso2.ballerinalang.util.RepoUtils;
import picocli.CommandLine;

import java.io.IOException;
Expand All @@ -18,8 +19,9 @@
import java.nio.file.Paths;
import java.util.Objects;

import static io.ballerina.cli.cmd.CommandOutputUtils.assertTomlFilesEquals;
import static io.ballerina.cli.cmd.CommandOutputUtils.getOutput;
import static io.ballerina.cli.cmd.CommandOutputUtils.readFileAsString;
import static io.ballerina.cli.cmd.CommandOutputUtils.replaceDependenciesTomlContent;
import static io.ballerina.projects.util.ProjectConstants.DEPENDENCIES_TOML;
import static io.ballerina.projects.util.ProjectConstants.RESOURCE_DIR_NAME;

Expand All @@ -43,8 +45,15 @@ public void setup() throws IOException {
this.testResources = super.tmpDir.resolve("build-test-resources");
URI testResourcesURI = Objects.requireNonNull(getClass().getClassLoader().getResource("test-resources"))
.toURI();
Files.walkFileTree(Paths.get(testResourcesURI),
new BuildCommandTest.Copy(Paths.get(testResourcesURI), this.testResources));
Path testResourcesPath = Paths.get(testResourcesURI);
Files.walkFileTree(testResourcesPath,
new BuildCommandTest.Copy(testResourcesPath, this.testResources));

// Copy the compiler plugin jars to the test resources directory
Path compilerPluginJarsPath = Paths.get("build", "compiler-plugin-jars");
Files.walkFileTree(compilerPluginJarsPath,
new BuildCommandTest.Copy(compilerPluginJarsPath,
this.testResources.resolve("compiler-plugin-jars")));
} catch (URISyntaxException e) {
Assert.fail("error loading resources");
}
Expand Down Expand Up @@ -258,10 +267,8 @@ public void testPackageWithEmptyDependenciesToml() throws IOException {
// `Dependencies.toml` file should not get deleted
Assert.assertTrue(projectPath.resolve(DEPENDENCIES_TOML).toFile().exists());
// `dependencies-toml-version` should exists in `Dependencies.toml`
String expected = "[ballerina]\n"
+ "dependencies-toml-version = \"2\"";
String actual = Files.readString(projectPath.resolve(DEPENDENCIES_TOML));
Assert.assertTrue(actual.contains(expected));
assertTomlFilesEquals(projectPath.resolve(DEPENDENCIES_TOML),
projectPath.resolve("resources").resolve("expectedDependencies.toml"));
}

@Test(description = "Pack a package without root package in Dependencies.toml")
Expand All @@ -278,8 +285,8 @@ public void testPackageWithoutRootPackageInDependenciesToml() throws IOException
Assert.assertTrue(projectPath.resolve("target").resolve("bala").resolve("foo-winery-java17-0.1.0.bala")
.toFile().exists());

Assert.assertEquals(readFileAsString(projectPath.resolve(DEPENDENCIES_TOML)).trim(), readFileAsString(
projectPath.resolve(RESOURCE_DIR_NAME).resolve("expectedDependencies.toml")).trim());
assertTomlFilesEquals(projectPath.resolve(DEPENDENCIES_TOML),
projectPath.resolve(RESOURCE_DIR_NAME).resolve("expectedDependencies.toml"));
}

@Test(description = "Pack an empty package with compiler plugin")
Expand All @@ -293,7 +300,7 @@ public void testPackEmptyProjectWithCompilerPlugin() throws IOException {
String buildLog = readOutput(true);

Assert.assertTrue(projectPath.resolve("target").resolve("bala")
.resolve("wso2-emptyProjWithCompilerPlugin-any-0.1.0.bala").toFile().exists());
.resolve("wso2-emptyProjWithCompilerPlugin-java17-0.1.0.bala").toFile().exists());
Assert.assertEquals(buildLog.replaceAll("\r", ""),
getOutput("compile-empty-project-with-compiler-plugin.txt"));
}
Expand All @@ -309,7 +316,7 @@ public void testPackEmptyProjectWithTool() throws IOException {
String buildLog = readOutput(true);

Assert.assertTrue(projectPath.resolve("target").resolve("bala")
.resolve("wso2-emptyProjWithTool-any-0.1.0.bala").toFile().exists());
.resolve("wso2-emptyProjWithTool-java17-0.1.0.bala").toFile().exists());
Assert.assertEquals(buildLog.replaceAll("\r", ""),
getOutput("compile-empty-project-with-tool.txt"));
}
Expand Down Expand Up @@ -427,6 +434,8 @@ public void testPackEmptyPackage() throws IOException {
@Test(description = "Pack an empty package with compiler plugin")
public void testPackEmptyPackageWithCompilerPlugin() throws IOException {
Path projectPath = this.testResources.resolve("emptyPackageWithCompilerPlugin");
replaceDependenciesTomlContent(
projectPath, "**INSERT_DISTRIBUTION_VERSION_HERE**", RepoUtils.getBallerinaShortVersion());
System.setProperty("user.dir", projectPath.toString());

PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true);
Expand All @@ -445,7 +454,7 @@ private void buildAndCacheCompilerPluginPackage() {
BCompileUtil.compileAndCacheBala(compilerPluginPath.toString());
}

@Test(enabled = false, description = "Pack a non template package with a compiler plugin dependency",
@Test(description = "Pack a non template package with a compiler plugin dependency",
groups = {"packWithCompilerPlugin"})
public void testPackNonTemplatePackageWithACompilerPackageDependency() throws IOException {

Expand All @@ -470,7 +479,7 @@ public void testPackNonTemplatePackageWithACompilerPackageDependency() throws IO
"returns error? {\n}"));
}

@Test(enabled = false, description = "Pack a template package with a compiler plugin dependency",
@Test(description = "Pack a template package with a compiler plugin dependency",
groups = {"packWithCompilerPlugin"})
public void testPackTemplatePackageWithACompilerPackageDependency() throws IOException {

Expand All @@ -497,14 +506,14 @@ public void testPackTemplatePackageWithACompilerPackageDependency() throws IOExc

@Test(description = "Pack a library package with platform libraries")
public void testPackProjectWithPlatformLibs() throws IOException {
Path projectPath = this.testResources.resolve("validProjectWithPlatformLibs");
Path projectPath = this.testResources.resolve("validProjectWithPlatformLibs1");
System.setProperty("user.dir", projectPath.toString());

PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true);
new CommandLine(packCommand).parseArgs();
packCommand.execute();
String buildLog = readOutput(true);
Assert.assertTrue(buildLog.contains("WARNING: Package is not verified with GraalVM."));
Assert.assertEquals(buildLog.replaceAll("\r", ""), getOutput("pack-project-with-platform-libs.txt"));
}

@AfterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Compiling source
wso2/emptyProjWithCompilerPlugin:0.1.0

Creating bala
target/bala/wso2-emptyProjWithCompilerPlugin-any-0.1.0.bala
target/bala/wso2-emptyProjWithCompilerPlugin-java17-0.1.0.bala
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Compiling source
wso2/emptyProjWithTool:0.1.0

Creating bala
target/bala/wso2-emptyProjWithTool-any-0.1.0.bala
target/bala/wso2-emptyProjWithTool-java17-0.1.0.bala
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Compiling source
user/LibraryProject:0.1.0

Creating bala
target/bala/user-LibraryProject-any-0.1.0.bala
target/bala/user-LibraryProject-java17-0.1.0.bala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Compiling source
sameera/myproject:0.1.0

Creating bala

************************************************************
* WARNING: Package is not verified with GraalVM. *
************************************************************

The GraalVM compatibility property has not been defined for the package 'myproject'. This could potentially lead to compatibility issues with GraalVM.

To resolve this warning, please ensure that all Java dependencies of this package are compatible with GraalVM. Subsequently, update the Ballerina.toml file under the section '[platform.java17]' with the attribute 'graalvmCompatible = true'.

************************************************************

target/bala/sameera-myproject-java17-0.1.0.bala
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Compiling source
wso2/emptyProjWithCompilerPlugin:0.1.0

Creating bala
target\bala\wso2-emptyProjWithCompilerPlugin-any-0.1.0.bala
target\bala\wso2-emptyProjWithCompilerPlugin-java17-0.1.0.bala
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Compiling source
wso2/emptyProjWithTool:0.1.0

Creating bala
target\bala\wso2-emptyProjWithTool-any-0.1.0.bala
target\bala\wso2-emptyProjWithTool-java17-0.1.0.bala
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Compiling source
user/LibraryProject:0.1.0

Creating bala
target\bala\user-LibraryProject-any-0.1.0.bala
target\bala\user-LibraryProject-java17-0.1.0.bala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Compiling source
sameera/myproject:0.1.0

Creating bala

************************************************************
* WARNING: Package is not verified with GraalVM. *
************************************************************

The GraalVM compatibility property has not been defined for the package 'myproject'. This could potentially lead to compatibility issues with GraalVM.

To resolve this warning, please ensure that all Java dependencies of this package are compatible with GraalVM. Subsequently, update the Ballerina.toml file under the section '[platform.java17]' with the attribute 'graalvmCompatible = true'.

************************************************************

target\bala\sameera-myproject-java17-0.1.0.bala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
class = "io.samjs.plugins.init.codemodify.CodeModifyFunctionPlugin"

[[dependency]]
path = "../init-function-code-modify-compiler-plugin-1.0.0.jar"
path = "../../compiler-plugin-jars/init-function-code-modify-compiler-plugin-1.0.0.jar"

[[dependency]]
path = "../diagnostic-utils-lib-1.0.0.jar"
path = "../../compiler-plugin-jars/diagnostic-utils-lib-1.0.0.jar"
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "**INSERT_DISTRIBUTION_VERSION_HERE**"

[[package]]
org = "user"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# AUTO-GENERATED FILE. DO NOT MODIFY.

# This file is auto-generated by Ballerina for managing dependency versions.
# It should not be modified by hand.

[ballerina]
dependencies-toml-version = "2"
distribution-version = "**INSERT_DISTRIBUTION_VERSION_HERE**"

[[package]]
org = "foo"
name = "winery"
version = "0.1.0"
modules = [
{org = "foo", packageName = "winery", moduleName = "winery"}
]

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "**INSERT_DISTRIBUTION_VERSION_HERE**"

[[package]]
org = "ballerina"
Expand Down

0 comments on commit d0afe8d

Please sign in to comment.