Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Coffeescript: Tests not executed #406

Closed
siebenschlaefer opened this issue Apr 30, 2017 · 3 comments
Closed

Coffeescript: Tests not executed #406

siebenschlaefer opened this issue Apr 30, 2017 · 3 comments

Comments

@siebenschlaefer
Copy link

I was able to solve https://www.codewars.com/kata/check-and-mate and
https://www.codewars.com/kata/5313b713bb244a0eb20001fe by just executing a successful test:

Test.expect true

A solution of just

# comment

results in Time: 311ms Passed: 0 Failed: 1 Errors: 1.

This might be because both use embedded Javascript (with `) for their tests and it looks like that code is not executed.

@DonaldKellett
Copy link
Member

DonaldKellett commented May 1, 2017

I just tested the Kata Check and Mate as a guest and confirmed that this hack works for CoffeeScript but not JavaScript.

UPDATE: I also tested this with the other (7 kyu) Kata that @siebenschlaefer linked to with the exact same results. This appears to be a CoffeeScript-specific Issue and has nothing to do with the individual Kata affected.

@kazk
Copy link
Member

kazk commented Jul 19, 2017

I think this is caused by tests written as embedded JavaScript in the form:

`
test();
`
# CoffeeScript test from "Number-like counter" kata (simplified)
`
var c = new Counter();
Test.expect(c == 0, "c == 0 was false");
`

Reproducible with

add = (a, b) -> a + b
`
Test.assertEquals(add(1, 1), 2);
`

image

add = (a, b) -> a + b
# adding
Test.expect true
# makes this pass

image

I'm guessing having no test at all is considered a failure and adding one passing test works around it.


This issue only happens when the first backtick is followed by LF.

`Test.assertEquals(add(1, 1), 2);` # ok

`Test.assertEquals(add(1, 1),
2);`                               # ok

`
Test.assertEquals(add(1, 1), 2);
`                                  # not ok
`
Test.assertEquals(add(1, 1), 2);`  # not ok

image

This is because CoffeeScript runner combines the code like the following:

Test.handleError ->
  # setup
  # solution
  do ->
    # tests

and

`
Test.assertEquals(add(1, 1), 2);`

is

return
Test.assertEquals(add(1, 1), 2);;

inside do ->.

Also, more than one statement won't work. You can work around with

`(function() {
Test.assertEquals(add(1, 1), 2);
Test.assertEquals(add(1, 2), 3);
// ...
})()`

Maybe this used to work on older version of CoffeeScript, but I don't know the language enough to tell.


By the way, is this common on Codewars? Just wrapping the original JavaScript tests with backticks to have CoffeeScript translation?

@kazk
Copy link
Member

kazk commented Aug 3, 2017

Closing this because I'm not sure how to fix this from our end and workarounds are available.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants