From dee4088a385e70d21e2577ed74028d5a87af57b1 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sat, 19 Oct 2024 22:06:39 +0700 Subject: [PATCH] test: separate `test_assert.cmake` into several files --- CMakeLists.txt | 3 + test/test_assert.cmake | 398 --------------------------------- test/test_assert_number.cmake | 160 +++++++++++++ test/test_assert_string.cmake | 120 ++++++++++ test/test_assert_version.cmake | 121 ++++++++++ 5 files changed, 404 insertions(+), 398 deletions(-) create mode 100644 test/test_assert_number.cmake create mode 100644 test/test_assert_string.cmake create mode 100644 test/test_assert_version.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 0fd591f..b4bcdf7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,10 @@ if(ASSERTION_ENABLE_TESTS) add_cmake_script_test(test/test_add_test.cmake) add_cmake_script_test(test/test_assert_call.cmake) + add_cmake_script_test(test/test_assert_number.cmake) add_cmake_script_test(test/test_assert_process.cmake) + add_cmake_script_test(test/test_assert_string.cmake) + add_cmake_script_test(test/test_assert_version.cmake) add_cmake_script_test(test/test_assert.cmake) add_cmake_script_test(test/test_fail.cmake) endif() diff --git a/test/test_assert.cmake b/test/test_assert.cmake index dc950ea..8d31d4f 100644 --- a/test/test_assert.cmake +++ b/test/test_assert.cmake @@ -374,404 +374,6 @@ section("regular expression match condition assertions") endsection() endsection() -section("number equality condition assertions") - set(SEVEN_VAR 7) - set(THIRTEEN_VAR 13) - - section("given equal numbers") - section("it should assert number equality conditions") - assert(NOT 7 LESS 7) - assert(NOT 7 GREATER 7) - assert(7 EQUAL 7) - assert(7 LESS_EQUAL 7) - assert(7 GREATER_EQUAL 7) - - assert(NOT SEVEN_VAR LESS SEVEN_VAR) - assert(NOT SEVEN_VAR GREATER SEVEN_VAR) - assert(SEVEN_VAR EQUAL SEVEN_VAR) - assert(SEVEN_VAR LESS_EQUAL SEVEN_VAR) - assert(SEVEN_VAR GREATER_EQUAL SEVEN_VAR) - endsection() - - section("it should fail to assert number equality conditions") - assert_call(assert 7 LESS 7 - EXPECT_FATAL_ERROR STREQUAL - "expected number:\n 7\nto be less than:\n 7") - - assert_call(assert 7 GREATER 7 - EXPECT_FATAL_ERROR STREQUAL - "expected number:\n 7\nto be greater than:\n 7") - - assert_call(assert NOT 7 EQUAL 7 - EXPECT_FATAL_ERROR STREQUAL - "expected number:\n 7\nnot to be equal to:\n 7") - - assert_call(assert NOT 7 LESS_EQUAL 7 - EXPECT_FATAL_ERROR STREQUAL "expected number:\n 7\n" - "not to be less than or equal to:\n 7") - - assert_call(assert NOT 7 GREATER_EQUAL 7 - EXPECT_FATAL_ERROR STREQUAL "expected number:\n 7\n" - "not to be greater than or equal to:\n 7") - endsection() - endsection() - - section("given a lesser number") - section("it should assert number equality conditions") - assert(7 LESS 13) - assert(NOT 7 GREATER 13) - assert(NOT 7 EQUAL 13) - assert(7 LESS_EQUAL 13) - assert(NOT 7 GREATER_EQUAL 13) - - assert(SEVEN_VAR LESS THIRTEEN_VAR) - assert(NOT SEVEN_VAR GREATER THIRTEEN_VAR) - assert(NOT SEVEN_VAR EQUAL THIRTEEN_VAR) - assert(SEVEN_VAR LESS_EQUAL THIRTEEN_VAR) - assert(NOT SEVEN_VAR GREATER_EQUAL THIRTEEN_VAR) - endsection() - - section("it should fail to assert number equality conditions") - assert_call(assert NOT 7 LESS 13 - EXPECT_FATAL_ERROR STREQUAL "expected number:\n 7\n" - "not to be less than:\n 13") - - assert_call(assert 7 GREATER 13 - EXPECT_FATAL_ERROR STREQUAL "expected number:\n 7\n" - "to be greater than:\n 13") - - assert_call(assert 7 EQUAL 13 - EXPECT_FATAL_ERROR STREQUAL "expected number:\n 7\n" - "to be equal to:\n 13") - - assert_call(assert NOT 7 LESS_EQUAL 13 - EXPECT_FATAL_ERROR STREQUAL "expected number:\n 7\n" - "not to be less than or equal to:\n 13") - - assert_call(assert 7 GREATER_EQUAL 13 - EXPECT_FATAL_ERROR STREQUAL "expected number:\n 7\n" - "to be greater than or equal to:\n 13") - endsection() - endsection() - - section("given a greater number") - section("it should assert number equality conditions") - assert(NOT 13 LESS 7) - assert(13 GREATER 7) - assert(NOT 13 EQUAL 7) - assert(NOT 13 LESS_EQUAL 7) - assert(13 GREATER_EQUAL 7) - - assert(NOT THIRTEEN_VAR LESS SEVEN_VAR) - assert(THIRTEEN_VAR GREATER SEVEN_VAR) - assert(NOT THIRTEEN_VAR EQUAL SEVEN_VAR) - assert(NOT THIRTEEN_VAR LESS_EQUAL SEVEN_VAR) - assert(THIRTEEN_VAR GREATER_EQUAL SEVEN_VAR) - endsection() - - section("it should fail to assert number equality conditions") - assert_call(assert 13 LESS 7 - EXPECT_FATAL_ERROR STREQUAL "expected number:\n 13\n" - "to be less than:\n 7") - - assert_call(assert NOT 13 GREATER 7 - EXPECT_FATAL_ERROR STREQUAL "expected number:\n 13\n" - "not to be greater than:\n 7") - - assert_call(assert 13 EQUAL 7 - EXPECT_FATAL_ERROR STREQUAL "expected number:\n 13\n" - "to be equal to:\n 7") - - assert_call(assert 13 LESS_EQUAL 7 - EXPECT_FATAL_ERROR STREQUAL "expected number:\n 13\n" - "to be less than or equal to:\n 7") - - assert_call(assert NOT 13 GREATER_EQUAL 7 - EXPECT_FATAL_ERROR STREQUAL "expected number:\n 13\n" - "not to be greater than or equal to:\n 7") - endsection() - endsection() - - section("given a non-number") - section("it should assert number equality conditions") - set(STRING_VAR "some string") - - assert(NOT 7 LESS "some string") - assert(NOT 7 GREATER "some string") - assert(NOT 7 EQUAL "some string") - assert(NOT 7 LESS_EQUAL "some string") - assert(NOT 7 GREATER_EQUAL "some string") - - assert(NOT SEVEN_VAR LESS STRING_VAR) - assert(NOT SEVEN_VAR GREATER STRING_VAR) - assert(NOT SEVEN_VAR EQUAL STRING_VAR) - assert(NOT SEVEN_VAR LESS_EQUAL STRING_VAR) - assert(NOT SEVEN_VAR GREATER_EQUAL STRING_VAR) - endsection() - - section("it should fail to assert number equality conditions") - assert_call(assert 7 LESS "some string" - EXPECT_FATAL_ERROR STREQUAL "expected number:\n 7\n" - "to be less than:\n some string") - - assert_call(assert 7 GREATER "some string" - EXPECT_FATAL_ERROR STREQUAL "expected number:\n 7\n" - "to be greater than:\n some string") - - assert_call(assert 7 EQUAL "some string" - EXPECT_FATAL_ERROR STREQUAL "expected number:\n 7\n" - "to be equal to:\n some string") - - assert_call(assert 7 LESS_EQUAL "some string" - EXPECT_FATAL_ERROR STREQUAL "expected number:\n 7\n" - "to be less than or equal to:\n some string") - - assert_call(assert 7 GREATER_EQUAL "some string" - EXPECT_FATAL_ERROR STREQUAL "expected number:\n 7\n" - "to be greater than or equal to:\n some string") - endsection() - endsection() -endsection() - -section("string equality condition assertions") - set(STRING_VAR "some string") - set(OTHER_STRING_VAR "some other string") - - section("given equal strings") - section("it should assert string equality conditions") - assert(NOT "some string" STRLESS "some string") - assert(NOT "some string" STRGREATER "some string") - assert("some string" STREQUAL "some string") - assert("some string" STRLESS_EQUAL "some string") - assert("some string" STRGREATER_EQUAL "some string") - - assert(NOT STRING_VAR STRLESS STRING_VAR) - assert(NOT STRING_VAR STRGREATER STRING_VAR) - assert(STRING_VAR STREQUAL STRING_VAR) - assert(STRING_VAR STRLESS_EQUAL STRING_VAR) - assert(STRING_VAR STRGREATER_EQUAL STRING_VAR) - endsection() - - section("it should fail to assert string equality conditions") - assert_call(assert "some string" STRLESS "some string" - EXPECT_FATAL_ERROR STREQUAL "expected string:\n some string\n" - "to be less than:\n some string") - - assert_call(assert "some string" STRGREATER "some string" - EXPECT_FATAL_ERROR STREQUAL "expected string:\n some string\n" - "to be greater than:\n some string") - - assert_call(assert NOT "some string" STREQUAL "some string" - EXPECT_FATAL_ERROR STREQUAL "expected string:\n some string\n" - "not to be equal to:\n some string") - - assert_call(assert NOT "some string" STRLESS_EQUAL "some string" - EXPECT_FATAL_ERROR STREQUAL "expected string:\n some string\n" - "not to be less than or equal to:\n some string") - - assert_call(assert NOT "some string" STRGREATER_EQUAL "some string" - EXPECT_FATAL_ERROR STREQUAL "expected string:\n some string\n" - "not to be greater than or equal to:\n some string") - endsection() - endsection() - - section("given a lesser string") - section("it should assert string equality conditions") - assert("some other string" STRLESS "some string") - assert(NOT "some other string" STRGREATER "some string") - assert(NOT "some other string" STREQUAL "some string") - assert("some other string" STRLESS_EQUAL "some string") - assert(NOT "some other string" STRGREATER_EQUAL "some string") - - assert(OTHER_STRING_VAR STRLESS STRING_VAR) - assert(NOT OTHER_STRING_VAR STRGREATER STRING_VAR) - assert(NOT OTHER_STRING_VAR STREQUAL STRING_VAR) - assert(OTHER_STRING_VAR STRLESS_EQUAL STRING_VAR) - assert(NOT OTHER_STRING_VAR STRGREATER_EQUAL STRING_VAR) - endsection() - - section("it should fail to assert string equality conditions") - assert_call(assert NOT "some other string" STRLESS "some string" - EXPECT_FATAL_ERROR STREQUAL "expected string:\n some other string\n" - "not to be less than:\n some string") - - assert_call(assert "some other string" STRGREATER "some string" - EXPECT_FATAL_ERROR STREQUAL "expected string:\n some other string\n" - "to be greater than:\n some string") - - assert_call(assert "some other string" STREQUAL "some string" - EXPECT_FATAL_ERROR STREQUAL "expected string:\n some other string\n" - "to be equal to:\n some string") - - assert_call(assert NOT "some other string" STRLESS_EQUAL "some string" - EXPECT_FATAL_ERROR STREQUAL "expected string:\n some other string\n" - "not to be less than or equal to:\n some string") - - assert_call(assert "some other string" STRGREATER_EQUAL "some string" - EXPECT_FATAL_ERROR STREQUAL "expected string:\n some other string\n" - "to be greater than or equal to:\n some string") - endsection() - endsection() - - section("given a greater string") - section("it should assert string equality conditions") - assert(NOT "some string" STRLESS "some other string") - assert("some string" STRGREATER "some other string") - assert(NOT "some string" STREQUAL "some other string") - assert(NOT "some string" STRLESS_EQUAL "some other string") - assert("some string" STRGREATER_EQUAL "some other string") - - assert(NOT STRING_VAR STRLESS OTHER_STRING_VAR) - assert(STRING_VAR STRGREATER OTHER_STRING_VAR) - assert(NOT STRING_VAR STREQUAL OTHER_STRING_VAR) - assert(NOT STRING_VAR STRLESS_EQUAL OTHER_STRING_VAR) - assert(STRING_VAR STRGREATER_EQUAL OTHER_STRING_VAR) - endsection() - - section("it should fail to assert string equality conditions") - assert_call(assert "some string" STRLESS "some other string" - EXPECT_FATAL_ERROR STREQUAL "expected string:\n some string\n" - "to be less than:\n some other string") - - assert_call(assert NOT "some string" STRGREATER "some other string" - EXPECT_FATAL_ERROR STREQUAL "expected string:\n some string\n" - "not to be greater than:\n some other string") - - assert_call(assert "some string" STREQUAL "some other string" - EXPECT_FATAL_ERROR STREQUAL "expected string:\n some string\n" - "to be equal to:\n some other string") - - assert_call(assert "some string" STRLESS_EQUAL "some other string" - EXPECT_FATAL_ERROR STREQUAL "expected string:\n some string\n" - "to be less than or equal to:\n some other string") - - assert_call(assert NOT "some string" STRGREATER_EQUAL "some other string" - EXPECT_FATAL_ERROR STREQUAL "expected string:\n some string\n" - "not to be greater than or equal to:\n some other string") - endsection() - endsection() -endsection() - -section("version equality condition assertions") - set(VERSION_VAR 1.2.3) - set(VERSIONN_VAR 1.02.3) - set(OTHER_VERSION_VAR 1.3.4) - - section("given equal versions") - section("it should assert version equality conditions") - assert(NOT 1.2.3 VERSION_LESS 1.02.3) - assert(NOT 1.2.3 VERSION_GREATER 1.02.3) - assert(1.2.3 VERSION_EQUAL 1.02.3) - assert(1.2.3 VERSION_LESS_EQUAL 1.02.3) - assert(1.2.3 VERSION_GREATER_EQUAL 1.02.3) - - assert(NOT VERSION_VAR VERSION_LESS VERSIONN_VAR) - assert(NOT VERSION_VAR VERSION_GREATER VERSIONN_VAR) - assert(VERSION_VAR VERSION_EQUAL VERSIONN_VAR) - assert(VERSION_VAR VERSION_LESS_EQUAL VERSIONN_VAR) - assert(VERSION_VAR VERSION_GREATER_EQUAL VERSIONN_VAR) - endsection() - - section("it should fail to assert version equality conditions") - assert_call(assert 1.2.3 VERSION_LESS 1.02.3 - EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.2.3\n" - "to be less than:\n 1.02.3") - - assert_call(assert 1.2.3 VERSION_GREATER 1.02.3 - EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.2.3\n" - "to be greater than:\n 1.02.3") - - assert_call(assert NOT 1.2.3 VERSION_EQUAL 1.02.3 - EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.2.3\n" - "not to be equal to:\n 1.02.3") - - assert_call(assert NOT 1.2.3 VERSION_LESS_EQUAL 1.02.3 - EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.2.3\n" - "not to be less than or equal to:\n 1.02.3") - - assert_call(assert NOT 1.2.3 VERSION_GREATER_EQUAL 1.02.3 - EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.2.3\n" - "not to be greater than or equal to:\n 1.02.3") - endsection() - endsection() - - section("given a lesser version") - section("it should assert version equality conditions") - assert(1.2.3 VERSION_LESS 1.3.4) - assert(NOT 1.2.3 VERSION_GREATER 1.3.4) - assert(NOT 1.2.3 VERSION_EQUAL 1.3.4) - assert(1.2.3 VERSION_LESS_EQUAL 1.3.4) - assert(NOT 1.2.3 VERSION_GREATER_EQUAL 1.3.4) - - assert(VERSION_VAR VERSION_LESS OTHER_VERSION_VAR) - assert(NOT VERSION_VAR VERSION_GREATER OTHER_VERSION_VAR) - assert(NOT VERSION_VAR VERSION_EQUAL OTHER_VERSION_VAR) - assert(VERSION_VAR VERSION_LESS_EQUAL OTHER_VERSION_VAR) - assert(NOT VERSION_VAR VERSION_GREATER_EQUAL OTHER_VERSION_VAR) - endsection() - - section("it should fail to assert version equality conditions") - assert_call(assert NOT 1.2.3 VERSION_LESS 1.3.4 - EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.2.3\n" - "not to be less than:\n 1.3.4") - - assert_call(assert 1.2.3 VERSION_GREATER 1.3.4 - EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.2.3\n" - "to be greater than:\n 1.3.4") - - assert_call(assert 1.2.3 VERSION_EQUAL 1.3.4 - EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.2.3\n" - "to be equal to:\n 1.3.4") - - assert_call(assert NOT 1.2.3 VERSION_LESS_EQUAL 1.3.4 - EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.2.3\n" - "not to be less than or equal to:\n 1.3.4") - - assert_call(assert 1.2.3 VERSION_GREATER_EQUAL 1.3.4 - EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.2.3\n" - "to be greater than or equal to:\n 1.3.4") - endsection() - endsection() - - section("given a greater version") - section("it should assert version equality conditions") - assert(NOT 1.3.4 VERSION_LESS 1.2.3) - assert(1.3.4 VERSION_GREATER 1.2.3) - assert(NOT 1.3.4 VERSION_EQUAL 1.2.3) - assert(NOT 1.3.4 VERSION_LESS_EQUAL 1.2.3) - assert(1.3.4 VERSION_GREATER_EQUAL 1.2.3) - - assert(NOT OTHER_VERSION_VAR VERSION_LESS VERSION_VAR) - assert(OTHER_VERSION_VAR VERSION_GREATER VERSION_VAR) - assert(NOT OTHER_VERSION_VAR VERSION_EQUAL VERSION_VAR) - assert(NOT OTHER_VERSION_VAR VERSION_LESS_EQUAL VERSION_VAR) - assert(OTHER_VERSION_VAR VERSION_GREATER_EQUAL VERSION_VAR) - endsection() - - section("it should fail to assert version equality conditions") - assert_call(assert 1.3.4 VERSION_LESS 1.2.3 - EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.3.4\n" - "to be less than:\n 1.2.3") - - assert_call(assert NOT 1.3.4 VERSION_GREATER 1.2.3 - EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.3.4\n" - "not to be greater than:\n 1.2.3") - - assert_call(assert 1.3.4 VERSION_EQUAL 1.2.3 - EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.3.4\n" - "to be equal to:\n 1.2.3") - - assert_call(assert 1.3.4 VERSION_LESS_EQUAL 1.2.3 - EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.3.4\n" - "to be less than or equal to:\n 1.2.3") - - assert_call(assert NOT 1.3.4 VERSION_GREATER_EQUAL 1.2.3 - EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.3.4\n" - "not to be greater than or equal to:\n 1.2.3") - endsection() - endsection() -endsection() - section("path equality condition assertions") section("it should assert path equality conditions") set(PATH_VAR "/some/path") diff --git a/test/test_assert_number.cmake b/test/test_assert_number.cmake new file mode 100644 index 0000000..b123362 --- /dev/null +++ b/test/test_assert_number.cmake @@ -0,0 +1,160 @@ +cmake_minimum_required(VERSION 3.24) + +include(${CMAKE_CURRENT_LIST_DIR}/../cmake/Assertion.cmake) + +set(SEVEN_VAR 7) +set(THIRTEEN_VAR 13) + +section("given equal numbers") + section("it should assert number equality conditions") + assert(NOT 7 LESS 7) + assert(NOT 7 GREATER 7) + assert(7 EQUAL 7) + assert(7 LESS_EQUAL 7) + assert(7 GREATER_EQUAL 7) + + assert(NOT SEVEN_VAR LESS SEVEN_VAR) + assert(NOT SEVEN_VAR GREATER SEVEN_VAR) + assert(SEVEN_VAR EQUAL SEVEN_VAR) + assert(SEVEN_VAR LESS_EQUAL SEVEN_VAR) + assert(SEVEN_VAR GREATER_EQUAL SEVEN_VAR) + endsection() + + section("it should fail to assert number equality conditions") + assert_call(assert 7 LESS 7 + EXPECT_FATAL_ERROR STREQUAL + "expected number:\n 7\nto be less than:\n 7") + + assert_call(assert 7 GREATER 7 + EXPECT_FATAL_ERROR STREQUAL + "expected number:\n 7\nto be greater than:\n 7") + + assert_call(assert NOT 7 EQUAL 7 + EXPECT_FATAL_ERROR STREQUAL + "expected number:\n 7\nnot to be equal to:\n 7") + + assert_call(assert NOT 7 LESS_EQUAL 7 + EXPECT_FATAL_ERROR STREQUAL "expected number:\n 7\n" + "not to be less than or equal to:\n 7") + + assert_call(assert NOT 7 GREATER_EQUAL 7 + EXPECT_FATAL_ERROR STREQUAL "expected number:\n 7\n" + "not to be greater than or equal to:\n 7") + endsection() +endsection() + +section("given a lesser number") + section("it should assert number equality conditions") + assert(7 LESS 13) + assert(NOT 7 GREATER 13) + assert(NOT 7 EQUAL 13) + assert(7 LESS_EQUAL 13) + assert(NOT 7 GREATER_EQUAL 13) + + assert(SEVEN_VAR LESS THIRTEEN_VAR) + assert(NOT SEVEN_VAR GREATER THIRTEEN_VAR) + assert(NOT SEVEN_VAR EQUAL THIRTEEN_VAR) + assert(SEVEN_VAR LESS_EQUAL THIRTEEN_VAR) + assert(NOT SEVEN_VAR GREATER_EQUAL THIRTEEN_VAR) + endsection() + + section("it should fail to assert number equality conditions") + assert_call(assert NOT 7 LESS 13 + EXPECT_FATAL_ERROR STREQUAL "expected number:\n 7\n" + "not to be less than:\n 13") + + assert_call(assert 7 GREATER 13 + EXPECT_FATAL_ERROR STREQUAL "expected number:\n 7\n" + "to be greater than:\n 13") + + assert_call(assert 7 EQUAL 13 + EXPECT_FATAL_ERROR STREQUAL "expected number:\n 7\n" + "to be equal to:\n 13") + + assert_call(assert NOT 7 LESS_EQUAL 13 + EXPECT_FATAL_ERROR STREQUAL "expected number:\n 7\n" + "not to be less than or equal to:\n 13") + + assert_call(assert 7 GREATER_EQUAL 13 + EXPECT_FATAL_ERROR STREQUAL "expected number:\n 7\n" + "to be greater than or equal to:\n 13") + endsection() +endsection() + +section("given a greater number") + section("it should assert number equality conditions") + assert(NOT 13 LESS 7) + assert(13 GREATER 7) + assert(NOT 13 EQUAL 7) + assert(NOT 13 LESS_EQUAL 7) + assert(13 GREATER_EQUAL 7) + + assert(NOT THIRTEEN_VAR LESS SEVEN_VAR) + assert(THIRTEEN_VAR GREATER SEVEN_VAR) + assert(NOT THIRTEEN_VAR EQUAL SEVEN_VAR) + assert(NOT THIRTEEN_VAR LESS_EQUAL SEVEN_VAR) + assert(THIRTEEN_VAR GREATER_EQUAL SEVEN_VAR) + endsection() + + section("it should fail to assert number equality conditions") + assert_call(assert 13 LESS 7 + EXPECT_FATAL_ERROR STREQUAL "expected number:\n 13\n" + "to be less than:\n 7") + + assert_call(assert NOT 13 GREATER 7 + EXPECT_FATAL_ERROR STREQUAL "expected number:\n 13\n" + "not to be greater than:\n 7") + + assert_call(assert 13 EQUAL 7 + EXPECT_FATAL_ERROR STREQUAL "expected number:\n 13\n" + "to be equal to:\n 7") + + assert_call(assert 13 LESS_EQUAL 7 + EXPECT_FATAL_ERROR STREQUAL "expected number:\n 13\n" + "to be less than or equal to:\n 7") + + assert_call(assert NOT 13 GREATER_EQUAL 7 + EXPECT_FATAL_ERROR STREQUAL "expected number:\n 13\n" + "not to be greater than or equal to:\n 7") + endsection() +endsection() + +section("given a non-number") + section("it should assert number equality conditions") + set(STRING_VAR "some string") + + assert(NOT 7 LESS "some string") + assert(NOT 7 GREATER "some string") + assert(NOT 7 EQUAL "some string") + assert(NOT 7 LESS_EQUAL "some string") + assert(NOT 7 GREATER_EQUAL "some string") + + assert(NOT SEVEN_VAR LESS STRING_VAR) + assert(NOT SEVEN_VAR GREATER STRING_VAR) + assert(NOT SEVEN_VAR EQUAL STRING_VAR) + assert(NOT SEVEN_VAR LESS_EQUAL STRING_VAR) + assert(NOT SEVEN_VAR GREATER_EQUAL STRING_VAR) + endsection() + + section("it should fail to assert number equality conditions") + assert_call(assert 7 LESS "some string" + EXPECT_FATAL_ERROR STREQUAL "expected number:\n 7\n" + "to be less than:\n some string") + + assert_call(assert 7 GREATER "some string" + EXPECT_FATAL_ERROR STREQUAL "expected number:\n 7\n" + "to be greater than:\n some string") + + assert_call(assert 7 EQUAL "some string" + EXPECT_FATAL_ERROR STREQUAL "expected number:\n 7\n" + "to be equal to:\n some string") + + assert_call(assert 7 LESS_EQUAL "some string" + EXPECT_FATAL_ERROR STREQUAL "expected number:\n 7\n" + "to be less than or equal to:\n some string") + + assert_call(assert 7 GREATER_EQUAL "some string" + EXPECT_FATAL_ERROR STREQUAL "expected number:\n 7\n" + "to be greater than or equal to:\n some string") + endsection() +endsection() diff --git a/test/test_assert_string.cmake b/test/test_assert_string.cmake new file mode 100644 index 0000000..b53321c --- /dev/null +++ b/test/test_assert_string.cmake @@ -0,0 +1,120 @@ +cmake_minimum_required(VERSION 3.24) + +include(${CMAKE_CURRENT_LIST_DIR}/../cmake/Assertion.cmake) + +set(STRING_VAR "some string") +set(OTHER_STRING_VAR "some other string") + +section("given equal strings") + section("it should assert string equality conditions") + assert(NOT "some string" STRLESS "some string") + assert(NOT "some string" STRGREATER "some string") + assert("some string" STREQUAL "some string") + assert("some string" STRLESS_EQUAL "some string") + assert("some string" STRGREATER_EQUAL "some string") + + assert(NOT STRING_VAR STRLESS STRING_VAR) + assert(NOT STRING_VAR STRGREATER STRING_VAR) + assert(STRING_VAR STREQUAL STRING_VAR) + assert(STRING_VAR STRLESS_EQUAL STRING_VAR) + assert(STRING_VAR STRGREATER_EQUAL STRING_VAR) + endsection() + + section("it should fail to assert string equality conditions") + assert_call(assert "some string" STRLESS "some string" + EXPECT_FATAL_ERROR STREQUAL "expected string:\n some string\n" + "to be less than:\n some string") + + assert_call(assert "some string" STRGREATER "some string" + EXPECT_FATAL_ERROR STREQUAL "expected string:\n some string\n" + "to be greater than:\n some string") + + assert_call(assert NOT "some string" STREQUAL "some string" + EXPECT_FATAL_ERROR STREQUAL "expected string:\n some string\n" + "not to be equal to:\n some string") + + assert_call(assert NOT "some string" STRLESS_EQUAL "some string" + EXPECT_FATAL_ERROR STREQUAL "expected string:\n some string\n" + "not to be less than or equal to:\n some string") + + assert_call(assert NOT "some string" STRGREATER_EQUAL "some string" + EXPECT_FATAL_ERROR STREQUAL "expected string:\n some string\n" + "not to be greater than or equal to:\n some string") + endsection() +endsection() + +section("given a lesser string") + section("it should assert string equality conditions") + assert("some other string" STRLESS "some string") + assert(NOT "some other string" STRGREATER "some string") + assert(NOT "some other string" STREQUAL "some string") + assert("some other string" STRLESS_EQUAL "some string") + assert(NOT "some other string" STRGREATER_EQUAL "some string") + + assert(OTHER_STRING_VAR STRLESS STRING_VAR) + assert(NOT OTHER_STRING_VAR STRGREATER STRING_VAR) + assert(NOT OTHER_STRING_VAR STREQUAL STRING_VAR) + assert(OTHER_STRING_VAR STRLESS_EQUAL STRING_VAR) + assert(NOT OTHER_STRING_VAR STRGREATER_EQUAL STRING_VAR) + endsection() + + section("it should fail to assert string equality conditions") + assert_call(assert NOT "some other string" STRLESS "some string" + EXPECT_FATAL_ERROR STREQUAL "expected string:\n some other string\n" + "not to be less than:\n some string") + + assert_call(assert "some other string" STRGREATER "some string" + EXPECT_FATAL_ERROR STREQUAL "expected string:\n some other string\n" + "to be greater than:\n some string") + + assert_call(assert "some other string" STREQUAL "some string" + EXPECT_FATAL_ERROR STREQUAL "expected string:\n some other string\n" + "to be equal to:\n some string") + + assert_call(assert NOT "some other string" STRLESS_EQUAL "some string" + EXPECT_FATAL_ERROR STREQUAL "expected string:\n some other string\n" + "not to be less than or equal to:\n some string") + + assert_call(assert "some other string" STRGREATER_EQUAL "some string" + EXPECT_FATAL_ERROR STREQUAL "expected string:\n some other string\n" + "to be greater than or equal to:\n some string") + endsection() +endsection() + +section("given a greater string") + section("it should assert string equality conditions") + assert(NOT "some string" STRLESS "some other string") + assert("some string" STRGREATER "some other string") + assert(NOT "some string" STREQUAL "some other string") + assert(NOT "some string" STRLESS_EQUAL "some other string") + assert("some string" STRGREATER_EQUAL "some other string") + + assert(NOT STRING_VAR STRLESS OTHER_STRING_VAR) + assert(STRING_VAR STRGREATER OTHER_STRING_VAR) + assert(NOT STRING_VAR STREQUAL OTHER_STRING_VAR) + assert(NOT STRING_VAR STRLESS_EQUAL OTHER_STRING_VAR) + assert(STRING_VAR STRGREATER_EQUAL OTHER_STRING_VAR) + endsection() + + section("it should fail to assert string equality conditions") + assert_call(assert "some string" STRLESS "some other string" + EXPECT_FATAL_ERROR STREQUAL "expected string:\n some string\n" + "to be less than:\n some other string") + + assert_call(assert NOT "some string" STRGREATER "some other string" + EXPECT_FATAL_ERROR STREQUAL "expected string:\n some string\n" + "not to be greater than:\n some other string") + + assert_call(assert "some string" STREQUAL "some other string" + EXPECT_FATAL_ERROR STREQUAL "expected string:\n some string\n" + "to be equal to:\n some other string") + + assert_call(assert "some string" STRLESS_EQUAL "some other string" + EXPECT_FATAL_ERROR STREQUAL "expected string:\n some string\n" + "to be less than or equal to:\n some other string") + + assert_call(assert NOT "some string" STRGREATER_EQUAL "some other string" + EXPECT_FATAL_ERROR STREQUAL "expected string:\n some string\n" + "not to be greater than or equal to:\n some other string") + endsection() +endsection() diff --git a/test/test_assert_version.cmake b/test/test_assert_version.cmake new file mode 100644 index 0000000..e995d87 --- /dev/null +++ b/test/test_assert_version.cmake @@ -0,0 +1,121 @@ +cmake_minimum_required(VERSION 3.24) + +include(${CMAKE_CURRENT_LIST_DIR}/../cmake/Assertion.cmake) + +set(VERSION_VAR 1.2.3) +set(VERSIONN_VAR 1.02.3) +set(OTHER_VERSION_VAR 1.3.4) + +section("given equal versions") + section("it should assert version equality conditions") + assert(NOT 1.2.3 VERSION_LESS 1.02.3) + assert(NOT 1.2.3 VERSION_GREATER 1.02.3) + assert(1.2.3 VERSION_EQUAL 1.02.3) + assert(1.2.3 VERSION_LESS_EQUAL 1.02.3) + assert(1.2.3 VERSION_GREATER_EQUAL 1.02.3) + + assert(NOT VERSION_VAR VERSION_LESS VERSIONN_VAR) + assert(NOT VERSION_VAR VERSION_GREATER VERSIONN_VAR) + assert(VERSION_VAR VERSION_EQUAL VERSIONN_VAR) + assert(VERSION_VAR VERSION_LESS_EQUAL VERSIONN_VAR) + assert(VERSION_VAR VERSION_GREATER_EQUAL VERSIONN_VAR) + endsection() + + section("it should fail to assert version equality conditions") + assert_call(assert 1.2.3 VERSION_LESS 1.02.3 + EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.2.3\n" + "to be less than:\n 1.02.3") + + assert_call(assert 1.2.3 VERSION_GREATER 1.02.3 + EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.2.3\n" + "to be greater than:\n 1.02.3") + + assert_call(assert NOT 1.2.3 VERSION_EQUAL 1.02.3 + EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.2.3\n" + "not to be equal to:\n 1.02.3") + + assert_call(assert NOT 1.2.3 VERSION_LESS_EQUAL 1.02.3 + EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.2.3\n" + "not to be less than or equal to:\n 1.02.3") + + assert_call(assert NOT 1.2.3 VERSION_GREATER_EQUAL 1.02.3 + EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.2.3\n" + "not to be greater than or equal to:\n 1.02.3") + endsection() +endsection() + +section("given a lesser version") + section("it should assert version equality conditions") + assert(1.2.3 VERSION_LESS 1.3.4) + assert(NOT 1.2.3 VERSION_GREATER 1.3.4) + assert(NOT 1.2.3 VERSION_EQUAL 1.3.4) + assert(1.2.3 VERSION_LESS_EQUAL 1.3.4) + assert(NOT 1.2.3 VERSION_GREATER_EQUAL 1.3.4) + + assert(VERSION_VAR VERSION_LESS OTHER_VERSION_VAR) + assert(NOT VERSION_VAR VERSION_GREATER OTHER_VERSION_VAR) + assert(NOT VERSION_VAR VERSION_EQUAL OTHER_VERSION_VAR) + assert(VERSION_VAR VERSION_LESS_EQUAL OTHER_VERSION_VAR) + assert(NOT VERSION_VAR VERSION_GREATER_EQUAL OTHER_VERSION_VAR) + endsection() + + section("it should fail to assert version equality conditions") + assert_call(assert NOT 1.2.3 VERSION_LESS 1.3.4 + EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.2.3\n" + "not to be less than:\n 1.3.4") + + assert_call(assert 1.2.3 VERSION_GREATER 1.3.4 + EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.2.3\n" + "to be greater than:\n 1.3.4") + + assert_call(assert 1.2.3 VERSION_EQUAL 1.3.4 + EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.2.3\n" + "to be equal to:\n 1.3.4") + + assert_call(assert NOT 1.2.3 VERSION_LESS_EQUAL 1.3.4 + EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.2.3\n" + "not to be less than or equal to:\n 1.3.4") + + assert_call(assert 1.2.3 VERSION_GREATER_EQUAL 1.3.4 + EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.2.3\n" + "to be greater than or equal to:\n 1.3.4") + endsection() +endsection() + +section("given a greater version") + section("it should assert version equality conditions") + assert(NOT 1.3.4 VERSION_LESS 1.2.3) + assert(1.3.4 VERSION_GREATER 1.2.3) + assert(NOT 1.3.4 VERSION_EQUAL 1.2.3) + assert(NOT 1.3.4 VERSION_LESS_EQUAL 1.2.3) + assert(1.3.4 VERSION_GREATER_EQUAL 1.2.3) + + assert(NOT OTHER_VERSION_VAR VERSION_LESS VERSION_VAR) + assert(OTHER_VERSION_VAR VERSION_GREATER VERSION_VAR) + assert(NOT OTHER_VERSION_VAR VERSION_EQUAL VERSION_VAR) + assert(NOT OTHER_VERSION_VAR VERSION_LESS_EQUAL VERSION_VAR) + assert(OTHER_VERSION_VAR VERSION_GREATER_EQUAL VERSION_VAR) + endsection() + + section("it should fail to assert version equality conditions") + assert_call(assert 1.3.4 VERSION_LESS 1.2.3 + EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.3.4\n" + "to be less than:\n 1.2.3") + + assert_call(assert NOT 1.3.4 VERSION_GREATER 1.2.3 + EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.3.4\n" + "not to be greater than:\n 1.2.3") + + assert_call(assert 1.3.4 VERSION_EQUAL 1.2.3 + EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.3.4\n" + "to be equal to:\n 1.2.3") + + assert_call(assert 1.3.4 VERSION_LESS_EQUAL 1.2.3 + EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.3.4\n" + "to be less than or equal to:\n 1.2.3") + + assert_call(assert NOT 1.3.4 VERSION_GREATER_EQUAL 1.2.3 + EXPECT_FATAL_ERROR STREQUAL "expected version:\n 1.3.4\n" + "not to be greater than or equal to:\n 1.2.3") + endsection() +endsection()