diff --git a/CMakeLists.txt b/CMakeLists.txt index 125bfbd..9ecc00e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,7 @@ project(xlang DESCRIPTION "XLANG Compiler") enable_language(CXX) +enable_testing() set(CMAKE_CXX_COMPILER /bin/clang++) set(CXX_STANDARD 23) set(CMAKE_CXX_FLAGS "-std=c++${CXX_STANDARD}") @@ -20,4 +21,10 @@ add_executable(${PROJECT_NAME} ${SOURCES}) target_link_libraries( ${PROJECT_NAME} -) \ No newline at end of file +) + +add_test(NAME CompactSourceAll COMMAND ${PROJECT_NAME} ../examples/compact/exitall.x) +add_test(NAME TestOutputBinary COMMAND ${CMAKE_COMMAND} + -DTEST_EXECUTABLE=./out + -P ${CMAKE_CURRENT_SOURCE_DIR}/check_exit_9.cmake) +set_tests_properties(TestOutputBinary PROPERTIES DEPENDS CompactSourceAll) \ No newline at end of file diff --git a/check_exit_9.cmake b/check_exit_9.cmake new file mode 100644 index 0000000..263d79b --- /dev/null +++ b/check_exit_9.cmake @@ -0,0 +1,10 @@ +execute_process( + COMMAND ${TEST_EXECUTABLE} ${TEST_ARGS} + RESULT_VARIABLE EXIT_CODE +) + +message(STATUS "Test exited with code: ${EXIT_CODE}") + +if(NOT EXIT_CODE EQUAL 9) + message(FATAL_ERROR "Expected exit code 9, but got ${EXIT_CODE}") +endif() diff --git a/examples/compact/exitall.x b/examples/compact/exitall.x index 17ee1c6..d352e84 100644 --- a/examples/compact/exitall.x +++ b/examples/compact/exitall.x @@ -5,7 +5,7 @@ var x = 1 + 2 * 3; } var y = x - 3; var z = (3 * 5) / 3; -if (x) { - exit(y + z); +if (x ) { + exit(y + z); } -exit (1); // Should never exit \ No newline at end of file +exit (1); \ No newline at end of file diff --git a/src/tokenization.hxx b/src/tokenization.hxx index a622a11..e9362b3 100644 --- a/src/tokenization.hxx +++ b/src/tokenization.hxx @@ -83,6 +83,12 @@ public: } tokens.push_back({.type = TokenType::int_lit, .value = buffer}); buffer.clear(); + } else if (peek().value() == '/' && peek(1).has_value() && peek(1).value() == '/') { + consume(); + consume(); + while (peek().has_value() && peek().value() != '\n') { + consume(); + } } else if (std::isspace(peek().value())) { consume(); } else {