exercism / go-test-runner

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

Extracting code for the specific test case does not work even when it conforms to the requirements #78

Closed junedev closed 1 year ago

junedev commented 2 years ago

Even though some exercise tests seems to conform to the spec described here https://github.com/exercism/go-test-runner#subtest-format-specification, the test code on the website includes all test cases instead only the one that is currently tested. Example where it is not working: Card Tricks Exercise image

Example where the test case extraction is working correctly: Cars Assemble image

dreig commented 1 year ago

I'd like to give this a go, if nobody else is currently working on it.

dreig commented 1 year ago

I can't find examples of it not working (for the Card Tricks exercise). The test-runner correctly splits the code into multiple test cases both locally, as well as on the website. I've looked through multiple community solutions, both recent and fairly old (> 6mo ago) and they all seem to pass multiple test cases. Below is a screenshot from a randomly chosen community solution: image

junedev commented 1 year ago

Strange, I will double check whether I can still reproduce the issue and report back.

dreig commented 1 year ago

I noticed that in some of the exercises, the body of the Run() contains multiple statements, in which case, only the first line would be extracted. You can see it in my screenshot above, (the last line: got := GetItem(tt.args.slice, tt.args.index)) as well as in both of your screenshots. I created #87 to address this.

junedev commented 1 year ago

@dreig Finally had some time to test around more. Here the output I see for Gross Store when I open up TestAddItem/ Invalid measurement unit (test successful):

func TestAddItem(t *testing.T) {
    tests := []struct {
        name        string
        entry       []entry
        expected    bool
    }{
        {
            "Invalid measurement unit",
            []entry{
                {"pasta", "", 0},
                {"onion", "quarter", 0},
                {"pasta", "pound", 0},
            },
            false,
        },
        {
            "Valid measurement unit",
            []entry{
                {"peas", "quarter_of_a_dozen", 3},
                {"tomato", "half_of_a_dozen", 6},
                {"chili", "dozen", 12},
                {"cucumber", "small_gross", 120},
                {"potato", "gross", 144},
                {"zucchini", "great_gross", 1728},
            },
            true,
        },
        {
            "check quantity of item added twice",
            []entry{
                {"peas", "quarter_of_a_dozen", 3},
                {"peas", "quarter_of_a_dozen", 6},
                {"tomato", "half_of_a_dozen", 6},
                {"tomato", "quarter_of_a_dozen", 9},
            },
            true,
        },
    }
    units := Units()
    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            bill := NewBill()
            for _, item := range tt.entry {
                ok := AddItem(bill, units, item.name, item.unit)
                if ok != tt.expected {
                    t.Errorf("Expected %t from AddItem, found %t at %v", tt.expected, ok, item.name)
                }

                itemQty, ok := bill[item.name]
                if ok != tt.expected {
                    t.Errorf("Could not find item %s in customer bill", item.name)
                }

                if itemQty != item.qty {
                    t.Errorf("Expected %s to have quantity %d in customer bill, found %d", item.name, item.qty, itemQty)
                }
            }
        })
    }
}

If things would be working correctly, I would expect to see only the data for the one subtest that I opened up. I see the same when the test is failing and also for other tasks of the exercise.

For Card Tricks it did not happen anymore.

dreig commented 1 year ago

@junedev missed your message (I have to to prune my GH notifications).

I can reproduce the issue locally in gross_store_test. I'll look into it this week and try to fix it.

junedev commented 1 year ago

Thanks!

I looked at the output above again and maybe the two ranges below the test data struct cause the confusion. It might be that the test runner cannot identify the correct range loop. If you run the test runner for this locally, it should show you a warning if this happens. (Not sure this is the problem but might be something worth looking at.)