|
| 1 | +. $(dirname $0)/helper.sh |
| 2 | +. "${AUTODEP8_SUPPORT_DIR}/autodep8lib.sh" |
| 3 | + |
| 4 | +run_read_config() { |
| 5 | + has debian/tests/autopkgtest-pkg-ruby.conf "$@" |
| 6 | + check_run read_config ruby |
| 7 | +} |
| 8 | + |
| 9 | +assertInvalidConfig() { |
| 10 | + assertEquals "W: debian/tests/autopkgtest-pkg-ruby.conf: invalid configuration line: ${1} (ignored)" "$(cat stderr)" |
| 11 | +} |
| 12 | + |
| 13 | +test_no_config() { |
| 14 | + check_run read_config ruby |
| 15 | + assertEquals "" "$(cat stdout)" |
| 16 | + assertEquals "" "$(cat stderr)" |
| 17 | +} |
| 18 | + |
| 19 | +test_read_config_valid() { |
| 20 | + run_read_config 'foo=bar' |
| 21 | + assertEquals "foo=bar" "$(cat stdout)" |
| 22 | +} |
| 23 | + |
| 24 | +test_read_config_invalid_single_word() { |
| 25 | + run_read_config 'foo' |
| 26 | + assertEquals "" "$(cat stdout)" |
| 27 | + assertInvalidConfig foo |
| 28 | +} |
| 29 | + |
| 30 | +test_read_config_invalid_no_assignment() { |
| 31 | + run_read_config 'foo bar' |
| 32 | + assertEquals "" "$(cat stdout)" |
| 33 | + assertInvalidConfig 'foo bar' |
| 34 | +} |
| 35 | + |
| 36 | +test_read_config_invalid_variable() { |
| 37 | + run_read_config 'foo bar=baz' |
| 38 | + assertEquals "" "$(cat stdout)" |
| 39 | + assertInvalidConfig 'foo bar=baz' |
| 40 | +} |
| 41 | + |
| 42 | +test_read_config_invalid_variable_an_whitespace() { |
| 43 | + run_read_config 'foo bar = baz' |
| 44 | + assertEquals "" "$(cat stdout)" |
| 45 | + assertInvalidConfig 'foo bar = baz' |
| 46 | +} |
| 47 | + |
| 48 | +test_read_config_invalid_command_injection() { |
| 49 | + run_read_config '/bin/sh -c "poweroff"' |
| 50 | + assertEquals "" "$(cat stdout)" |
| 51 | + assertInvalidConfig '/bin/sh -c "poweroff"' |
| 52 | +} |
| 53 | + |
| 54 | +test_read_config_remove_comments() { |
| 55 | + run_read_config '# comment\nfoo=bar\n# more comments' |
| 56 | + assertEquals "foo=bar" "$(cat stdout)" |
| 57 | + assertEquals "" "$(cat stderr)" |
| 58 | +} |
| 59 | + |
| 60 | +test_read_config_multiline() { |
| 61 | + run_read_config 'foo=bar \\\nbaz' |
| 62 | + assertEquals "foo=bar baz" "$(cat stdout)" |
| 63 | +} |
| 64 | + |
| 65 | +test_read_config_remove_whitespace_around_equals() { |
| 66 | + run_read_config 'foo = bar' |
| 67 | + assertEquals 'foo=bar' "$(cat stdout)" |
| 68 | +} |
| 69 | + |
| 70 | +test_read_config_remove_whitespace_multiple_equals() { |
| 71 | + run_read_config 'foo = bar = baz' |
| 72 | + assertEquals 'foo=bar = baz' "$(cat stdout)" |
| 73 | +} |
| 74 | + |
| 75 | +test_read_config_exports_variables() { |
| 76 | + run_read_config 'foo=bar' |
| 77 | + assertEquals "bar" "${pkg_ruby_foo}" |
| 78 | +} |
| 79 | + |
| 80 | +. shunit2 |
0 commit comments