소스 검색

tests: Improve naming of tests

Ole 10 년 전
부모
커밋
2e8104c703
4개의 변경된 파일108개의 추가작업 그리고 131개의 파일을 삭제
  1. 59 75
      tests/functions.cpp
  2. 2 4
      tests/stack.cpp
  3. 21 15
      tests/types.cpp
  4. 26 37
      tests/usertypes.cpp

+ 59 - 75
tests/functions.cpp

@@ -9,102 +9,86 @@ void test_function_noret_noparams() {
 	noret_environment++;
 }
 
-TEST_CASE("wrap_function_noret_noparams") {
-	lua_State* state = luaL_newstate();
-
-	// Setup environment
-	noret_environment = 1337;
-
-	// Wrap function
-	// lua_CFunction cfun = luwra::wrap_function<void(), test_function_noret_noparams>;
-	lua_CFunction cfun = LUWRA_WRAP_FUNCTION(test_function_noret_noparams);
-	REQUIRE(cfun != nullptr);
-
-	// Register function
-	luwra::setGlobal(state, "test_function_noret_noparams", cfun);
-
-	// Invoke function
-	REQUIRE(luaL_dostring(state, "test_function_noret_noparams()") == 0);
-	REQUIRE(lua_gettop(state) == 0);
-	REQUIRE(noret_environment == 1338);
-
-	lua_close(state);
-}
-
 static
 void test_function_noret(int a, int b) {
 	noret_environment = a + b;
 }
 
-TEST_CASE("wrap_function_noret") {
-	lua_State* state = luaL_newstate();
-
-	// Test function beforehand
-	test_function_noret(13, 37);
-	int req_environemt = noret_environment;
+static
+int test_function_noparams() {
+	return 13 * 37;
+}
 
-	// Wrap function
-	// lua_CFunction cfun = luwra::wrap_function<void(int, int), test_function_noret>;
-	lua_CFunction cfun = LUWRA_WRAP_FUNCTION(test_function_noret);
-	REQUIRE(cfun != nullptr);
+static
+int test_function(int a, int b) {
+	return (a + b) * (a - b);
+}
 
-	// Register function
-	luwra::setGlobal(state, "test_function_noret", cfun);
+TEST_CASE("FunctionWrapper") {
+	luwra::StateWrapper state;
 
-	// Invoke function
-	REQUIRE(luaL_dostring(state, "test_function_noret(13, 37)") == 0);
-	REQUIRE(lua_gettop(state) == 0);
-	REQUIRE(noret_environment == req_environemt);
+	SECTION("without return value, without parameters") {
+		// Setup environment
+		noret_environment = 1337;
 
-	lua_close(state);
-}
+		// Wrap function
+		lua_CFunction cfun = LUWRA_WRAP_FUNCTION(test_function_noret_noparams);
+		REQUIRE(cfun != nullptr);
 
-static
-int test_function_noparams() {
-	return 13 * 37;
-}
+		// Register function
+		luwra::setGlobal(state, "test_function_noret_noparams", cfun);
 
-TEST_CASE("wrap_function_noparams") {
-	lua_State* state = luaL_newstate();
+		// Invoke function
+		REQUIRE(luaL_dostring(state, "test_function_noret_noparams()") == 0);
+		REQUIRE(lua_gettop(state) == 0);
+		REQUIRE(noret_environment == 1338);
+	}
 
-	// Wrap function
-	// lua_CFunction cfun = luwra::wrap_function<int(), test_function_noparams>;
-	lua_CFunction cfun = LUWRA_WRAP_FUNCTION(test_function_noparams);
-	REQUIRE(cfun != nullptr);
+	SECTION("without return value, with parameters") {
+		// Test function beforehand
+		test_function_noret(13, 37);
+		int req_environemt = noret_environment;
 
-	// Register function
-	luwra::setGlobal(state, "test_function_noparams", cfun);
+		// Wrap function
+		lua_CFunction cfun = LUWRA_WRAP_FUNCTION(test_function_noret);
+		REQUIRE(cfun != nullptr);
 
-	// Invoke function
-	REQUIRE(luaL_dostring(state, "return test_function_noparams()") == 0);
-	REQUIRE(lua_gettop(state) == 1);
-	REQUIRE(luwra::Value<int>::read(state, -1) == test_function_noparams());
+		// Register function
+		luwra::setGlobal(state, "test_function_noret", cfun);
 
-	lua_close(state);
-}
+		// Invoke function
+		REQUIRE(luaL_dostring(state, "test_function_noret(13, 37)") == 0);
+		REQUIRE(lua_gettop(state) == 0);
+		REQUIRE(noret_environment == req_environemt);
+	}
 
-static
-int test_function(int a, int b) {
-	return (a + b) * (a - b);
-}
+	SECTION("with return value, without parameters") {
+		// Wrap function
+		lua_CFunction cfun = LUWRA_WRAP_FUNCTION(test_function_noparams);
+		REQUIRE(cfun != nullptr);
 
-TEST_CASE("wrap_function") {
-	lua_State* state = luaL_newstate();
+		// Register function
+		luwra::setGlobal(state, "test_function_noparams", cfun);
 
-	// Wrap function
-	// lua_CFunction cfun = luwra::wrap_function<int(int, int), test_function>;
-	lua_CFunction cfun = LUWRA_WRAP_FUNCTION(test_function);
-	REQUIRE(cfun != nullptr);
+		// Invoke function
+		REQUIRE(luaL_dostring(state, "return test_function_noparams()") == 0);
+		REQUIRE(lua_gettop(state) == 1);
+		REQUIRE(luwra::Value<int>::read(state, -1) == test_function_noparams());
+	}
 
-	// Register function
-	luwra::setGlobal(state, "test_function", cfun);
+	SECTION("with return value, with parameters") {
+		// Wrap function
+		lua_CFunction cfun = LUWRA_WRAP_FUNCTION(test_function);
+		REQUIRE(cfun != nullptr);
 
-	// Invoke function
-	REQUIRE(luaL_dostring(state, "return test_function(37, 13)") == 0);
-	REQUIRE(lua_gettop(state) == 1);
-	REQUIRE(luwra::Value<int>::read(state, -1) == test_function(37, 13));
+		// Register function
+		luwra::setGlobal(state, "test_function", cfun);
 
-	lua_close(state);
+		// Invoke function
+		REQUIRE(luaL_dostring(state, "return test_function(37, 13)") == 0);
+		REQUIRE(lua_gettop(state) == 1);
+		REQUIRE(luwra::Value<int>::read(state, -1) == test_function(37, 13));
+	}
 }
 
 TEST_CASE("NativeFunction") {

+ 2 - 4
tests/stack.cpp

@@ -16,8 +16,8 @@ void test_function_3(int) {
 
 }
 
-TEST_CASE("stack_interaction") {
-	lua_State* state = luaL_newstate();
+TEST_CASE("StackInteraction") {
+	luwra::StateWrapper state;
 
 	luwra::push(state, 1);
 	luwra::push(state, 2);
@@ -36,6 +36,4 @@ TEST_CASE("stack_interaction") {
 	REQUIRE(luwra::apply(state, -2, test_function_1) == -2);
 	REQUIRE(luwra::apply(state, -3, test_function_1) == -1);
 	REQUIRE(luwra::apply(state, -3, test_function_2) == 9);
-
-	lua_close(state);
 }

+ 21 - 15
tests/types.cpp

@@ -6,6 +6,8 @@
 #include <utility>
 #include <type_traits>
 
+#if LUA_VERSION_NUM >= 503
+
 template <typename I>
 struct NumericTest {
 	static
@@ -41,8 +43,8 @@ using SelectNumericTest =
 		TautologyTest
 	>::type;
 
-TEST_CASE("numeric") {
-	lua_State* state = luaL_newstate();
+TEST_CASE("NumberLimits") {
+	luwra::StateWrapper state;
 
 	// Integer-based types
 	SelectNumericTest<lua_Integer, signed char>::test(state);
@@ -60,12 +62,22 @@ TEST_CASE("numeric") {
 	SelectNumericTest<lua_Number, float>::test(state);
 	SelectNumericTest<lua_Number, double>::test(state);
 	SelectNumericTest<lua_Number, long double>::test(state);
+}
+
+#endif /* LUA_VERSION_NUM >= 503 */
+
+TEST_CASE("Numbers") {
+	luwra::StateWrapper state;
 
-	lua_close(state);
+	REQUIRE(luwra::push(state, 1337) == 1);
+	REQUIRE(luwra::push(state, 13.37) == 1);
+
+	REQUIRE(luwra::read<int>(state, -2) == 1337);
+	REQUIRE(luwra::read<float>(state, -1) == 13.37f);
 }
 
-TEST_CASE("string") {
-	lua_State* state = luaL_newstate();
+TEST_CASE("Strings") {
+	luwra::StateWrapper state;
 
 	const char* test_cstr = "Luwra Test String";
 	std::string test_str(test_cstr);
@@ -99,12 +111,10 @@ TEST_CASE("string") {
 	REQUIRE(test_str == l_str1);
 	REQUIRE(test_str == l_str2);
 	REQUIRE(l_str1   == l_str2);
-
-	lua_close(state);
 }
 
-TEST_CASE("tuples") {
-	lua_State* state = luaL_newstate();
+TEST_CASE("Tuples") {
+	luwra::StateWrapper state;
 
 	int a = 13;
 	std::string b("Hello");
@@ -117,17 +127,13 @@ TEST_CASE("tuples") {
 	// Push nested tuple
 	auto tuple_nested = std::make_tuple(a, b, c, tuple);
 	REQUIRE(luwra::push(state, tuple_nested) == 6);
-
-	lua_close(state);
 }
 
-TEST_CASE("boolean") {
-	lua_State* state = luaL_newstate();
+TEST_CASE("Boolean") {
+	luwra::StateWrapper state;
 
 	bool value = true;
 
 	REQUIRE(luwra::push(state, value) == 1);
 	REQUIRE(luwra::read<bool>(state, -1) == value);
-
-	lua_close(state);
 }

+ 26 - 37
tests/usertypes.cpp

@@ -9,40 +9,33 @@ struct A {
 	A(int x = 1338): a(x) {}
 };
 
-TEST_CASE("usertypes_registration") {
-	lua_State* state = luaL_newstate();
-
-	// Registration
+TEST_CASE("UserTypes") {
+	luwra::StateWrapper state;
 	luwra::registerUserType<A>(state);
 
-	// Reference
-	A* instance = new A;
-	luwra::Value<A*>::push(state, instance);
-
-	// Type checks
-	REQUIRE(luwra::internal::check_user_type<A>(state, -1) == instance);
-	REQUIRE(luwra::Value<A*>::read(state, -1) == instance);
+	SECTION("registration") {
+		// Reference
+		A* instance = new A;
+		luwra::Value<A*>::push(state, instance);
 
-	lua_close(state);
-	delete instance;
-}
+		// Type checks
+		REQUIRE(luwra::internal::check_user_type<A>(state, -1) == instance);
+		REQUIRE(luwra::Value<A*>::read(state, -1) == instance);
 
-TEST_CASE("usertypes_ctor") {
-	lua_State* state = luaL_newstate();
-
-	// Registration
-	luwra::registerUserType<A>(state);
-	luwra::setGlobal(state, "A", LUWRA_WRAP_CONSTRUCTOR(A, int));
+		delete instance;
+	}
 
-	// Construction
-	REQUIRE(luaL_dostring(state, "return A(73)") == 0);
+	SECTION("constructor") {
+		luwra::setGlobal(state, "A", LUWRA_WRAP_CONSTRUCTOR(A, int));
 
-	// Check
-	A* instance = luwra::read<A*>(state, -1);
-	REQUIRE(instance != nullptr);
-	REQUIRE(instance->a == 73);
+		// Construction
+		REQUIRE(luaL_dostring(state, "return A(73)") == 0);
 
-	lua_close(state);
+		// Check
+		A* instance = luwra::read<A*>(state, -1);
+		REQUIRE(instance != nullptr);
+		REQUIRE(instance->a == 73);
+	}
 }
 
 struct B {
@@ -59,8 +52,8 @@ struct B {
 	{}
 };
 
-TEST_CASE("usertypes_wrap_fields") {
-	lua_State* state = luaL_newstate();
+TEST_CASE("UserTypeFields") {
+	luwra::StateWrapper state;
 
 	// Registration
 	luwra::registerUserType<B>(
@@ -108,8 +101,6 @@ TEST_CASE("usertypes_wrap_fields") {
 	// 'const volatile'-qualified set
 	REQUIRE(luaL_dostring(state, "val:cvn(42)") == 0);
 	REQUIRE(value.cvn == 1338);
-
-	lua_close(state);
 }
 
 struct C {
@@ -136,8 +127,8 @@ struct C {
 	}
 };
 
-TEST_CASE("usertypes_wrap_methods") {
-	lua_State* state = luaL_newstate();
+TEST_CASE("UserTypeMethods") {
+	luwra::StateWrapper state;
 
 	// Registration
 	luwra::registerUserType<C>(
@@ -173,11 +164,9 @@ TEST_CASE("usertypes_wrap_methods") {
 	REQUIRE(luaL_dostring(state, "return value:foo4(334)") == 0);
 	REQUIRE(value.prop == 1000);
 	REQUIRE(luwra::read<int>(state, -1) == 666);
-
-	lua_close(state);
 }
 
-TEST_CASE("usertypes_gchook_tref") {
+TEST_CASE("UserTypeGarbageCollectionRef") {
 	lua_State* state = luaL_newstate();
 
 	// Registration
@@ -196,7 +185,7 @@ TEST_CASE("usertypes_gchook_tref") {
 	REQUIRE(shared_var.use_count() == 1);
 }
 
-TEST_CASE("usertypes_gchook_tptr") {
+TEST_CASE("UserTypeGarbageCollectionPtr") {
 	lua_State* state = luaL_newstate();
 
 	// Registration