Skip to content

Commit

Permalink
ShellMixin: workdir should be overridable
Browse files Browse the repository at this point in the history
This is a port from eight.
  • Loading branch information
Jared Grubb committed Mar 8, 2015
1 parent cb9b4c0 commit ec26788
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion master/buildbot/process/buildstep.py
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,8 @@ def makeRemoteShellCommand(self, collectStdout=False, collectStderr=False,
kwargs['env'].update(self.env)
kwargs['stdioLogName'] = stdioLogName

kwargs['workdir'] = self.workdir
if not kwargs.get('workdir'):
kwargs['workdir'] = self.workdir

# the rest of the args go to RemoteShellCommand
cmd = remotecommand.RemoteShellCommand(
Expand Down
19 changes: 17 additions & 2 deletions master/buildbot/test/unit/test_process_buildstep.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,13 +822,15 @@ def run(self):

class SimpleShellCommand(buildstep.ShellMixin, buildstep.BuildStep):

def __init__(self, **kwargs):
def __init__(self, makeRemoteShellCommandKwargs=None, **kwargs):
self.makeRemoteShellCommandKwargs = makeRemoteShellCommandKwargs or {}

kwargs = self.setupShellMixin(kwargs)
buildstep.BuildStep.__init__(self, **kwargs)

@defer.inlineCallbacks
def run(self):
cmd = yield self.makeRemoteShellCommand()
cmd = yield self.makeRemoteShellCommand(**self.makeRemoteShellCommandKwargs)
yield self.runCommand(cmd)
defer.returnValue(cmd.results())

Expand Down Expand Up @@ -922,6 +924,19 @@ def test_example_step_workdir(self):
self.expectOutcome(result=SUCCESS)
yield self.runStep()

@defer.inlineCallbacks
def test_example_override_workdir(self):
# Test that makeRemoteShellCommand(workdir=X) works.
self.setupStep(SimpleShellCommand(
makeRemoteShellCommandKwargs={'workdir': '/alternate'},
command=['foo', properties.Property('bar', 'BAR')]))
self.expectCommands(
ExpectShell(workdir='/alternate', command=['foo', 'BAR'])
+ 0,
)
self.expectOutcome(result=SUCCESS)
yield self.runStep()

@defer.inlineCallbacks
def test_example_env(self):
self.setupStep(ShellMixinExample(env={'BAR': 'BAR'}), wantDefaultWorkdir=False)
Expand Down

0 comments on commit ec26788

Please sign in to comment.