Constants

Constants
  • _TEST_PROFILER_ENABLED = SOURCEMOD_V_MAJOR >= 1 && SOURCEMOD_V_MINOR >= 10

  • _TEST_FUNCTION_WORKAROUND = SOURCEMOD_V_MAJOR >= 1 && SOURCEMOD_V_MINOR >= 11

  • TEST_PASS_SYMBOL = "✓"

  • TEST_FAIL_SYMBOL = "✗"

Methods

Test_SetBoxWidth

Sets the width of the box rendered for sections.

Arguments
  • width int

  • Width of box.

Signature

1void Test_SetBoxWidth(int width)

Test_MBStrlen

Calculates the visible length of a string, taking into account multibyte Unicode symbols.

Arguments
  • str const char[]

  • String to check.

Returns
    • int

    Signature

    1int Test_MBStrlen(const char[] str)
    

    Test_Print

    Fits the message to a box and outputs to server.

    Arguments
    • message const char[]

    • Message to output.

    • any

    • Further arguments to pass to message formatter.

    Signature

    1void Test_Print(const char[] message, any ...)
    

    Test_PrintCentered

    Aligns the message to the center of the box and outputs to server.

    Arguments
    • message const char[]

    • Message to output.

    • any… “

    Signature

    1void Test_PrintCentered(const char[] message,  any...)
    

    Test_PrintSeparator

    Prints a box-width separator.

    Arguments
    • separator int

    • Separator to use. default: '-'

    Signature

    1void Test_PrintSeparator(int separator = '-')
    

    Test_StartSection

    Resets the test counters to 0 and outputs the section name to the server. If profiling is enabled, starts the profiler.

    Arguments
    • name const char[]

    • Name of section.

    Signature

    1void Test_StartSection(const char[] name)
    

    Test_EndSection

    Outputs the amount of tests passed and failed to the server. If profiling is enabled, stops the profiler and outputs the time taken.

    Signature

    1void Test_EndSection()
    

    Test_BeforeRun

    Prepares the assert counts and prints the test name to server.

    Arguments
    • name const char[]

    • Name of test.

    Signature

    1void Test_BeforeRun(const char[] name)
    

    Test_AfterRun

    Calculates and outputs the test result to server.

    Returns
    • bool

    Signature

    1bool Test_AfterRun()
    

    Test_Run

    Performs pre-test operations, executes the test then performs post-test operations.

    Arguments
    • name const char[]

    • Name of test.

    • method Test_Method

    • Method to execute.

    Returns
      • bool

      Signature

      1bool Test_Run(const char[] name, Test_Method method)
      

      Test_RunUnsafe

      Works the same as Test_Run but accepts a less strictly typed method, which SM1.11 seems to require when using GetFunctionByName.

      Arguments
      • name const char[]

      • Name of test.

      • method Function

      • Method to execute.

      Returns
        • bool

        Signature

        1bool Test_RunUnsafe(const char[] name, Function method)
        

        Test_RunFromString

        Resolves the function based on the provided name and executes Test_Run.

        Arguments
        • name const char[]

        • Name of test to run.

        Returns
          • bool

          Signature

          1bool Test_RunFromString(const char[] name)
          

          Test_IsPassing

          Determines whether or not the currently running test is passing.

          Returns
          • bool

          Signature

          1bool Test_IsPassing()
          

          Test_Output

          Outputs the message to server.

          Arguments
          • message const char[]

          • Message to output.

          • any

          • Further arguments to pass to message formatter.

          Signature

          1void Test_Output(const char[] message, any ...)
          

          Test_OutputAssertResult

          Adds to the assert counters and outputs the assertion result to server.

          Arguments
          • result bool

          • message const char[]

          • Message to output.

          • any

          • Further arguments to pass to message formatter.

          Returns
            • bool

            Signature

            1bool Test_OutputAssertResult(bool result, const char[] message, any ...)
            

            Test_Assert

            Asserts that the value is truthy.

            Arguments
            • name const char[]

            • Name to output in assertion result.

            • value any

            • Value to compare.

            Returns
              • bool

              Signature

              1bool Test_Assert(const char[] name, any value)
              

              Test_AssertTrue

              Asserts that the value is true.

              Arguments
              • name const char[]

              • Name to output in assertion result.

              • value any

              • Value to compare.

              Returns
                • bool

                Signature

                1bool Test_AssertTrue(const char[] name, any value)
                

                Test_AssertFalse

                Asserts that the value is false.

                Arguments
                • name const char[]

                • Name to output in assertion result.

                • value any

                • Value to compare.

                Returns
                  • bool

                  Signature

                  1bool Test_AssertFalse(const char[] name, any value)
                  

                  Test_AssertNull

                  Asserts that the value is null.

                  Arguments
                  • name const char[]

                  • Name to output in assertion result.

                  • value Handle

                  • Value to compare.

                  Returns
                    • bool

                    Signature

                    1bool Test_AssertNull(const char[] name, Handle value)
                    

                    Test_AssertNotNull

                    Asserts that the value is not null.

                    Arguments
                    • name const char[]

                    • Name to output in assertion result.

                    • value Handle

                    • Value to compare.

                    Returns
                      • bool

                      Signature

                      1bool Test_AssertNotNull(const char[] name, Handle value)
                      

                      Test_AssertEqual

                      Asserts that two values are equal.

                      Arguments
                      • name const char[]

                      • Name to output in assertion result.

                      • expected any

                      • First value to compare.

                      • actual any

                      • Second value to compare.

                      Returns
                        • bool

                        Signature

                        1bool Test_AssertEqual(const char[] name, any expected, any actual)
                        

                        Test_AssertNotEqual

                        Asserts that two values are not equal.

                        Arguments
                        • name const char[]

                        • Name to output in assertion result.

                        • expected any

                        • First value to compare.

                        • actual any

                        • Second value to compare.

                        Returns
                          • bool

                          Signature

                          1bool Test_AssertNotEqual(const char[] name, any expected, any actual)
                          

                          Test_FloatsEqual

                          Helper function to check whether two floats are “equal” within a threshold (to account for floating point errors).

                          For more information, see https://en.wikipedia.org/wiki/Floating_point_error_mitigation.

                          Arguments
                          • expected float

                          • First value to compare.

                          • actual float

                          • Second value to compare.

                          • threshold float

                          • Maximum allowed difference between floats. default: 0.0001

                          Returns
                            • bool

                            Signature

                            1bool Test_FloatsEqual(float expected, float actual, float threshold = 0.0001)
                            

                            Test_AssertFloatsEqual

                            Asserts that two floats are equal.

                            For more information, see Test_FloatsEqual.

                            Arguments
                            • name const char[]

                            • Name to output in assertion result.

                            • expected float

                            • First value to compare.

                            • actual float

                            • Second value to compare.

                            • threshold float

                            • Maximum allowed difference between floats. default: 0.0001

                            Returns
                              • bool

                              Signature

                              1bool Test_AssertFloatsEqual(const char[] name, float expected, float actual, float threshold = 0.0001)
                              

                              Test_AssertFloatsNotEqual

                              Asserts that two floats are not equal.

                              For more information, see Test_FloatsEqual.

                              Arguments
                              • name const char[]

                              • Name to output in assertion result.

                              • expected float

                              • First value to compare.

                              • actual float

                              • Second value to compare.

                              • threshold float

                              • Maximum allowed difference between floats. default: 0.0001

                              Returns
                                • bool

                                Signature

                                1bool Test_AssertFloatsNotEqual(const char[] name, float expected, float actual, float threshold = 0.0001)
                                

                                Test_AssertStringsEqual

                                Asserts that two strings are equal.

                                Arguments
                                • name const char[]

                                • Name to output in assertion result.

                                • expected const char[]

                                • First string to compare.

                                • actual const char[]

                                • Second string to compare.

                                Returns
                                  • bool

                                  Signature

                                  1bool Test_AssertStringsEqual(const char[] name, const char[] expected, const char[] actual)
                                  

                                  Test_AssertStringsNotEqual

                                  Asserts that two strings are not equal.

                                  Arguments
                                  • name const char[]

                                  • Name to output in assertion result.

                                  • expected const char[]

                                  • First string to compare.

                                  • actual const char[]

                                  • Second string to compare.

                                  Returns
                                    • bool

                                    Signature

                                    1bool Test_AssertStringsNotEqual(const char[] name, const char[] expected, const char[] actual)