codewars / codewars-runner-cli

Old CodeRunner project. See https://github.com/codewars/runner instead.
GNU Affero General Public License v3.0
400 stars 141 forks source link

Add Haxe #810

Closed Nezteb closed 4 years ago

Nezteb commented 4 years ago

Please complete the following information about the language:

The following are optional, but will help us add the language:


:+1: reaction might help.


kazk commented 4 years ago

Deployed See https://github.com/codewars/codewars.com/wiki/Language-Haxe

Nezteb commented 4 years ago

You're the best @kazk! Time to create some katas. 🙌

nadako commented 4 years ago

Looks like it tries to extract the name from a class definition in the Code (I get Failed to detect class name. error when there's no class is defined). I wonder why that is needed, because in Haxe a module can contain different kinds of named types (class, interface, abstract, typedef), also module-level static vars and functions are coming soon.

If it's just to determine the module name (a .hx file), I would suggest just hard-coding it to something like Code.hx and then add import Code; to the test cases, which will import all the definitions from the module into the namespace of the test module.

Nezteb commented 4 years ago

@kazk ^

I know nothing of Codewars' sandbox implementations as I don't believe they're open-sourced, but would that be a difficult change to make?

kazk commented 4 years ago

This is why we have the language in Beta status :)

I wonder why that is needed, because in Haxe a module can contain different kinds of named types (class, interface, abstract, typedef), also module-level static vars and functions are coming soon.

It's not needed at all. I had simply misunderstood how Haxe types and modules works.

I know nothing of Codewars' sandbox implementations as I don't believe they're open-sourced

Our code runner is just a thin wrapper around Docker API and it's really simple (the code in this repository is obsolete and haven't been used, sorry for the confusion). For Haxe, the project structure looks like the following:

.
├── src
│   └── Solution.hx        submitted solution
├── tests
│   ├── CodewarsReport.hx  utest report for Codewars (will be open sourced later)
│   ├── RunTests.hx        test entry point
│   └── SolutionTest.hx    kata tests
├── haxelib.json
└── tests.hxml

Currently, the name of the solution file and the test file are determined by looking at its contents. Changing that to always use the same module name is easy to do.

tests/RunTests.hx is currently generated (because it needs the test class name) and looks like the following:

import utest.UTest;
import utest.Runner;
import utest.ui.common.HeaderDisplayMode;

class RunTests {
  static public function main() {
    var runner = new Runner();
    runner.addCase(new SolutionTest()); // <- generated
    var report = new CodewarsReport(runner);
    report.displaySuccessResults = AlwaysShowSuccessResults;
    report.displayHeader = NeverShowHeader;
    runner.run();
  }
}

Tests are execute with haxe tests.hxml where tests.hxml is the following:

-cp src
-cp tests
-lib utest
-main RunTests
--interp

I can change the solution to always be in src/Solution.hx and the tests to be required to have a class SolutionTest and write it to tests/SolutionTest.hx.

@nadako @Nezteb Any suggestions?

kazk commented 4 years ago

What happens if the solution contains package pack; declaration. Can it still be loaded from src/Solution.hx or does it have to go to src/pack/Solution.hx? We can disallow package declaration to keep things simple if it's the latter.

kazk commented 4 years ago

If solution contains package pack;, the test fails with

tests/SolutionTest.hx:2: character 8 : `package pack;` in src/Solution.hx should be `package;`

so I think that should be clear enough.

I'll make the changes I posted above and let you guys know when it's deployed.

kazk commented 4 years ago

The change was deployed and published kata was updated. Please let me know if you find anything else that should be fixed or if you have any questions.

kazk commented 4 years ago

@Steffan153 Can you update your translations' test cases by adding import Solution; and changing the test class name to SolutionTest? I'll approve them after that.

Steffan153 commented 4 years ago

@kazk Done. Here are the unapproved translations in case you lost them: https://www.codewars.com/kumite/5eb3819706aa66001743245e?sel=5eb3819706aa66001743245e https://www.codewars.com/kumite/5eb38348f4f8e0001915794b?sel=5eb38348f4f8e0001915794b https://www.codewars.com/kumite/5eb3805afec7d10032de0844?sel=5eb3805afec7d10032de0844

markknol commented 4 years ago

I did found that the tests are are flipped. “expected B, but got A” but should be “expected A, but got B”. My input is on the left side where it should be at the other side. image

Not sure if this is the right place to put, I'm pretty new to codewars. Came here for Haxe :)

DonaldKellett commented 4 years ago

I did found that the tests are are flipped. “expected B, but got A” but should be “expected A, but got B”. My input is on the left side where it should be at the other side. image

Not sure if this is the right place to put, I'm pretty new to codewars. Came here for Haxe :)

That means that the order of the actual and expected values for the assertions in the tests are flipped, which is a Kata-specific issue and therefore should be raised in the Discourse of the affected Kata instead.

Nezteb commented 4 years ago

@markknol It looks like that particular kata test has been fixed!

https://www.codewars.com/kata/5d50e3914861a500121e1958/train/haxe

Screen Shot 2020-05-08 at 11 41 27 AM
Steffan153 commented 4 years ago

Yeah, I fixed it a while ago. You probably needed to click the Reset button.