Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conformance tests for trap-expr #1085

Conversation

KavinduZoysa
Copy link
Contributor

@KavinduZoysa KavinduZoysa changed the base branch from master to conformance-tests April 19, 2022 15:46
conformance/lang/expressions/trap_expr.balt Outdated Show resolved Hide resolved
conformance/lang/expressions/trap_expr.balt Outdated Show resolved Hide resolved
conformance/lang/expressions/trap_expr.balt Outdated Show resolved Hide resolved
conformance/lang/expressions/trap_expr.balt Outdated Show resolved Hide resolved
conformance/lang/expressions/trap_expr.balt Outdated Show resolved Hide resolved
conformance/lang/expressions/trap_expr.balt Outdated Show resolved Hide resolved
conformance/lang/expressions/trap_expr.balt Show resolved Hide resolved
conformance/lang/expressions/trap_expr.balt Outdated Show resolved Hide resolved
conformance/lang/expressions/trap_expr.balt Outdated Show resolved Hide resolved
conformance/lang/expressions/trap_expr.balt Show resolved Hide resolved
conformance/lang/expressions/trap_expr.balt Outdated Show resolved Hide resolved
conformance/lang/expressions/trap_expr.balt Show resolved Hide resolved
conformance/lang/expressions/trap_expr.balt Outdated Show resolved Hide resolved
conformance/lang/expressions/trap_expr.balt Outdated Show resolved Hide resolved
conformance/lang/expressions/trap_expr.balt Outdated Show resolved Hide resolved
Comment on lines 232 to 238
function foo() returns int {
return 0;
}

function errorFunction() {
int _ = trap 2 / foo(); // @error incompatible types: expected 'int', found '(int|error)'
error e = trap 2 / foo(); // @error incompatible types: expected 'error', found 'int'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the test overly complicated? We don't need a function call. Even a variable reference would suffice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

Comment on lines 232 to 238
function foo() returns int {
return 0;
}

function errorFunction() {
int _ = trap 2 / foo(); // @error incompatible types: expected 'int', found '(int|error)'
error e = trap 2 / foo(); // @error incompatible types: expected 'error', found 'int'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the error correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created an issue and moved this test to failing tests

int|error t1 = trap trap 2 / foo();
io:println(t1); // @output error("{ballerina}DivisionByZero",message=" / by zero")
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have tests for when the expression doesn't panic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added few tests at the bottom

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it the test immediately after this? Can we improve the descriptions to specifically mention that they don't panic?

conformance/lang/expressions/trap_expr.balt Outdated Show resolved Hide resolved
conformance/lang/expressions/trap_expr.balt Outdated Show resolved Hide resolved
conformance/lang/expressions/trap_expr.balt Outdated Show resolved Hide resolved
conformance/lang/expressions/trap_expr.balt Show resolved Hide resolved
@KavinduZoysa KavinduZoysa force-pushed the trap-expr-conformance-tests branch from cf23ec1 to 8d3942d Compare August 30, 2022 09:14
@@ -0,0 +1,351 @@
Test-Case: output
Description: Test evaluation of expression resulting in value v,
Copy link
Member

@MaryamZi MaryamZi Sep 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this? It's not clear what v is. I would say

Suggested change
Description: Test evaluation of expression resulting in value v,
Description: Test the result of the trap expression being `e`, when evaluation of the expression completes abruptly with panic with associated value `e`.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please recheck all descriptions. We need to make the concise, but self-explanatory and clear.

}

Test-Case: output
Description: Test trap expression when the expression is a type-cast-expr.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Description: Test trap expression when the expression is a type-cast-expr.
Description: Test trap expression when the expression is a type cast expression.

Please update wherever applicable.

int|error t1 = trap trap 2 / foo();
io:println(t1); // @output error("{ballerina}DivisionByZero",message=" / by zero")
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it the test immediately after this? Can we improve the descriptions to specifically mention that they don't panic?

@KavinduZoysa KavinduZoysa force-pushed the trap-expr-conformance-tests branch from 8d3942d to fb67a16 Compare September 12, 2022 14:29
@MaryamZi MaryamZi changed the base branch from conformance-tests to master September 30, 2022 04:59
conformance/lang/expressions/trap_expr.balt Outdated Show resolved Hide resolved
conformance/lang/expressions/trap_expr.balt Outdated Show resolved Hide resolved
conformance/lang/expressions/trap_expr.balt Outdated Show resolved Hide resolved
conformance/lang/expressions/trap_expr.balt Outdated Show resolved Hide resolved
conformance/lang/expressions/trap_expr.balt Outdated Show resolved Hide resolved
}

Test-Case: output
Description: Test trap expression when the expression is a numeric-literal and it does not panic.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When does a numeric literal panic?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for string.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on this?

Let's also remove the productions from the descriptions everywhere.

numeric-literal -> numeric literal

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5303f62

conformance/lang/expressions/trap_expr.balt Outdated Show resolved Hide resolved
conformance/lang/expressions/trap_expr.balt Outdated Show resolved Hide resolved
}

Test-Case: output
Description: Test trap expression when the expression is a byte value and it does not panic.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add some tests with function calls here instead of literals and variable reference expressions that we know will never panic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaryamZi, do you mean here to add function calls that causes panic or add functions that return literal?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like a function call, which at compile-time we don't know if it will panic.

function init() {
    int|error a = trap fn("1");
    io:println(a);
}

function fn(string str) returns int {
    return checkpanic int:fromString(str);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

@KavinduZoysa KavinduZoysa force-pushed the trap-expr-conformance-tests branch from 530a9c8 to 5303f62 Compare October 31, 2022 04:43
}

Test-Case: output
Description: Test trap expression when the expression is a function call which returns subtype of int or panic.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Description: Test trap expression when the expression is a function call which returns subtype of int or panic.
Description: Test trap expression when the expression is a function call which returns a subtype of int or panics.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix wherever applicable.

}

Test-Case: output
Description: Test trap expression when the expression is a query expression
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Description: Test trap expression when the expression is a query expression
Description: Test trap expression when the expression is a query expression.


function init() {
int zero = 0;
int|error e1 = trap (check 2 / zero);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a bug. trap captures a panic. check should return the error from the function. Can you recheck in the spec and create a spec issue if required or a lang issue?

Comment on lines +217 to +218
int[] i = [];
return i[3];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing member access related labels in Labels.


function init() {
Obj obj = new();
error? t = trap obj.bar();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't match the description.

Test trap expression when the expression is a new expression.

panic error("msg");
}
};
error? e = trap obj.bar();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also doesn't match the description.

@hasithaa hasithaa closed this Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Waiting on Author
Development

Successfully merging this pull request may close these issues.

Add spec conformance tests for trap-expr
5 participants