You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 14, 2020. It is now read-only.
-Readme update
-Test Crashed message and unit test
-Test timeout message and unit test
-Replace \n with <:LF:> and unit test
-C unit test on docker build
This project is used by [Codewars](http://www.codewars.com) and [Qualified.io](https://www.qualified.io) to execute small sets of code within various languages, using various testing frameworks.
6
-
Each time code is run, it is executed within a Docker container in order to secure unsafe code execution.
6
+
Each time code is run, it is executed within a Docker container in order to secure unsafe code execution.
7
7
8
8
All execution is done within Docker, with a Node CLI app contained within each container
9
-
that manages the code execution for that specific language environment and returns the result via stdout.
9
+
that manages the code execution for that specific language environment and returns the result via stdout.
10
10
11
11
## Contributions
12
12
13
13
This project has been open-sourced so that the Codewars and Qualified communites can contribute support for new languages and
14
14
frameworks. See the [Language Support Status section](#user-content-language-support-status) for more information regarding which languages are currently supported
15
15
and where their Codewars/Qualified support has been added.
16
-
16
+
17
17
## Basic Usage
18
18
19
19
Within each Docker image, there is a copy of the Node executable and a `run` script. That script accepts multiple options
@@ -35,7 +35,7 @@ docker run --rm -it codewars/node-runner bash
35
35
docker-compose run node-runner
36
36
```
37
37
38
-
Or you could choose to execute the code outside of Docker by creating a container that will remove itself after it executes:
38
+
Or you could choose to execute the code outside of Docker by creating a container that will remove itself after it executes:
39
39
40
40
```
41
41
# direct Docker call:
@@ -50,9 +50,9 @@ docker-compose run ruby -c "puts 'I ran inside of Docker using Ruby'"
50
50
### Integrated Test Suites
51
51
The most significant aspect of this project is that integrated test support is built in to many languages. This is how
52
52
Codewars and Qualified work, instead of testing STDOUT of a program, the executed code is tested using traditional
53
-
code testing methods, with unit-tests and language-specific testing frameworks.
53
+
code testing methods, with unit-tests and language-specific testing frameworks.
54
54
55
-
Here is a very simple example of running tests using the simplified Codewars testing framework.
55
+
Here is a very simple example of running tests using the simplified Codewars testing framework.
56
56
57
57
```
58
58
# manually running docker
@@ -64,7 +64,7 @@ docker-compose run javascript -c "var a = 1;" -t cw -f "Test.assertEquals(a, 1)"
64
64
65
65
Which would output `<PASSED::>Test Passed: Value == 1` to STDOUT.
66
66
67
-
## Language Support Status
67
+
## Language Support Status
68
68
69
69
Many languages are currently supported in various states of completeness. This list tries to keep track of each.
70
70
@@ -74,7 +74,7 @@ Many languages are currently supported in various states of completeness. This l
@@ -119,7 +119,7 @@ You should have [Docker](https://www.docker.com/) installed, if not do that firs
119
119
environments you will need to build the proper Docker image. To get started lets work with the
120
120
node image.
121
121
122
-
Run `make node` to build the base and node images. This will take a few minutes. You can speed up the process by first
122
+
Run `make node` to build the base and node images. This will take a few minutes. You can speed up the process by first
123
123
downloading the existing images that you intend to work on, which will allow you to only need to build when you make a change.
124
124
125
125
For example, if you intend to work on the jvm image, you would do this:
@@ -129,7 +129,7 @@ For example, if you intend to work on the jvm image, you would do this:
129
129
docker pull codewars/base-runner
130
130
docker pull codewars/jvm-runner
131
131
132
-
# now build the jvm image, so that any recent changes that have may not have been pushed yet get added into the image
132
+
# now build the jvm image, so that any recent changes that have may not have been pushed yet get added into the image
133
133
make jvm
134
134
```
135
135
@@ -161,8 +161,8 @@ to update these you should `make {image_you_want_to_update}` the image to ensure
161
161
We mentioned before that you also have the option of using [Docker Compose](https://docs.docker.com/compose/) to run the CLI tool. We have setup the `docker-compose.yml`
162
162
file to provide very useful pre-configured services for making development easier. Instead of having to issue the long command
163
163
mentioned above, you can simply run `docker-compose run node-runner` to bash into a fresh container with your local volumes already mounted.
164
-
165
-
All of the docker compose services are setup to mount volumes to make development easier, so that is the recommended way of
164
+
165
+
All of the docker compose services are setup to mount volumes to make development easier, so that is the recommended way of
166
166
interacting with the codebase. You should note though that the compose file is unable to build images due to how
167
167
the directory structure is laid out, so you have to first `make {runner_name}` the image before you can run it. Otherwise
168
168
it will pull down the latest copy from Docker Hub.
@@ -181,7 +181,7 @@ docker-compose run typescript_test
181
181
182
182
## Test Suite Output Format
183
183
184
-
A custom and very basic format is used for sending data out of the CLI tool. All formatted data is returned via STDOUT.
184
+
A custom and very basic format is used for sending data out of the CLI tool. All formatted data is returned via STDOUT.
185
185
If you do nothing but write normal strings to STDOUT, then codewars.com will display each line as you would expect, unformatted.
186
186
187
187
A small subset of commands is supported that can be used to format output. They are:
@@ -193,8 +193,8 @@ A small subset of commands is supported that can be used to format output. They
193
193
-`<ERROR::>`
194
194
-`<COMPLETEDIN::>`
195
195
196
-
Prefixing a new line with these commands will cause that line to be formatted.
197
-
Since each new STDOUT line is considered a new piece of data, if you wish to format multiple lines as one
196
+
Prefixing a new line with these commands will cause that line to be formatted.
197
+
Since each new STDOUT line is considered a new piece of data, if you wish to format multiple lines as one
198
198
item (such as a multi line "passed" message), then you must replace all \n line feed characters with the `<:LF:>` token.
199
199
200
200
For example, in Ruby, if you wanted to write a multi-line passed message:
@@ -207,8 +207,8 @@ end
207
207
208
208
### Nested Describes
209
209
210
-
Some test frameworks support nested levels of describes. In order for our output to support multiple levels,
211
-
you must also use the `<COMPLETEDIN::>` token, which acts as a terminator for the current item. This should be used
210
+
Some test frameworks support nested levels of describes. In order for our output to support multiple levels,
211
+
you must also use the `<COMPLETEDIN::>` token, which acts as a terminator for the current item. This should be used
212
212
to terminate both `<DESCRIBE::>` and `<IT::>` statements.
213
213
214
214
The following is a full example of what the output might look like, that supports nested describes:
@@ -218,7 +218,7 @@ The following is a full example of what the output might look like, that support
218
218
<IT::>It should return a string
219
219
<PASSED::>Test Passed
220
220
<COMPLETEDIN::>23
221
-
<IT::>It should return "foo"
221
+
<IT::>It should return "foo"
222
222
This is some direct output (i.e. console.log("..."))
223
223
<FAILED::>Expected "foo" but instead got ""
224
224
<COMPLETEDIN::>10
@@ -236,21 +236,21 @@ statement, the 2nd completes the nested DESCRIBE and the 3rd completes the top l
236
236
#### <COMPLETEDIN::> Details
237
237
238
238
The value of COMPLETEDIN should be time spent executing the related statement, in milliseconds. It is not required
239
-
to support time. `<COMPLETEDIN::>` is valid on its own, and in that case it is only used to terminate the current statement.
239
+
to support time. `<COMPLETEDIN::>` is valid on its own, and in that case it is only used to terminate the current statement.
240
240
241
241
### Why the custom format?
242
242
243
-
Getting different test suites in different languages to all play together with the same format can be tricky. In many cases,
244
-
customizing the test suite output is very limited (sometimes requiring hacking). Because of this, using formats such as
245
-
XML and JSON are complicated because its not always possibly to correctly close out the data format when a program raises an exception.
243
+
Getting different test suites in different languages to all play together with the same format can be tricky. In many cases,
244
+
customizing the test suite output is very limited (sometimes requiring hacking). Because of this, using formats such as
245
+
XML and JSON are complicated because its not always possibly to correctly close out the data format when a program raises an exception.
246
246
247
247
The format choosen was originally done so that at any point in time the program could exit while still having readable data.
248
248
Other formats, such as TAP (Test Anything Protocol) could also be an option. However another requirement that we had when
249
249
designing the format was to have it be incredibly simple yet flexible, so that Codewars.com could support more than simply
250
250
outputing test results. With the current format there is nothing stopping you from outputing HTML, JS canvas code, etc in order
251
251
to create a rich and even interactive test result output.
252
-
253
-
252
+
253
+
254
254
## How to add a new language
255
255
256
256
> Note: These steps all assume you are adding a completely new language to the project. Many languages are currently in an incomplete
@@ -272,22 +272,22 @@ as a part of the test suite.
272
272
273
273
The runner script is responsible for outputing a `run` method. This method utilizes the shovel helper which will handle
274
274
all of the inter-process communication for you. The shovel config accepts strategies to determine how to handle running
275
-
the code based on the options passed in. There are currently two types of strategies.
275
+
the code based on the options passed in. There are currently two types of strategies.
276
276
277
277
-`solutionOnly`: Code is simply executed and its STDOUT returned. There is no test integration.
278
278
-`testIntegration`: Code is executed within a configurable test suite and the test output is returned via STDOUT.
279
279
280
280
Each of these strategies is passed in a `run` method which is used to ultimately execute the final command.
281
-
281
+
282
282
## TODO
283
283
284
284
### Paradigm Shift
285
285
286
-
There is currently no way of handling language/package versioning well. This is largely caused by the Node CLI tool having to be
286
+
There is currently no way of handling language/package versioning well. This is largely caused by the Node CLI tool having to be
287
287
baked in to the Docker container. A more ideal solution would involve keeping the CLI outside of Docker (or within its own sibling container)
288
288
and communicating to language specific containers. This would allow us to easily swap out container versions that have no
289
289
dependencies on the CLI codebase. This would involve having to utilize the `docker cp` command to copy
290
-
files to the docker container in order to be compiled. Upgrading to this newer paradigm is the next big phase of this project.
290
+
files to the docker container in order to be compiled. Upgrading to this newer paradigm is the next big phase of this project.
291
291
292
292
### Ability to send input parameters and return data
0 commit comments