Skip to content

Commit

Permalink
Merge pull request #42645 from gayaldassanayake/fix-build-tool-tests
Browse files Browse the repository at this point in the history
Fix RunBuildToolTaskTest assertions
  • Loading branch information
gayaldassanayake authored Apr 26, 2024
2 parents 9739f80 + da30d88 commit de17421
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package io.ballerina.cli.cmd;

import io.ballerina.cli.launcher.BLauncherException;
import io.ballerina.cli.task.RunBuildToolsTask;
import io.ballerina.projects.BuildOptions;
import io.ballerina.projects.Project;
Expand All @@ -36,6 +37,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;

Expand Down Expand Up @@ -88,7 +90,7 @@ public void setup() throws IOException {
}

@Test(description = "Resolve a tool offline", dataProvider = "buildToolOfflineProvider")
public void testOfflineToolResolution(String projectName, String outputFileName, boolean sticky)
public void testOfflineToolResolution(String projectName, String outputFileName, boolean sticky, boolean isError)
throws IOException {
Path projectPath = buildToolResources.resolve(projectName);
Project project = BuildProject.load(projectPath,
Expand All @@ -97,7 +99,18 @@ public void testOfflineToolResolution(String projectName, String outputFileName,
try (MockedStatic<BuildToolUtils> repoUtils = Mockito.mockStatic(
BuildToolUtils.class, Mockito.CALLS_REAL_METHODS)) {
repoUtils.when(BuildToolUtils::getCentralBalaDirPath).thenReturn(mockCentralBalaDirPath);
runBuildToolsTask.execute(project);
try {
runBuildToolsTask.execute(project);
} catch (BLauncherException e) {
if (!isError) {
String errorMsg = "Error executing build tools task for project: " + projectName
+ (sticky ? "with sticky." : "without sticky. ") + e.getMessage();
Assert.fail(errorMsg);
}
List<String> messages = e.getMessages();
Assert.assertEquals(messages.size(), 1);
Assert.assertEquals(messages.get(0), "error: build tool execution contains errors");
}
}
String buildLog = readOutput(true);
Assert.assertEquals(buildLog.replaceAll("\r", ""), getOutput(outputFileName));
Expand Down Expand Up @@ -135,76 +148,91 @@ public Object[][] buildToolOfflineProvider() {
{
"project-with-central-build-tool",
"build-tool-offline.txt",
false,
false
},
{
"project-with-non-existent-build-tool",
"build-tool-offline-resolve-failed.txt",
false
false,
true
},
{
"fresh-project-with-central-build-tool",
"build-tool-offline-resolve-failed-wo-version.txt",
false
false,
true,
},
{
"project-with-2.x-central-build-tool",
"build-tool-offline-with-new-major-version-locked.txt",
false
false,
true
},
{
"project-with-non-existent-subcommand",
"build-tool-non-existent-subcommand.txt",
false,
false
},
{
"project-with-invalid-name-build-tool",
"build-tool-invalid-name.txt",
false,
false
},
{
"project-with-multilevel-subcommands",
"build-tool-multilevel-subcommands.txt",
false,
false
},
{
"project-with-only-subcommands",
"build-tool-only-subcommands.txt",
false,
false
},
{
"project-with-hidden-commands",
"build-tool-hidden-commands.txt",
false,
false
},
{
"project-with-missing-interface-build-tool",
"build-tool-missing-interface.txt",
false,
false
},
{
"project-with-no-options-build-tool",
"build-tool-no-options.txt",
false,
false
},
{
"project-with-old-build-tool",
"build-tool-without-sticky.txt",
false,
false
},
{
"project-with-old-build-tool",
"build-tool-with-sticky.txt",
true,
true
},
{
"project-lt-24h-with-build-tool",
"build-tool-lt-24-build-file.txt",
false
false,
true
},
{
"project-gt-24h-with-build-tool",
"build-tool-gt-24-build-file.txt",
false,
false
},
};
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Executing Build Tools
ERROR [Ballerina.toml:(6:1,10:24)] Build tool 'dummy_tool:1.3.0' cannot be resolved

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Executing Build Tools
ERROR [Ballerina.toml:(6:1,10:24)] Build tool 'dummy_tool' cannot be resolved

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Executing Build Tools
ERROR [Ballerina.toml:(6:1,10:24)] Build tool 'nonexistent:1.4.0' cannot be resolved

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Executing Build Tools
ERROR [Ballerina.toml:(6:1,10:24)] Build tool 'dummy_tool:2.0.0' cannot be resolved

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Executing Build Tools
ERROR [Ballerina.toml:(6:1,10:24)] Build tool 'dummy_tool:1.3.5' cannot be resolved

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Executing Build Tools
ERROR [Ballerina.toml:(6:1,10:24)] Build tool 'dummy_tool:1.3.0' cannot be resolved

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Executing Build Tools
ERROR [Ballerina.toml:(6:1,10:24)] Build tool 'dummy_tool' cannot be resolved

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Executing Build Tools
ERROR [Ballerina.toml:(6:1,10:24)] Build tool 'nonexistent:1.4.0' cannot be resolved

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Executing Build Tools
ERROR [Ballerina.toml:(6:1,10:24)] Build tool 'dummy_tool:2.0.0' cannot be resolved

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Executing Build Tools
ERROR [Ballerina.toml:(6:1,10:24)] Build tool 'dummy_tool:1.3.5' cannot be resolved

0 comments on commit de17421

Please sign in to comment.