{"action":"created","issue":{"url":"https://api.github.com/repos/philsquared/Catch/issues/558","repository_url":"https://api.github.com/repos/philsquared/Catch","labels_url":"https://api.github.com/repos/philsquared/Catch/issues/558/labels{/name}","comments_url":"https://api.github.com/repos/philsquared/Catch/issues/558/comments","events_url":"https://api.github.com/repos/philsquared/Catch/issues/558/events","html_url":"https://github.com/philsquared/Catch/issues/558","id":122627600,"number":558,"title":"Run test case N times with N different inputs","user":{"login":"capsocrates","id":10004446,"avatar_url":"https://avatars.githubusercontent.com/u/10004446?v=3","gravatar_id":"","url":"https://api.github.com/users/capsocrates","html_url":"https://github.com/capsocrates","followers_url":"https://api.github.com/users/capsocrates/followers","following_url":"https://api.github.com/users/capsocrates/following{/other_user}","gists_url":"https://api.github.com/users/capsocrates/gists{/gist_id}","starred_url":"https://api.github.com/users/capsocrates/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/capsocrates/subscriptions","organizations_url":"https://api.github.com/users/capsocrates/orgs","repos_url":"https://api.github.com/users/capsocrates/repos","events_url":"https://api.github.com/users/capsocrates/events{/privacy}","received_events_url":"https://api.github.com/users/capsocrates/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2015-12-16T23:30:58Z","updated_at":"2016-11-02T17:01:43Z","closed_at":null,"body":"Sometimes I want to repeat a test a number of times, but with one (or more) values changed each time. If I try to wrap a TEST_CASE inside a for loop, the for loop just executes on its own before the TEST_CASE executes.\n\nE.g.\n\n``` c++\n//desired behavior\n\nSCENARIO(\"... some scenario...\", \"\") {\n    //do setup here\n    WHEN(\"We do something 10 times\") {\n        std::vector<mock_class> objs;\n        for(const auto counter : {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}) {\n            WHEN(\"We do something\") {\n                static_member_of_mock_class = counter;\n                //do stuff with mock class that modifies objs\n            }\n        }\n    }\n}\n```\n\n``` c++\n//how to actually implement desired behavior with Catch\n\nSCENARIO(\"... some scenario...\", \"\") {\n    WHEN(\"We do something 10 times\") {\n        for(const auto counter : {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}) {\n            std::vector<mock_class> objs;\n            static_member_of_mock_class = counter;\n            //do stuff with mock class that modifies objs\n        }\n    }\n}\n```\n\nI recognize that a for loop might not jive with the implementation of the TEST_CASEs, but it would be nice to have some built-in feature that allows Catch to run the same test over again just with different inputs/setups.\n\nAs an extension to that, it would be nice to have a feature that allowed running a TEST_CASE repeatedly with different combinations of inputs, for instance, given inputs\n\n``` c++\nconst auto counters = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};\nconst auto letters = {'a', 'b', 'c', 'd', 'e'};\nconst auto strings = {\"abra\", \"cadabra\"};\n\nCOMBINE(counters, letters, strings) {\n    std::cout << counter << letter << string << \", \";\n    /*\n     * outputs 0aabra, 1aabra 2aabra ... 0babra ... 0cabra... 0acadabra ... etc.\n     * */\n}\n```\n"},"comment":{"url":"https://api.github.com/repos/philsquared/Catch/issues/comments/257929211","html_url":"https://github.com/philsquared/Catch/issues/558#issuecomment-257929211","issue_url":"https://api.github.com/repos/philsquared/Catch/issues/558","id":257929211,"user":{"login":"roversch","id":1436556,"avatar_url":"https://avatars.githubusercontent.com/u/1436556?v=3","gravatar_id":"","url":"https://api.github.com/users/roversch","html_url":"https://github.com/roversch","followers_url":"https://api.github.com/users/roversch/followers","following_url":"https://api.github.com/users/roversch/following{/other_user}","gists_url":"https://api.github.com/users/roversch/gists{/gist_id}","starred_url":"https://api.github.com/users/roversch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roversch/subscriptions","organizations_url":"https://api.github.com/users/roversch/orgs","repos_url":"https://api.github.com/users/roversch/repos","events_url":"https://api.github.com/users/roversch/events{/privacy}","received_events_url":"https://api.github.com/users/roversch/received_events","type":"User","site_admin":false},"created_at":"2016-11-02T17:01:43Z","updated_at":"2016-11-02T17:01:43Z","body":"👍 This would be especially useful for testing numerical code, like the one I'm working on. \r\n\r\nFor example, I have slightly different data for each test run. I could write a loop around one 'REQUIRE', but for 'SECTION's or 'TEST_CASE's this does not work apparently."}}
{"actor":{"display_login":"roversch"}}