exercism / go-test-runner

GNU Affero General Public License v3.0
15 stars 17 forks source link

Upgrade to version 3 spec #32

Closed ErikSchierboom closed 1 year ago

ErikSchierboom commented 3 years ago

If possible, this test runner should be updated to version 3 of the test runner interface specification. In version 3, one additional feature is enabled: the ability to link individual tests to tasks. This allows the website to show which tests belong to which tasks.

The way tests are linked to tasks is via an (optional) task_id field, which is an integer that matches the number of the task as defined in the exercise's instructions.md file (note: the instructions start at index 1).

This is an example of a test in the results.json file:

{
  "name": "Expected oven time in minutes",
  "status": "pass",
  "task_id": 1,
  "test_code": "Assert.Equal(40, Lasagna.ExpectedMinutesInOven());"
}

You are completely free in how to implement this. Some options are:

  1. Add metadata to a test that the test runner can then discover while running the tests (e.g. an attribute or annotation)
  2. Define a test name/task id mapping (e.g. in the exercise's .meta/config.json file)
  3. Any other option you can think of...

Let me know if there are any questions.

junedev commented 2 years ago

Here my suggestion what we could do here:

By default, we assume that there is one func TestSomething(t *testing.T) {...} block for each task and that they appear in the order in which the tasks appear. We already have the test results in order and we can find out which parent test name each one has. There, we could easily number things. Everything with the first parent test name that appears in the list gets task id 1, next one gets 2 etc.

With that, we could handle like 80% of the cases (gut feeling) already without changing a single thing in the test files of the exercises.

Then for special concept exercises that have more test cases than tasks, we can allow adding the task id to the test manually. An example where we need this is https://github.com/exercism/go/blob/main/exercises/concept/bird-watcher/bird_watcher_test.go#L108

I am proposing to use a simple comment to add the task ID for a test. The pattern should be easy enough to check for and I can't think of a case where there would be other comments containing the same text so we would confuse things.

// TaskID 3
func TestFixBirdCount(t *testing.T) {
  // ...
}

@exercism/go Any thoughts on this?