From 24027fae817d20cd07cc410e8109aae5c74ea153 Mon Sep 17 00:00:00 2001 From: riyafa Date: Thu, 6 May 2021 10:20:14 +0530 Subject: [PATCH] Fix failure in the-main-function example --- .../tests/the_main_function_test.bal | 15 ++------------- examples/the-main-function/the_main_function.bal | 4 ++-- examples/the-main-function/the_main_function.out | 14 +------------- 3 files changed, 5 insertions(+), 28 deletions(-) diff --git a/examples/the-main-function/tests/the_main_function_test.bal b/examples/the-main-function/tests/the_main_function_test.bal index 02ec40e7fa..98354cffe3 100644 --- a/examples/the-main-function/tests/the_main_function_test.bal +++ b/examples/the-main-function/tests/the_main_function_test.bal @@ -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"); @@ -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\")"); diff --git a/examples/the-main-function/the_main_function.bal b/examples/the-main-function/the_main_function.bal index 783ea95d84..e431462de2 100644 --- a/examples/the-main-function/the_main_function.bal +++ b/examples/the-main-function/the_main_function.bal @@ -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? { diff --git a/examples/the-main-function/the_main_function.out b/examples/the-main-function/the_main_function.out index de491261ed..a6a9353e2d 100644 --- a/examples/the-main-function/the_main_function.out +++ b/examples/the-main-function/the_main_function.out @@ -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`. @@ -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"}