Skip to content

Commit

Permalink
Fix failure in the-main-function example
Browse files Browse the repository at this point in the history
  • Loading branch information
riyafa committed May 6, 2021
1 parent c070fcb commit 24027fa
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 28 deletions.
15 changes: 2 additions & 13 deletions examples/the-main-function/tests/the_main_function_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,9 @@ public function mockPrint(any|error... s) {
function testFunc() {
test:when(mock_printLn).call("mockPrint");

// Invoking the main function.
error? e = main("Alice");
test:assertTrue(e is ());
test:assertExactEquals(outputs[0], "Name: Alice, Age: 18, Year: Freshman");

// Invoking the main function.
counter = 0;
e = main("Alice", 20);
test:assertTrue(e is ());
test:assertExactEquals(outputs[0], "Name: Alice, Age: 20, Year: Freshman");

// Invoking the main function.
counter = 0;
e = main("Alice", 18, "Sophomore");
error? e = main("Alice", 18, "Sophomore");
test:assertTrue(e is ());
test:assertExactEquals(outputs[0], "Name: Alice, Age: 18, Year: Sophomore");

Expand All @@ -46,7 +35,7 @@ function testFunc() {

// Invoking the main function.
counter = 0;
e = main("Ali");
e = main("Ali", 30, "Freshman");
if (e is error) {
test:assertExactEquals(e.message(), "InvalidName");
test:assertExactEquals(e.toString(), "error(\"InvalidName\",message=\"invalid length\")");
Expand Down
4 changes: 2 additions & 2 deletions examples/the-main-function/the_main_function.bal
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import ballerina/io;
// The rest parameter `modules` represents the additional arguments.
// The `main` function may return an `error` or `()`.
public function main(string name,
int age = 18,
string year = "Freshman",
int age,
string year,
string... modules)
returns error? {

Expand Down
14 changes: 1 addition & 13 deletions examples/the-main-function/the_main_function.out
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
# To run this sample, navigate to the directory that contains the
# `.bal` file, and execute the `bal run` command below.

# Use the ballerina `run` command to invoke the `main` function specifying `Alice`
# as the string argument for `name`. `18` would be set as the value for
# `age` and `Freshman` would be set as the value for `year`.
bal run the_main_function.bal -- Alice
Name: Alice, Age: 18, Year: Freshman

# Use the ballerina `run` command to invoke the `main` function specifying `Alice`
# as the string argument for `name` and `20` as the integer value for
# `age`. Both arguments are specified as operands.
bal run the_main_function.bal -- Alice 20
Name: Alice, Age: 20, Year: Freshman

# Use the ballerina `run` command to invoke the `main` function specifying `Alice`
# as the string argument for `name`, 18 as the `age` and `Sophomore` as the string
# argument for `year`.
Expand All @@ -27,5 +15,5 @@ Name: Alice, Age: 20, Year: Sophomore, Module(s): ["math","physics"]

# Use the ballerina `run` command to invoke the `main` function specifying an invalid
# string as the argument for `name`. The `error` returned would be printed.
bal run the_main_function.bal -- Ali
bal run the_main_function.bal -- Ali 30 Freshman
error: InvalidName {"message":"invalid length"}

0 comments on commit 24027fa

Please sign in to comment.