Skip to content

Commit

Permalink
Added READMEs for examples 5, 6, 7, and 8.
Browse files Browse the repository at this point in the history
  • Loading branch information
しずえ authored and kuredoro committed Oct 28, 2021
1 parent 5b880d3 commit 3824d2a
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 0 deletions.
19 changes: 19 additions & 0 deletions _examples/05_endless_loop/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Example 5. Endless loop

This example demonstrates how `scold` handles time limits.

`main.cpp` reads an integer and hangs forever.

Run the example like so:
```
$ g++ main.cpp -o loop
$ scold loop
```

The output will look like this:

![scold's output for example 5](output.png)

Things to note:
1. The tests are sorted by the time they finished and not by their ids.
2. The run-time of the tests is not equal to the time limit, because it includes the time OS needed to terminate the applications.
Binary file added _examples/05_endless_loop/output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions _examples/06_args/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Example 6. Application arguments

This example demonstrates how `scold` allows you to pass command-line arguments to the programs under testing.

`main.cpp` reads an integer and prints the sum of this integer with an integer passed as a command-line argument. If none were provided, it crashes.

Run the example like so:
```
$ g++ main.cpp -o args
$ scold args
```

The outputs for (a) no arguments, (b) argument `1`, and (c) argument `0` will look like this

![scold's output for example 6](output.png)

Things to note:
1. Because of this feature, you need to be careful, since the flags designated to `scold` should appear *before* the name of the executable.
Binary file added _examples/06_args/output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions _examples/07_js/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Example 7. Testing Node.js apps

This example demonstrates how `scold` allows you to test programs that cannot be compiled.

`index.js` parses a line it reads from the `stdin` containing two integers and prints their sum.

`inputs.txt` describes a number of tests to check that summation works.

Run the example like so:
```
$ scold node index
```

The output will be

![scold's output for example 7](output.png)

Things to note:
1. This is applicable to *any* interpreted languages and even other command-line tools. You can in the very same fashion test applications written in go, python, ruby and more.
Binary file added _examples/07_js/output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions _examples/08_bad_inputs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Example 7. Input robustness

This example demonstrates how `scold` checks that the provided `inputs.txt` is correct.

Run the example like so (note that `.` is an incorrect executable name, but validation of `inputs.txt` will be performed sooner):
```
$ scold -i inputs1.txt .
```

The output will be

![scold's output for example 8](output.png)

Things to note:
1. The error messages display the line number and the line that contains the error.
2. The error messages reference the filename and the first line of the problematic region (the `.\inputs1.txt:1:` string).
3. The error messages are capable of printing multi-line code snippets.
4. Errors are hierachical: the core error message (that goes after the last `:`) is amended with additional contextual information during the validation stage. It is in essence a Go way of reporting errors. This makes for a clean architecture inside the `scold`'s codebase, and also clearer error messages.
Binary file added _examples/08_bad_inputs/output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3824d2a

Please sign in to comment.