|
#include "test_utils.h"
|
|
|
|
UnittestTestResult_t* test_println_int(void) {
|
|
UNITTEST_BEGIN_TEST("TestPrintln", "test_println_int");
|
|
|
|
RAVA_TEST_RUN(_unittest_result,
|
|
"public class Test {\n"
|
|
" public static int main() {\n"
|
|
" System.out.println(42);\n"
|
|
" return 42;\n"
|
|
" }\n"
|
|
"}\n",
|
|
"Test", "main", 42, "println should execute and return value");
|
|
|
|
UNITTEST_END_TEST();
|
|
}
|
|
|
|
UnittestTestResult_t* test_println_expression(void) {
|
|
UNITTEST_BEGIN_TEST("TestPrintln", "test_println_expression");
|
|
|
|
RAVA_TEST_RUN(_unittest_result,
|
|
"public class Test {\n"
|
|
" public static int main() {\n"
|
|
" int x = 10;\n"
|
|
" int y = 20;\n"
|
|
" System.out.println(x + y);\n"
|
|
" return x + y;\n"
|
|
" }\n"
|
|
"}\n",
|
|
"Test", "main", 30, "println with expression should work");
|
|
|
|
UNITTEST_END_TEST();
|
|
}
|
|
|
|
UnittestTestResult_t* test_println_multiple(void) {
|
|
UNITTEST_BEGIN_TEST("TestPrintln", "test_println_multiple");
|
|
|
|
RAVA_TEST_RUN(_unittest_result,
|
|
"public class Test {\n"
|
|
" public static int main() {\n"
|
|
" System.out.println(1);\n"
|
|
" System.out.println(2);\n"
|
|
" System.out.println(3);\n"
|
|
" return 6;\n"
|
|
" }\n"
|
|
"}\n",
|
|
"Test", "main", 6, "multiple println calls should work");
|
|
|
|
UNITTEST_END_TEST();
|
|
}
|
|
|
|
UnittestTestResult_t* test_print_no_newline(void) {
|
|
UNITTEST_BEGIN_TEST("TestPrintln", "test_print_no_newline");
|
|
|
|
RAVA_TEST_RUN(_unittest_result,
|
|
"public class Test {\n"
|
|
" public static int main() {\n"
|
|
" System.out.print(42);\n"
|
|
" return 42;\n"
|
|
" }\n"
|
|
"}\n",
|
|
"Test", "main", 42, "print without newline should work");
|
|
|
|
UNITTEST_END_TEST();
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
UnittestConfig_t *config = unittest_config_create();
|
|
config->verbosity = 2;
|
|
|
|
if (argc > 1 && strcmp(argv[1], "--json") == 0) {
|
|
config->output_format = UNITTEST_FORMAT_JSON;
|
|
config->use_colors = false;
|
|
}
|
|
|
|
UnittestTestSuite_t *suite = unittest_test_suite_create("Print/Println Tests");
|
|
|
|
UnittestTestCase_t *tc = unittest_test_case_create("TestPrintln");
|
|
unittest_test_case_add_result(tc, test_println_int());
|
|
unittest_test_case_add_result(tc, test_println_expression());
|
|
unittest_test_case_add_result(tc, test_println_multiple());
|
|
unittest_test_case_add_result(tc, test_print_no_newline());
|
|
unittest_test_suite_add_test_case(suite, tc);
|
|
|
|
unittest_generate_report(suite, config);
|
|
|
|
int failures = suite->total_failed + suite->total_errors;
|
|
unittest_test_suite_destroy(suite);
|
|
unittest_config_destroy(config);
|
|
|
|
return failures > 0 ? 1 : 0;
|
|
}
|