Skip to content

Commit

Permalink
Merge pull request #42709 from gabilang/fix-unescape-identifier
Browse files Browse the repository at this point in the history
Fix NoSuchFieldError for escaped identifiers during bal test
  • Loading branch information
warunalakshitha authored Jun 4, 2024
2 parents dcc0437 + 242f192 commit e6639af
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1936,7 +1936,8 @@ private BIRGlobalVariableDcl getVarRef(BLangPackageVarRef astPackageVarRefExpr)
this.globalVarMap.put(symbol, globalVarDcl);
}

if (!isInSamePackage(astPackageVarRefExpr.varSymbol, env.enclPkg.packageID)) {
if (!isInSamePackage(astPackageVarRefExpr.varSymbol, env.enclPkg.packageID) ||
env.enclPkg.packageID.isTestPkg) {
this.env.enclPkg.importedGlobalVarsDummyVarDcls.add(globalVarDcl);
}
return globalVarDcl;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://wso2.com).
*
* Licensed 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;

/**
* Test class containing tests related to escaped identifiers validation.
*/
public class EscapedIdentifiersValidationTest extends BaseTestCase {

private BMainInstance balClient;
private String projectPath;

@BeforeClass
public void setup() throws BallerinaTestException {
balClient = new BMainInstance(balServer);
projectPath = projectBasedTestsPath.toString();
}

@Test
public void validateEscapedIdentifiersTest() throws BallerinaTestException, IOException {
String[] args = mergeCoverageArgs(new String[]{"validate-escaped-identifiers"});
String output = balClient.runMainAndReadStdOut("test", args,
new HashMap<>(), projectPath, true);
AssertionUtils.assertOutput("EscapedIdentifiersValidationTest-validateEscapedIdentifiersTest.txt",
output);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Compiling source
intg_tests/validate_escaped_identifiers:0.0.0

Running Tests with Coverage

validate_escaped_identifiers
[pass] test
[pass] test_add


2 passing
0 failing
0 skipped

Test execution time :*****s

Generating Test Report
validate-escaped-identifiers/target/report/test_results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Compiling source
intg_tests/validate_escaped_identifiers:0.0.0

Running Tests with Coverage

validate_escaped_identifiers
[pass] test
[pass] test_add


2 passing
0 failing
0 skipped

Test execution time :*****s

Generating Test Report
validate-escaped-identifiers\target\report\test_results.json

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
org = "intg_tests"
name = "validate_escaped_identifiers"
version = "0.0.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
//
// WSO2 Inc. 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.

public int int\-a = 10;

client class Client {
resource function get users\-all(string 'order = "asc") returns json {
return {
"users": [
{
"name": "Mitchell",
"age": 30
},
{
"name": "Andrew",
"age": 35
}
]
};
}
}

final Client clientEP = new;

function add(int a, int b) returns int {
return a + b;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
//
// WSO2 Inc. 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 test_add() {
test:assertEquals(add(1, int\-a), 11);
}

@test:Config {}
function test() {
json res = clientEP->/users\-all();
test:assertEquals(res, {"users":[{"name":"Mitchell","age":30},{"name":"Andrew","age":35}]});
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ under the License.
<class name="org.ballerinalang.testerina.test.TestparallelizationTest"/>
<class name="org.ballerinalang.testerina.test.SingleTestExecutionWithInitFailuresTest"/>
<class name="org.ballerinalang.testerina.test.TestExecutionWithInitFailuresTest"/>
<class name="org.ballerinalang.testerina.test.EscapedIdentifiersValidationTest"/>
</classes>
</test>
</suite>

0 comments on commit e6639af

Please sign in to comment.