exercism / go-test-runner

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

Test code extraction for exercises with separate file for test cases #80

Open junedev opened 2 years ago

junedev commented 2 years ago

For practice exercises that have a generator, the list of test cases is written into a separate file cases_test.go currently because this is easier to do for the generator then to somehow insert it into an existing test file.

The issue is that the test runner currently can't handle this separate file. The content of that file is ignored which leads to sub-optimal output on the website. The extracted code does not include the actual test case.

The current output e.g. for hamming looks like this: image

What we would like to have instead is:

var tt = struct {
    s1          string
    s2          string
    want        int
    expectError bool
}{
    description: "long identical strands",
    s1:          "GGACTGAAATCTG",
    s2:          "GGACTGAAATCTG",
    want:        0,
    expectError: false,
}

got, err := Distance(tc.s1, tc.s2)

switch {
// the usual code here
}

This be be doable by AST parsing the cases file and inserting the test cases AST part into the Test function so the result mimics the usual structure that the test runner can handle correctly, see https://github.com/exercism/go-test-runner#subtest-format-specification.

Related: https://github.com/exercism/go/issues/1872