{"thread":{"id":"10100","subject":"How to re-use setups in multiple tests?","startedAt":"2007-10-01T10:27:49Z","lastAt":"2007-10-01T13:40:40Z","messageCount":6,"participants":["Tom Clarke","Johannes Schindelin","Karl Hasselström"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"54466","messageId":"550f9510710010327l3e729ff1tbbb9b6c674c1cb11@mail.gmail.com","threadId":"10100","inReplyTo":null,"subject":"How to re-use setups in multiple tests?","fromName":"Tom Clarke","fromEmail":"tom@u2i.com","sentAt":"2007-10-01T10:27:49Z","receivedAt":"2007-10-01T10:27:49Z","isPatch":false,"sender":{"key":"tom@u2i.com","avatar":null},"body":"I'm wondering if there's a pattern for re-using setups across several\ntests, similar to how a setUp function is used in xUnit. The problem\nis I need the setup to actually be re-run, for each test to start from\na clean slate, so using the following doesn't work as the setup is\njust run before the first test.\n\ntest_expect_success setup '\n     # setup repostory to a particular state\n'\ntest_expect_success test1 '\n    # some test that expects the state to be as defined in setup, and\nchanges state of repository\n'\n\ntest_expect_success test2 '\n    # another test that expects the state to be as defined in setup\n'\n\nIs there a convention for doing this that's already used? Perhaps\npulling the setup code into a function or duplicating the code? Or is\nit better to create a separate test file for tests that need to be\nisolated?\n\nThanks,\n\n-Tom\n"},{"id":"54475","messageId":"Pine.LNX.4.64.0710011243230.28395@racer.site","threadId":"10100","inReplyTo":"550f9510710010327l3e729ff1tbbb9b6c674c1cb11@mail.gmail.com","subject":"Re: How to re-use setups in multiple tests?","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-10-01T11:45:00Z","receivedAt":"2007-10-01T11:45:00Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 1 Oct 2007, Tom Clarke wrote:\n\n> I'm wondering if there's a pattern for re-using setups across several \n> tests, similar to how a setUp function is used in xUnit. The problem is \n> I need the setup to actually be re-run, for each test to start from a \n> clean slate, so using the following doesn't work as the setup is just \n> run before the first test.\n\nWe typically do the clean up phase explicitely.  Or avoid it.\n\nExample: you want to do something to a branch, but the next step should \nuse the original state of the branch.\n\nSolution: \"git checkout -b new-branch HEAD~5\"\n\nSorry, unless you are a little less mysterious about the exact use case \nyou have in mind, I cannot help more.\n\nCiao,\nDscho\n"},{"id":"54477","messageId":"550f9510710010516s305c843br53da294f65318862@mail.gmail.com","threadId":"10100","inReplyTo":"Pine.LNX.4.64.0710011243230.28395@racer.site","subject":"Re: How to re-use setups in multiple tests?","fromName":"Tom Clarke","fromEmail":"tom@u2i.com","sentAt":"2007-10-01T12:16:47Z","receivedAt":"2007-10-01T12:16:47Z","isPatch":false,"sender":{"key":"tom@u2i.com","avatar":null},"body":"In this case the first test rebases the branch created in setup (it's\ntesting the rebase merge strategy), the second test should do the same\nthing, except check there is a warning if a --message option is\npassed.\n\nI suppose I could find the old pre-rebase head and work with that, but\nthat doesn't seem that clean to me.\n\nHere's the code (non-working):\n\n#!/bin/sh\n\ntest_description='merge-rebase backend test'\n\n. ./test-lib.sh\n\ntest_expect_success setup '\n        echo hello >a &&\n        git add a &&\n        test_tick && git commit -m initial &&\n\n        git checkout -b branch &&\n        echo hello >b &&\n        git add b &&\n        test_tick && git commit -m onbranch &&\n\n        git checkout master &&\n        echo update >a &&\n        git add a &&\n        test_tick && git commit -m update\n'\n\ntest_expect_success 'merging using rebase does not create merge\ncommit' '\n        git checkout branch &&\n        git merge -s rebase master &&\n\n        ( git log --pretty=oneline ) >actual &&\n        (\n                echo \"4db7a5a013e67aa623d1fd294e8d46e89b3ace8f\nonbranch\"\n                echo \"893371811dbd13e85c098b72d1ab42bcfd24c2db update\"\n                echo \"0e960b10429bf3f1e168ee2cc7d531ac7c622580\ninitial\"\n        ) >expected &&\n        git diff -w -u expected actual\n'\n\ntest_expect_success 'merging using rebase with message gives warning'\n'\n        #doesn't work because the branch has already been rebased and\nis therefore up to date\n        git checkout branch &&\n        git merge -m \"a message\" -s rebase master 2>&1 expected &&\n        (\n                echo \"warning: Message is not used for rebase merge\nstrategy\"\n        ) >expected &&\n        git diff -w -u expected actual\n'\n\ntest_done\n\n\n-Tom\n\nOn 10/1/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> Hi,\n>\n> On Mon, 1 Oct 2007, Tom Clarke wrote:\n>\n> > I'm wondering if there's a pattern for re-using setups across several\n> > tests, similar to how a setUp function is used in xUnit. The problem is\n> > I need the setup to actually be re-run, for each test to start from a\n> > clean slate, so using the following doesn't work as the setup is just\n> > run before the first test.\n>\n> We typically do the clean up phase explicitely.  Or avoid it.\n>\n> Example: you want to do something to a branch, but the next step should\n> use the original state of the branch.\n>\n> Solution: \"git checkout -b new-branch HEAD~5\"\n>\n> Sorry, unless you are a little less mysterious about the exact use case\n> you have in mind, I cannot help more.\n>\n> Ciao,\n> Dscho\n>\n>\n"},{"id":"54479","messageId":"Pine.LNX.4.64.0710011336530.28395@racer.site","threadId":"10100","inReplyTo":"550f9510710010516s305c843br53da294f65318862@mail.gmail.com","subject":"Re: How to re-use setups in multiple tests?","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-10-01T12:39:03Z","receivedAt":"2007-10-01T12:39:03Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 1 Oct 2007, Tom Clarke wrote:\n\n> In this case the first test rebases the branch created in setup (it's \n> testing the rebase merge strategy), the second test should do the same \n> thing, except check there is a warning if a --message option is passed.\n> \n> I suppose I could find the old pre-rebase head and work with that, but \n> that doesn't seem that clean to me.\n\nYou can use \"git reset --hard master@{1}\", and it really escapes me why \nthis should not be clean, and why you want to jump through hoops instead \nusing a much more complicated technique.\n\nCiao,\nDscho\n"},{"id":"54481","messageId":"550f9510710010546q55209759k4770cd3e78121cfc@mail.gmail.com","threadId":"10100","inReplyTo":"Pine.LNX.4.64.0710011336530.28395@racer.site","subject":"Re: How to re-use setups in multiple tests?","fromName":"Tom Clarke","fromEmail":"tom@u2i.com","sentAt":"2007-10-01T12:46:46Z","receivedAt":"2007-10-01T12:46:46Z","isPatch":false,"sender":{"key":"tom@u2i.com","avatar":null},"body":"On 10/1/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> > I suppose I could find the old pre-rebase head and work with that, but\n> > that doesn't seem that clean to me.\n>\n> You can use \"git reset --hard master@{1}\", and it really escapes me why\n> this should not be clean, and why you want to jump through hoops instead\n> using a much more complicated technique.\n\nThat'll be because my git knowledge isn't good enough to make it\nclean. Thanks for the suggestion :-)\n\n-Tom\n"},{"id":"54485","messageId":"20071001134040.GA4311@diana.vm.bytemark.co.uk","threadId":"10100","inReplyTo":"550f9510710010546q55209759k4770cd3e78121cfc@mail.gmail.com","subject":"Re: How to re-use setups in multiple tests?","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2007-10-01T13:40:40Z","receivedAt":"2007-10-01T13:40:40Z","isPatch":false,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"On 2007-10-01 14:46:46 +0200, Tom Clarke wrote:\n\n> On 10/1/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n>\n> > > I suppose I could find the old pre-rebase head and work with\n> > > that, but that doesn't seem that clean to me.\n> >\n> > You can use \"git reset --hard master@{1}\", and it really escapes\n> > me why this should not be clean, and why you want to jump through\n> > hoops instead using a much more complicated technique.\n>\n> That'll be because my git knowledge isn't good enough to make it\n> clean. Thanks for the suggestion :-)\n\nAnother even more foolproof way would be to have the setup create a\n(lightweight) tag, and let each subtest reset to that tag.\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"}]}