|
| 1 | +# The Quiz tools |
| 2 | + |
| 3 | +There are two tools related to scripts: |
| 4 | + |
| 5 | +- `quiz.py`: Generates a quiz RST file from a valid "quiz directory" |
| 6 | +- `update_quiz.py`: Updates all the quiz RST files in the given directory tree. |
| 7 | + |
| 8 | +# Principle |
| 9 | + |
| 10 | +Quizzes are **templates** for standalone Ada projects with multiple variants. |
| 11 | + |
| 12 | +Given a template, it is concretizable into several projects, one per |
| 13 | +choice. Those concrete projects will be *compile-run checked* by the tooling: |
| 14 | +those that compile and run without error will be considered correct answers. |
| 15 | + |
| 16 | +There are 3 kinds of errors that can be detected |
| 17 | + |
| 18 | +1. Project does not compile |
| 19 | +2. Project does compile but raises a run-time error |
| 20 | +3. Project does compile but raises a user error (`-gnata`) |
| 21 | + |
| 22 | +NB: For the case of user errors, the `-gnata` flag will need to be provided in the |
| 23 | +associated gpr file. |
| 24 | + |
| 25 | +Warning: Infinite loops or silent failures (return code is 0) are not detected by |
| 26 | +the tooling. |
| 27 | + |
| 28 | +# Usage |
| 29 | + |
| 30 | +The quizzes are meant to be used with the `contrib/quiz.py` script. This script |
| 31 | +takes an input file as argument and turns it into a Quiz slide in the training |
| 32 | +material's ReSTRuctured text idiom. |
| 33 | + |
| 34 | +This is done by instanciating copies of the quiz project directory, one for each |
| 35 | +choice (A, B, C...), extracting the associated question, trying a compile-run of |
| 36 | +the answer's code, and marking it as an answer in case it compiled and ran |
| 37 | +correctly. |
| 38 | + |
| 39 | +The output is saved as a *golden* .rst file and put into version control, so |
| 40 | +that the CI can double check the answer (using `contrib/quiz_update.py`), and |
| 41 | +validate that the result has not changed unexpectedly. |
| 42 | + |
| 43 | +This allows for reviewers to focus on the rst result, and for maintainers to |
| 44 | +focus on the Ada code. As a result, the quiz is reviewed in its included form, |
| 45 | +which is not compilable, and the Ada code is saved as well, allowing for |
| 46 | +unambiguous reproducibility. |
| 47 | + |
| 48 | +NB: Intermediate results could also be saved for similar reasons, but this is not |
| 49 | +the case today. |
| 50 | + |
| 51 | +# Template's format |
| 52 | + |
| 53 | +## adacut format |
| 54 | + |
| 55 | +The template is based on the `adacut` generic format, used by `contrib/adacut.py`. |
| 56 | +It provides *directives* that are to be written as |
| 57 | + |
| 58 | +```ada |
| 59 | +--$ directive type [target] |
| 60 | +``` |
| 61 | + |
| 62 | +* `directive` can be any of `begin`, `end`, `line` |
| 63 | +* `type` can be any of `cut`, `question`, `answer` |
| 64 | +* `target` can be any of `code`, `comment`, `all` (optional, `all` by default) |
| 65 | + |
| 66 | +The directive indicates whether a `begin ... end` block is concerned or just the |
| 67 | +line that follows. |
| 68 | + |
| 69 | +```ada |
| 70 | +--$ begin cut |
| 71 | +Toto : Integer; |
| 72 | +Titi : Integer; |
| 73 | +--$ end cut |
| 74 | +
|
| 75 | +--$ line cut |
| 76 | +Toto : Integer; |
| 77 | +``` |
| 78 | + |
| 79 | +The `cut` type is used to describe and answer, which will be *cut* into the |
| 80 | +template for the compile-run check. |
| 81 | + |
| 82 | +First `cut` will be taken as the variant for choice A, second for choice B etc... |
| 83 | + |
| 84 | +If `question` type is used, its content is included as part of the question, as |
| 85 | +a `.. code::` rst directive. |
| 86 | +If `answer` type is used, its content is included in the **answer** slide as an |
| 87 | +explaination paragraph, below the questions. |
| 88 | + |
| 89 | +## Signifiant comments |
| 90 | + |
| 91 | +The comment that is at the start of the file is considered to be the question and |
| 92 | +is included as-is (as raw rst). |
| 93 | + |
| 94 | +If a cut **begin** with a comment, the text of the comment is used as the choice |
| 95 | +text **instead** of the code of the block. |
| 96 | + |
| 97 | +If a cut **ends** with a comment, it is included as part of the answer in a special |
| 98 | +explaination block. |
0 commit comments