codewars / codewars-runner-cli

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

Add ColdFusion / CFML #782

Closed gpickin closed 4 years ago

gpickin commented 4 years ago

Please complete the following information about the language:

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

We as a community have built a series of tools, supported by Ortus Solutions including the CLI CommandBox, Test framework TestBox, and much more. If you add CFML, we as a community would like to help, whether its formatting the test output, or adding questions, we would love to have CFML on CodeWars.


:+1: reaction might help.


bdw429s commented 4 years ago

Hi, lead developer of CommandBox CLI here. I created the CFML Track for Exercism.io using command line task runners for the test cases.

https://exercism.io/tracks/cfml

I'm happy to help Codewars set up something similar.

kazk commented 4 years ago

@bdw429s Thanks! I was able to get CFML mostly working based on your TestRunner and CLIRenderer.

The test output will look something like the following: image

bdw429s commented 4 years ago

That's great. Let me know if you want me to review anything or test.

gpickin commented 4 years ago

As far as CodeMirror goes, I found a a codemirror textmate setup with a textmate cfml package. https://www.npmjs.com/package/codemirror-textmate and https://github.com/textmate/coldfusion.tmbundle

To be honest, Javascript for script based CFML will probably suffice... and html if they write tags.

gpickin commented 4 years ago

SVG of a generic CF logo - https://drive.google.com/file/d/1OsCzIXdrBY4JuOcUJvyok-uaeX6sqRhB/view?usp=sharing

kazk commented 4 years ago

I'm using CommandBox 4.8.0+00059 and it seems like Lucee 5.2.9.31 is used. Is 5.2.9.31 ok? Is there a way to use 5.3?

$ box version
CommandBox 4.8.0+00059

$ ls -l ~/.CommandBox/lib
total 59588
-rw-r--r-- 1 codewarrior codewarrior   164052 Jan 23 02:14 JavaEWAH-1.1.6.jar
-rw-r--r-- 1 codewarrior codewarrior    63118 Jan 23 02:14 activation-1.1.jar
-rw-r--r-- 1 codewarrior codewarrior   319913 Jan 23 02:14 bcpg-jdk15on-1.60.jar
-rw-r--r-- 1 codewarrior codewarrior   796532 Jan 23 02:14 bcpkix-jdk15on-1.60.jar
-rw-r--r-- 1 codewarrior codewarrior  4189881 Jan 23 02:14 bcprov-jdk15on-1.60.jar
drwxr-xr-x 1 codewarrior codewarrior     4096 Jan 23 19:20 jansi
-rw-r--r-- 1 codewarrior codewarrior    61347 Jan 23 02:14 jcommander-1.47.jar
-rw-r--r-- 1 codewarrior codewarrior   703467 Jan 23 02:14 jline-3.10.0.jar
-rw-r--r-- 1 codewarrior codewarrior   279730 Jan 23 02:14 jsch-0.1.54.jar
-rw-r--r-- 1 codewarrior codewarrior    17884 Jan 23 02:14 json-smart-mini-1.0.8.jar
-rw-r--r-- 1 codewarrior codewarrior    69362 Jan 23 02:14 jzlib-1.1.1.jar
-rw-r--r-- 1 codewarrior codewarrior 38242272 Jan 23 02:14 lucee-5.2.9.31-packed.jar
-rw-r--r-- 1 codewarrior codewarrior   298641 Jan 23 02:14 luceecli.jar
-rw-r--r-- 1 codewarrior codewarrior   493838 Jan 23 02:14 mail-1.4.4.jar
-rw-r--r-- 1 codewarrior codewarrior  2740073 Jan 23 02:14 org.eclipse.jgit-5.3.0.201903130848-r.jar
-rw-r--r-- 1 codewarrior codewarrior     3769 Jan 23 02:14 ortus-jgit.jar
-rw-r--r-- 1 codewarrior codewarrior 12537996 Jan 23 02:14 runwar-3.8.1-SNAPSHOT.jar
-rw-r--r-- 1 codewarrior codewarrior       26 Jan 23 02:14 version.properties
kazk commented 4 years ago

For CodeMirror, let's use JavaScript first and see how well it works. Maybe the community can create CFML mode if it doesn't work well.

bdw429s commented 4 years ago

Hi @kazk are you asking about the Lucee version in the context of trying to start a web server or just running tasks, etc from the CLI? You can use whatever version you want for starting a server, but the Lucee version that's packaged with the CLI is pinned for compatibility. The reason the latest stable version of CommandBox uses a slightly older version of Lucee is due to a number of nasty regressions that crept into the early 5.3.x releases that prevented me from being able to safely update the CLI. That said, you can use the 4.9.0-snapshot build of CommandBox which is using Luee 5.3.4-RC (and finally as a result, works on Java 11+). As soon as Lucee 5.3.4 goes stable (which I'm hoping happens in the next month), I'll be releasing the next version of CommandBox-- which I'll be bumping to 5.0.

So the TL; DR;

https://downloads.ortussolutions.com/#/ortussolutions/commandbox/4.9.0-alpha/

kazk commented 4 years ago

@bdw429s Thanks :) The version packaged with CommandBox is used when running tasks (tests), right? And that can't be changed so we'll need CommandBox 4.9.0 alpha to use Lucee 5.3?

Do you think there's any breaking change that might affect us? If we start with CommandBox 4.8/Lucee 5.2, do you think there's any problem running the same code in CommandBox 5.0/Lucee 5.3? (I couldn't find the changelog).

If using slightly outdated version for a month or so is fine, I can update to use CommandBox 5.0/Lucee 5.3.4 later when it's stable and released.


By the way, I made a gist with TestRunner.cfc and CodewarsReporter.cfc if anyone is interested. Please let me know if you find any awkward code (this is my first CFML).

https://gist.github.com/kazk/390ff997b54679044273c84d6bab507d

Is there any difference between arrayLen(array) vs array.len()?

bdw429s commented 4 years ago

@kazk

The version packaged with CommandBox is used when running tasks (tests), right?

Correct.

And that can't be changed so we'll need CommandBox 4.9.0 alpha to use Lucee 5.3?

Correct

Do you think there's any breaking change that might affect us?

I don't think so. I live on bleeding edges a lot but both Lucee and CommandBox don't break backwards compat very often. Even CommandBox 5.0, which is a major version bump should be backwards compat.

If we start with CommandBox 4.8/Lucee 5.2, do you think there's any problem running the same code in CommandBox 5.0/Lucee 5.3?

No I don't. I would expect them to work the same.

(I couldn't find the changelog).

CommandBox change logs are found on the Ortus blog and in our JIRA release notes. Lucee changs logs are found on the dev.lucee.org forum for each minor release. Ex: https://dev.lucee.org/t/announcing-lucee-5-3-1-87-rc/4749

If using slightly outdated version for a month or so is fine, I can update to use CommandBox 5.0/Lucee 5.3.4 later when it's stable and released.

That's a perfectly acceptable plan if you're a little uncomfortable with the bleeding edge.

By the way, I made a gist with TestRunner.cfc and CodewarsReporter.cfc if anyone is interested. Please let me know if you find any awkward code (this is my first CFML).

These look great, you're a natural :) The only change I'd suggest right off was you may want to use reFindNoCase() if you don't want this check to be case sensitive: https://gist.github.com/kazk/390ff997b54679044273c84d6bab507d#file-testrunner-cfc-L20

Is there any difference between arrayLen(array) vs array.len()?

No. CFML has a collection of "headless" built in functions, often times starting with the name of the data type they apply to such as arrayLen(), arrayFirst(), arrayEach() and also a set of "member" functions which do (roughly) the same thing but live on the actual objects such as arr.len(), arr.first(), and arr.each(). More here: https://cfdocs.org/member The only time you'll get bit with member functions is if your array came from a Library as is a Java ArrayList but not a CFML "proper" array or if you try to use a string member function on a variable that's actually a Boolean or Double, but those are sort of edge cases.

kazk commented 4 years ago

Thanks for all the information. I decided to go with CommandBox 4.8/Lucee 5.2 for now.

I tried CommandBox 4.9.0/Lucee 5.3.4-RC and everything worked, but it seems to take few seconds longer for some reason :/

gpickin commented 4 years ago

@kazk - Awesome work, thank you so much for this. We really appreciate the time, we'll get to work on converting Kata's over so CFML asap so people can start using it.

During our weekly podcast we're going to discuss a monthly coding challenge with a prize, so hopefully we'll get people signed up and using this very soon.

I live streamed today doing some Javascript Katas, I'll do the same with CFML ones. Thanks again.

kazk commented 4 years ago

I just deployed to production :rocket: @bdw429s @gpickin thanks for your help.

Have fun and let me know if you run into any issues. It's little slow, but that's common for JVM languages and I'm not sure if there's a way to make it faster. The code is executed in ephemeral container using box task run TestRunner. I might need to increase the maximum allowed time if it timeouts often. Also, we might want to use Run Listeners instead of outputting after the test completes so that the user gets partial results even if it timeouts.

Feel free to open new issues to discuss any enhancemnts.

bdw429s commented 4 years ago

Awesome! The spool up time is defo something we would like to improve, but most of the overhead is spinning up the CF engine. Since CFML was originally a web language, nobody noticed a few seconds back in the day when starting an entire servlet container.

FWIW, I've had people report that Java 8 oddly sometimes starts up faster than Java 11+ Feel free to test around on that. Also, make sure CommandBox has been 'warmed up' and started at least once on the container. Windows Defender can wreak slowness on JVM stuff, but I assume you're dealing with Linux here so it shouldn't be an issue.

Generally speaking when just using CommandBox locally on your PC, you can run box which starts up an interactive shell that keeps box running, then you can fire off commands and they are instant since the JVM never stops. It's on my list to try and have some sort of box daemon in the background like Gradle does. There may be a way you can leave box running and just pipe to the standard input but it may be tricky to tell when the task has finished. Just ideas.

kazk commented 4 years ago

FWIW, I've had people report that Java 8 oddly sometimes starts up faster than Java 11+ Feel free to test around on that.

That's probably why it took few seconds longer when I tried CommandBox 4.9.0. I'm using the version with JRE included. I'll try 4.9.0 with Java 8 later.

Also, make sure CommandBox has been 'warmed up' and started at least once on the container.

box task run TestRunner is the only command that's executed in a container (there's box version to initialize $HOME/.CommandBox and box install during the image build.) This is because we execute each submission in a separate ephemeral container that's created on demand. In the future, I'd like to integrate CRIU so we can start containers with the warmed up state.

Generally speaking when just using CommandBox locally on your PC, you can run box which starts up an interactive shell that keeps box running, then you can fire off commands and they are instant since the JVM never stops. It's on my list to try and have some sort of box daemon in the background like Gradle does.

Yeah, that makes sense. Running a single task in a fresh workspace is unusual use case. We had major performance issues when we tried to use Gradle to run tests for some of the JVM languages. We're now only using Gradle to manage dependencies and using the compilers directly to avoid its overhead. I was going to ask you if it's possible to do something similar, but I guess similarly bypassing box doesn't help for CFML if most of the overhead comes from spinning up the CF engine.