Skip to content

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

@junedev

Description

@junedev

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: exercism/go#1872

Metadata

Metadata

Assignees

No one assigned

    Labels

    x:action/improveImprove existing functionality/contentx:knowledge/intermediateQuite a bit of Exercism knowledge requiredx:module/test-runnerWork on Test Runnersx:rep/largeLarge amount of reputationx:size/mediumMedium amount of workx:type/codingWrite code that is not student-facing content (e.g. test-runners, generators, but not exercises)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions