-
Notifications
You must be signed in to change notification settings - Fork 753
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43443 from gabilang/fix-exitcode
[2201.8.x] Fix zero exit code when init failures during test execution
- Loading branch information
Showing
20 changed files
with
467 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...c/test/java/org/ballerinalang/testerina/test/SingleTestExecutionWithInitFailuresTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.ballerinalang.testerina.test; | ||
|
||
import org.ballerinalang.test.context.BMainInstance; | ||
import org.ballerinalang.test.context.BallerinaTestException; | ||
import org.ballerinalang.testerina.test.utils.AssertionUtils; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
|
||
public class SingleTestExecutionWithInitFailuresTest extends BaseTestCase { | ||
|
||
private BMainInstance balClient; | ||
private String projectPath; | ||
|
||
@BeforeClass | ||
public void setup() throws BallerinaTestException { | ||
balClient = new BMainInstance(balServer); | ||
projectPath = singleFileTestsPath.resolve("single-test-execution").toString(); | ||
} | ||
|
||
@Test | ||
public void testSingleBalTestExecutionWithInitFailure() throws BallerinaTestException, IOException { | ||
String[] args = mergeCoverageArgs(new String[]{"--tests", "testFunc", "bal-test-with-init-failure.bal"}); | ||
String output = balClient.runMainAndReadStdOut("test", args, new HashMap<>(), projectPath, false); | ||
AssertionUtils.assertOutput("SingleFileTestExecutionWithInitFailure.txt", output); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...est/src/test/java/org/ballerinalang/testerina/test/TestExecutionWithInitFailuresTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.ballerinalang.testerina.test; | ||
|
||
import org.ballerinalang.test.context.BMainInstance; | ||
import org.ballerinalang.test.context.BallerinaTestException; | ||
import org.ballerinalang.testerina.test.utils.AssertionUtils; | ||
import org.ballerinalang.testerina.test.utils.CommonUtils; | ||
import org.ballerinalang.testerina.test.utils.FileUtils; | ||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Paths; | ||
import java.util.HashMap; | ||
|
||
import static org.ballerinalang.testerina.test.BaseTestCase.balServer; | ||
import static org.ballerinalang.testerina.test.BaseTestCase.projectBasedTestsPath; | ||
|
||
public class TestExecutionWithInitFailuresTest { | ||
|
||
private BMainInstance balClient; | ||
private String projectPath; | ||
|
||
@BeforeClass | ||
public void setup() throws BallerinaTestException { | ||
balClient = new BMainInstance(balServer); | ||
projectPath = projectBasedTestsPath.resolve("test-execution-with-init-failure").toString(); | ||
} | ||
|
||
@Test() | ||
public void testModuleExecutionFlow() throws BallerinaTestException, IOException { | ||
String[] args = new String[]{}; | ||
String output = balClient.runMainAndReadStdOut("test", args, | ||
new HashMap<>(), projectPath, false); | ||
String firstString = "tests.test_execute-generated_"; | ||
String endString = "lineNumber"; | ||
output = CommonUtils.replaceVaryingString(firstString, endString, output); | ||
AssertionUtils.assertOutput("TestExecutionWithInitFailures.txt", output); | ||
} | ||
|
||
@AfterMethod | ||
public void copyExec() { | ||
try { | ||
FileUtils.copyBallerinaExec(Paths.get(projectPath), String.valueOf(System.currentTimeMillis())); | ||
} catch (IOException e) { | ||
// ignore exception | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...n-test/src/test/resources/command-outputs/unix/SingleFileTestExecutionWithInitFailure.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Code coverage is not yet supported with single bal files. Ignoring the flag and continuing the test run... | ||
warning: ignoring --includes flag since code coverage is not enabled | ||
Compiling source | ||
bal-test-with-init-failure.bal | ||
|
||
Running Tests | ||
|
||
bal-test-with-init-failure.bal | ||
error: {ballerina}DivisionByZero {"message":" / by zero"} | ||
error: there are test failures |
30 changes: 30 additions & 0 deletions
30
...ntegration-test/src/test/resources/command-outputs/unix/TestExecutionWithInitFailures.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Compiling source | ||
wso2/testExecutionWithModuleInitFailure:0.0.0 | ||
|
||
Running Tests | ||
|
||
testExecutionWithModuleInitFailure.moduleD | ||
[pass] testFunc | ||
|
||
|
||
1 passing | ||
0 failing | ||
0 skipped | ||
|
||
testExecutionWithModuleInitFailure | ||
error: {ballerina}DivisionByZero {"message":" / by zero"} | ||
|
||
testExecutionWithModuleInitFailure.moduleA | ||
error: {ballerina}DivisionByZero {"message":" / by zero"} | ||
|
||
testExecutionWithModuleInitFailure.moduleC | ||
[pass] testFunc | ||
|
||
|
||
1 passing | ||
0 failing | ||
0 skipped | ||
|
||
testExecutionWithModuleInitFailure.moduleB | ||
error: {ballerina}DivisionByZero {"message":" / by zero"} | ||
error: there are test failures |
10 changes: 10 additions & 0 deletions
10
...est/src/test/resources/command-outputs/windows/SingleFileTestExecutionWithInitFailure.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Code coverage is not yet supported with single bal files. Ignoring the flag and continuing the test run... | ||
warning: ignoring --includes flag since code coverage is not enabled | ||
Compiling source | ||
bal-test-with-init-failure.bal | ||
|
||
Running Tests | ||
|
||
bal-test-with-init-failure.bal | ||
error: {ballerina}DivisionByZero {"message":" / by zero"} | ||
error: there are test failures |
30 changes: 30 additions & 0 deletions
30
...gration-test/src/test/resources/command-outputs/windows/TestExecutionWithInitFailures.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Compiling source | ||
wso2/testExecutionWithModuleInitFailure:0.0.0 | ||
|
||
Running Tests | ||
|
||
testExecutionWithModuleInitFailure.moduleD | ||
[pass] testFunc | ||
|
||
|
||
1 passing | ||
0 failing | ||
0 skipped | ||
|
||
testExecutionWithModuleInitFailure | ||
error: {ballerina}DivisionByZero {"message":" / by zero"} | ||
|
||
testExecutionWithModuleInitFailure.moduleA | ||
error: {ballerina}DivisionByZero {"message":" / by zero"} | ||
|
||
testExecutionWithModuleInitFailure.moduleC | ||
[pass] testFunc | ||
|
||
|
||
1 passing | ||
0 failing | ||
0 skipped | ||
|
||
testExecutionWithModuleInitFailure.moduleB | ||
error: {ballerina}DivisionByZero {"message":" / by zero"} | ||
error: there are test failures |
7 changes: 7 additions & 0 deletions
7
...st/src/test/resources/project-based-tests/test-execution-with-init-failure/Ballerina.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
org = "wso2" | ||
name = "testExecutionWithModuleInitFailure" | ||
version = "0.0.0" | ||
|
||
[build-options] | ||
observabilityIncluded = false |
29 changes: 29 additions & 0 deletions
29
...ion-test/src/test/resources/project-based-tests/test-execution-with-init-failure/main.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). | ||
// | ||
// WSO2 LLC. licenses this file to you under the Apache License, | ||
// Version 2.0 (the "License"); you may not use this file except | ||
// in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
import testExecutionWithModuleInitFailure.moduleA; | ||
import testExecutionWithModuleInitFailure.moduleD; | ||
|
||
public function main() { | ||
} | ||
|
||
public function getGreeting(string s1, string s2) returns string { | ||
return s1 + moduleA:addSpaceAndGetString(s2); | ||
} | ||
|
||
public function getKey(int i) returns int { | ||
return i * moduleD:add(i, i*i); | ||
} |
24 changes: 24 additions & 0 deletions
24
...t/resources/project-based-tests/test-execution-with-init-failure/modules/moduleA/main.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). | ||
// | ||
// WSO2 LLC. licenses this file to you under the Apache License, | ||
// Version 2.0 (the "License"); you may not use this file except | ||
// in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
import testExecutionWithModuleInitFailure.moduleB; | ||
|
||
public function main() { | ||
} | ||
|
||
public function addSpaceAndGetString(string s) returns string { | ||
return " " + moduleB:add(s); | ||
} |
22 changes: 22 additions & 0 deletions
22
...urces/project-based-tests/test-execution-with-init-failure/modules/moduleA/tests/test.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). | ||
// | ||
// WSO2 LLC. licenses this file to you under the Apache License, | ||
// Version 2.0 (the "License"); you may not use this file except | ||
// in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
import ballerina/test; | ||
|
||
@test:Config {} | ||
public function testFunc() { | ||
test:assertEquals(addSpaceAndGetString("World"), " World!"); | ||
} |
26 changes: 26 additions & 0 deletions
26
...t/resources/project-based-tests/test-execution-with-init-failure/modules/moduleB/main.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). | ||
// | ||
// WSO2 LLC. licenses this file to you under the Apache License, | ||
// Version 2.0 (the "License"); you may not use this file except | ||
// in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
import testExecutionWithModuleInitFailure.moduleC; | ||
|
||
int a = 1/0; | ||
|
||
public function main() { | ||
} | ||
|
||
public function add(string s) returns string { | ||
return s + moduleC:foo(); | ||
} |
22 changes: 22 additions & 0 deletions
22
...urces/project-based-tests/test-execution-with-init-failure/modules/moduleB/tests/test.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). | ||
// | ||
// WSO2 LLC. licenses this file to you under the Apache License, | ||
// Version 2.0 (the "License"); you may not use this file except | ||
// in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
import ballerina/test; | ||
|
||
@test:Config {} | ||
function testFunc() { | ||
test:assertEquals(add("World"), "World!"); | ||
} |
Oops, something went wrong.