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

Fix test event listener for nested and unlabeled tests #2

Merged
merged 2 commits into from
Feb 16, 2022

Conversation

hobovsky
Copy link
Contributor

@hobovsky hobovsky commented Feb 15, 2022

Fixes #1 .

Supports:

  • Nested tests.
  • Tests without labels.

Example kumite: https://www.codewars.com/kumite/620a7361d746e5000f36a021/

Test output:

<IT::>Top level test case

<FAILED::>not equal

<COMPLETEDIN::>

<DESCRIBE::>Test Odd

<IT::>Should return false for 1

<PASSED::>Test passed

<COMPLETEDIN::>

<IT::>Should return false for 7

<PASSED::>Test passed

<COMPLETEDIN::>

<COMPLETEDIN::>

<DESCRIBE::>Test even

<IT::>Should return true for 100

<PASSED::>Test passed

<COMPLETEDIN::>

<IT::>Should return true for 42

<PASSED::>Test passed

<COMPLETEDIN::>

<COMPLETEDIN::>

<DESCRIBE::>Test edge cases

<DESCRIBE::>Test zero

<IT::>Should return true for 0

<PASSED::>Test passed

<COMPLETEDIN::>

<COMPLETEDIN::>

<DESCRIBE::>Test -1

<IT::>Should return false for -1

<PASSED::>Test passed

<COMPLETEDIN::>

<COMPLETEDIN::>

<COMPLETEDIN::>

<DESCRIBE::>Unlabeled tests

<IT::>

<FAILED::>Incorrect answer for n=100<:LF:>not equal

<COMPLETEDIN::>

<IT::>

<FAILED::>Incorrect answer for n=100<:LF:>not equal

<COMPLETEDIN::>

<DESCRIBE::>

<IT::>

<FAILED::>Incorrect answer for n=100<:LF:>not equal

<COMPLETEDIN::>

<IT::>

<FAILED::>Incorrect answer for n=100<:LF:>not equal

<COMPLETEDIN::>

<COMPLETEDIN::>

<COMPLETEDIN::>

Current output panel:

image

Output panel with updated listener:

image

@@ -3,24 +3,51 @@ open OUnit
let _esc_lf s =
s |> Str.global_replace (Str.regexp_string "\n") "<:LF:>";;

(* TODO Fix missing `<COMPLETEDIN::>` *)
let cw_print_success = function
| _ -> print_endline ("\n<PASSED::>Test passed")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function should only be used when there is a pattern-matching for the last argument. This function (and many other functions) should be written as

let cw_print_success () = print_endline "\n<PASSED::>Test passed"

Unnecessary parentheses should also be removed.

end
| suite -> perform_test cw_print_test_event suite

and dispatch_test_case = function
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't create mutually recursive functions here (and).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are mutually recursive tho, did not get a good idea yet how to decouple them.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then everything is fine here. I missed run_tests in dispatch_test_group.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw this mutually recursive functions construct struck me as odd. I know some languages need it, but majority is fine with just some declaration and no special marker for recursive, or mutually recursive, functions.

Would you have any insight why ocaml, fsharp, maybe some other languages, need it? Is it just syntax, or is it relevant from compilers point of view, or anything else?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is just syntax. The only real difference is that functions without rec (or and) can shadow functions (or constants) with the same name defined earlier and call old functions in their body. Compiling non-mutual recursive functions may be a little faster also.

| suite -> perform_test cw_print_test_event suite

and dispatch_test_case = function
| label, test_case -> begin
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of pairs (label, test_case) it is better to use separate arguments:

let dispatch_test_case label test_case =

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, randomly spraying parentheses and semicolons is my way of dealing with syntax errors and type mismatches.

I am noob.

@monadius
Copy link
Collaborator

Can I edit this PR somehow? Everything works fine but some small changes are required to make the code cleaner.

@hobovsky
Copy link
Contributor Author

Can I edit this PR somehow? Everything works fine but some small changes are required to make the code cleaner.

You can even steal the code to your repo.
Maybe I could make you contributor or something, just don't know how.

@hobovsky
Copy link
Contributor Author

Can I edit this PR somehow? Everything works fine but some small changes are required to make the code cleaner.

I made you a collaborator in my repo, but I dont know if it helps anything :)

@monadius
Copy link
Collaborator

I will push my changes to your repository. Then you will be able to update this PR.

@kazk
Copy link
Member

kazk commented Feb 15, 2022

@monadius I gave you Write permission, so you should be able to push to this PR. Maintainers of upstream project can write to PRs unless the author opted out if I remember correctly.

@monadius
Copy link
Collaborator

I successfully pushed my changes to this PR.

@kazk kazk changed the title Test event listener for nested and unlabeled tests Fix test event listener for nested and unlabeled tests Feb 16, 2022
@kazk kazk merged commit 44923fb into codewars:main Feb 16, 2022
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.

Test output is missing <COMPLETEDIN::>
3 participants