Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLEO testing library #92

Merged
merged 7 commits into from
Mar 6, 2024
Merged

CLEO testing library #92

merged 7 commits into from
Mar 6, 2024

Conversation

x87
Copy link

@x87 x87 commented Mar 4, 2024

Goals:

  • Focus on important things when writing unit tests.
  • Standardize test structure.

Public API:

  • test(name: string, callback: int) -- creates new test suite (collection of unit tests)
  • it(expectation: string, callback: int) -- creates new individual test focusing on testing one thing
  • before_each(callback: int) -- registers a callback that runs before each unit test (test setup)
  • after_each(callback: int) -- registers a callback that runs after each unit test (test teardown)
  • assert_eq(val1: int, val2: int) - checks if two int values are equal, otherwise stops the test execution
  • assert_eqf(val1: int, val2: int) - same as above, but for floats
  • assert_neq(val1: int, val2: int) - checks if two int values are not equal, otherwise stops the test execution
  • assert_neqf(val1: int, val2: int) - same as above, but for floats
  • assert(val: int) - checks if value is not 0, otherwise stops the test execution
  • assert_ptr(val: int) - checks if value is a valid pointer, otherwise stops the test execution

Simple example:

{$CLEO}
test('test suite', @tests)
terminate_this_custom_script

function tests
  it('should be true', @test1)
  it('should be false', @test2)
  return true

  function test1
   assert_eq(true, true)
  end
  function test2
   assert_eq(false, false)
  end
end

@x87 x87 changed the title add testing framework CLEO testing library Mar 4, 2024
@MiranDMC
Copy link
Collaborator

MiranDMC commented Mar 4, 2024

it( looks bad, almost like if
test -> test_suite/block/group
it -> test_case

@MiranDMC
Copy link
Collaborator

MiranDMC commented Mar 4, 2024

Please port some of file access opcodes. It will show use case of before_each (and lack of after_each?) functionality. At this moment I have no idea how the file handle is meant to be passed into testcase.

@x87
Copy link
Author

x87 commented Mar 5, 2024

Please port some of file access opcodes. It will show use case of before_each (and lack of after_each?) functionality. At this moment I have no idea how the file handle is meant to be passed into testcase.

added after_each, see example in 0AC8 (allocate/free)

it( looks bad, almost like if
test -> test_suite/block/group
it -> test_case

it is pretty much an industry standard, at least in web/mobile dev. also naturally easy to read: it("should ...

test suites are also often called describe.

what C++ libraries are used for unit testing? I can look into how they name things.

@MiranDMC
Copy link
Collaborator

MiranDMC commented Mar 5, 2024

what C++ libraries are used for unit testing? I can look into how they name things.

I used google tests. Visual Studio also has some built in support.

@x87 x87 marked this pull request as ready for review March 6, 2024 02:20
@x87 x87 requested a review from MiranDMC March 6, 2024 20:30
@MiranDMC
Copy link
Collaborator

MiranDMC commented Mar 6, 2024

How does the test output looks on the screen?
In my older tests I had multiple wait 0 commands between test actions to assure in case of game crash the info (of previous step) had chance to be written in to log.

@x87
Copy link
Author

x87 commented Mar 6, 2024

image

@MiranDMC
Copy link
Collaborator

MiranDMC commented Mar 6, 2024

image

Nice. I have finally to change debug utils plugin so it prints top-down, as current order is confusing.

@x87 x87 merged commit 6a21464 into master Mar 6, 2024
@x87
Copy link
Author

x87 commented Mar 6, 2024

Nice. I have finally to change debug utils plugin so it prints top-down, as current order is confusing.

it looks fine to me, especially the fading away effect makes more sense in bottom-top direction, without shifting text back to top

@x87 x87 deleted the test-framework branch March 7, 2024 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants