Skip to content

Automatic checking of Scala examples #19

@winitzki

Description

@winitzki

Scala code examples in the book are not automatically checked for correctness. So, some of the code examples may contain errors that are difficult to spot manually.

Initially, all code examples were tested in the Scala interpreter and copy/pasted into the book. However, the book text has been edited, which made it necessary to change some of the code samples as well. The result is that some of the code samples have small errors (e.g. changing the name of a variable in one place but not in another place).

The idea is to enable automatic checking of the book's text against a separate set of files that have been run through the Scala compiler.

Steps to implement:

  1. Create an mdoc file (or a set of files) containing all Scala code samples from the book, organized in such a way that everything compiles and runs. This requires adding all the necessary import statements, perhaps putting some code into objects for encapsulation, etc.
  2. Run the files through mdoc to make sure everything compiles, and prepare output files.
  3. Create a script that extracts Scala code examples from the .tex or .lyx files in the book's source code.
  4. For each code example from the book, make sure that exactly the same code is present in one of the mdoc output files.

Note that mdoc output contains some Scala REPL output as comments. We may or may not be able to use that.

Some of the Scala code examples contain Scala REPL lines, such as

scala> 1 + 2
res0: Int = 3

It is not clear whether we can easily parse these lines and verify that the mdoc output contains the correct results. It may be necessary to skip all these lines.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions