Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
#47: Revert - not a bug. Cover with proper tests and use cases
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed Aug 23, 2020
1 parent 63d60a2 commit c003acd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
11 changes: 11 additions & 0 deletions docs/examples/recursive-env-in-yaml/.rkd/makefile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: org.riotkit.rkd/yaml/v1

tasks:
:hello:
environment:
FIRST: "First"
SECOND: "Second"
THIRD: "Escaped one"
ALL: ${FIRST} ${SECOND} \${THIRD}
steps: |
echo "${ALL}"
2 changes: 1 addition & 1 deletion src/rkd/taskutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def sh(self, cmd: str, capture: bool = False, verbose: bool = False, strict: boo
env_str = ""

for name, value in env.items():
value = '' if value is None else str(value).replace('"', '\\"').replace('$', '\$')
value = '' if value is None else str(value).replace('"', '\\"')
env_str = env_str + (" export %s=\"%s\";\n" % (name, value))

cmd = env_str + cmd
Expand Down
17 changes: 17 additions & 0 deletions test/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,20 @@ def test_aliases_are_resolved_recursively(self):
full_output, exit_code = self._run_and_capture_output([':alias-in-alias-test'])

self.assertIn('Hello world', full_output)

def test_env_variables_are_recursively_resolved(self):
"""
:hello:
environment:
FIRST: "First"
SECOND: "Second"
THIRD: "Escaped one"
ALL: ${FIRST} ${SECOND} \${THIRD}
steps: |
echo "${ALL}"
"""

with self.environment({'RKD_PATH': SCRIPT_DIR_PATH + '/../docs/examples/recursive-env-in-yaml/.rkd'}):
full_output, exit_code = self._run_and_capture_output([':hello'])

self.assertIn('First Second ${THIRD}', full_output)
4 changes: 3 additions & 1 deletion test/test_taskutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,12 @@ def test_dollar_symbols_are_escaped_in_shell_commands(self):

with io.capture_descriptors(stream=out, enable_standard_out=False):
task.sh('env | grep TEST_ENV', env={
'TEST_ENV': 'Mikhail$1Bakunin$PATHtest'
'TEST_ENV': 'Mikhail\$1Bakunin\$PATHtest',
'TEST_ENV_NOT_ESCAPED': 'Hello $TEST_ENV'
})

self.assertIn('TEST_ENV=Mikhail$1Bakunin$PATHtest', out.getvalue())
self.assertIn('TEST_ENV_NOT_ESCAPED=Hello Mikhail$1Bakunin$PATHtest', out.getvalue())

def test_quotes_are_escaped_in_shell_commands(self):
task = InitTask()
Expand Down

0 comments on commit c003acd

Please sign in to comment.