1
0
Fork 0
mirror of synced 2024-11-16 13:35:35 -05:00
dotbot/test/tests/plugin.bash
E. Keys 0ba45763d9 Make parsed cli options available to plugins
- `Context` now provides a copy of the parsed cli options so that they
    can be used by plugins.
- Modified `Dispatcher` to pass parsed cli options to `Context`

Resolves #249
2020-12-02 19:19:40 -05:00

67 lines
No EOL
1.6 KiB
Bash

test_description='plugin loading works'
. '../test-lib.bash'
test_expect_success 'setup 1' '
cat > ${DOTFILES}/test.py <<EOF
import dotbot
import os.path
class Test(dotbot.Plugin):
def can_handle(self, directive):
return directive == "test"
def handle(self, directive, data):
with open(os.path.expanduser("~/flag"), "w") as f:
f.write("it works")
return True
EOF
'
test_expect_success 'run 1' '
run_dotbot --plugin ${DOTFILES}/test.py <<EOF
- test: ~
EOF
'
test_expect_success 'test 1' '
grep "it works" ~/flag
'
test_expect_success 'setup 2' '
rm ${DOTFILES}/test.py;
cat > ${DOTFILES}/test.py <<EOF
import dotbot
import os.path
class Test(dotbot.Plugin):
def can_handle(self, directive):
return directive == "test"
def handle(self, directive, data):
self._log.debug("Attempting to get options from Context")
options = self._context.options()
if options is None:
self._log.debug("Context.options is None, expected not None")
return False
if len(options.plugins) != 1:
self._log.debug("Context.options.plugins length is %i, expected 1" % len(options.plugins))
return False
if not options.plugins[0].endswith("test.py"):
self._log.debug("Context.options.plugins[0] is %s, expected end with tesp.py" % options.plugins[0])
return False
with open(os.path.expanduser("~/flag"), "w") as f:
f.write("it works")
return True
EOF
'
test_expect_success 'run 2' '
run_dotbot --plugin ${DOTFILES}/test.py <<EOF
- test: ~
EOF
'
test_expect_success 'test 2' '
grep "it works" ~/flag
'