Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
slonopotamus committed Aug 4, 2024
1 parent a755bda commit 6bee81a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
42 changes: 40 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ ifdef::env-github[]
:caution-caption: :fire:
endif::[]

CAUTION: This is pre-alpha software, not ready for production!

This project aims to provide a testing framework for Unreal Engine that does not suck.

== Goals
Expand All @@ -16,8 +14,15 @@ This project aims to provide a testing framework for Unreal Engine that does not
* Async execution support
* IDE and CI first-class support

== Dependencies

This project relies on C++20 features.
Tested against Unreal Engine 5.4.

== Usage

=== Defining tests

.Simple test
[source,cpp]
----
Expand Down Expand Up @@ -53,6 +58,39 @@ TEST_CLASS(MyFancyTestClass)
}
----

=== Assertions

All UEST assertions are done through `ASSERT_THAT(Expression, Matcher)`.
Failed assertion performs `return`, aborting further test execution.

.Available matchers
`ASSERT_THAT(Value, Is::True)`:: Tests that `Value` is `true`.
`ASSERT_THAT(Value, Is::False)`:: Tests that `Value` is `false`.
`ASSERT_THAT(Value, Is::Null)`:: Tests that `Value` is `nullptr`.
`ASSERT_THAT(Value, Is::EqualTo(Expected))`:: Tests that `Value` is equal to `Expected`.
`ASSERT_THAT(Value, Is::LessThan(OtherValue))`:: Tests that `Value` is less than `OtherValue`.
`ASSERT_THAT(Value, Is::LessThanOrEqualTo(OtherValue))` or `ASSERT_THAT(Value, Is::AtMost(OtherValue)`:: Tests that `Value` is less than or equal to `OtherValue`.
`ASSERT_THAT(Value, Is::GreaterThan(OtherValue))`:: Tests that `Value` is greater than `OtherValue`.
`ASSERT_THAT(Value, Is::GreaterThanOrEqualTo(OtherValue))` or `ASSERT_THAT(Value, Is::AtLeast(OtherValue)`:: Tests that `Value` is greater than or equal to `OtherValue`.
`ASSERT_THAT(Value, Is::Zero)`:: Shortcut for `ASSERT_THAT(Value, Is::EqualTo(0))`.
`ASSERT_THAT(Value, Is::Positive)`:: Shortcut for `ASSERT_THAT(Value, Is::GreaterThan(0))`.
`ASSERT_THAT(Value, Is::Negative)`:: Shortcut for `ASSERT_THAT(Value, Is::LessThan(0))`.
`ASSERT_THAT(Value, Is::InRange(From, To))`:: Tests that `Value` is greater than or equal to `From` and is less than or equal to `To`.

IMPORTANT: Because of the https://github.com/llvm/llvm-project/issues/73093[bug in Clang template type deduction] before 19.0, matchers with parameters (`LessThan`, `GreaterThan`, `EqualTo` and so on) require explicit template type specification: `ASSERT_THAT(0, Is::LessThan<int>(1))`.

You can also negate matchers using `ASSERT_THAT(Value, Is::Not::<assertion>)`.

Negated assertion example:
[source,cpp]
----
ASSERT_THAT(Value, Is::Not::Null);
----

#TODO: Document how to write custom matchers#

#TODO: Add `ASSERT_MULTIPLE` that allows performing multiple assertions without interrupting execution between them#

== Analysis of existing Unreal Engine solutions

As of 5.4, Unreal Engine has 4 (FOUR, that's not a typo) APIs for writing tests and all are very far from being good for various reasons.
Expand Down
1 change: 1 addition & 0 deletions Source/UEST/Public/UEST.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ namespace Is
} // namespace Not
} // namespace Is

// TODO: Provide ASSERT_THAT(Value) variant that tests that Value is true
#define ASSERT_THAT(Value, Matcher) \
do \
{ \
Expand Down

0 comments on commit 6bee81a

Please sign in to comment.