|
| 1 | +#! /usr/bin/env bats |
| 2 | + |
| 3 | +load ../environment |
| 4 | + |
| 5 | +PRINT_SOURCE='printf -- "%s\n" "$BASH_SOURCE"' |
| 6 | + |
| 7 | +setup() { |
| 8 | + test_filter |
| 9 | + @go.create_test_go_script '@go "$@"' |
| 10 | +} |
| 11 | + |
| 12 | +teardown() { |
| 13 | + @go.remove_test_go_rootdir |
| 14 | +} |
| 15 | + |
| 16 | +@test "$SUITE: project script takes precedence over plugin" { |
| 17 | + @go.create_test_command_script 'plugins/foo/bin/foo' "$PRINT_SOURCE" |
| 18 | + @go.create_test_command_script 'foo' "$PRINT_SOURCE" |
| 19 | + |
| 20 | + run "$TEST_GO_SCRIPT" 'foo' |
| 21 | + assert_success "$TEST_GO_SCRIPTS_DIR/foo" |
| 22 | +} |
| 23 | + |
| 24 | +@test "$SUITE: plugin can't use script from top-level _GO_SCRIPTS_DIR" { |
| 25 | + @go.create_test_command_script 'plugins/foo/bin/foo' '@go bar' |
| 26 | + @go.create_test_command_script 'bar' "$PRINT_SOURCE" |
| 27 | + |
| 28 | + run "$TEST_GO_SCRIPT" 'foo' |
| 29 | + assert_failure |
| 30 | + assert_line_equals 0 'Unknown command: bar' |
| 31 | +} |
| 32 | + |
| 33 | +@test "$SUITE: plugin can use script from top-level _GO_PLUGINS_DIR" { |
| 34 | + @go.create_test_command_script 'plugins/foo/bin/foo' '@go bar' |
| 35 | + @go.create_test_command_script 'plugins/bar/bin/bar' "$PRINT_SOURCE" |
| 36 | + |
| 37 | + run "$TEST_GO_SCRIPT" 'foo' |
| 38 | + assert_success "$TEST_GO_SCRIPTS_DIR/plugins/bar/bin/bar" |
| 39 | +} |
| 40 | + |
| 41 | +@test "$SUITE: plugin can use plugin from own plugin dir" { |
| 42 | + @go.create_test_command_script 'plugins/foo/bin/foo' '@go bar' |
| 43 | + @go.create_test_command_script 'plugins/foo/bin/plugins/bar/bin/bar' \ |
| 44 | + "$PRINT_SOURCE" |
| 45 | + |
| 46 | + run "$TEST_GO_SCRIPT" 'foo' |
| 47 | + assert_success "$TEST_GO_SCRIPTS_DIR/plugins/foo/bin/plugins/bar/bin/bar" |
| 48 | +} |
| 49 | + |
| 50 | +@test "$SUITE: plugin's local _GO_SCRIPTS_DIR scripts take precedence" { |
| 51 | + @go.create_test_command_script 'plugins/foo/bin/foo' '@go bar' |
| 52 | + @go.create_test_command_script 'plugins/foo/bin/bar' "$PRINT_SOURCE" |
| 53 | + @go.create_test_command_script 'plugins/bar/bin/bar' "$PRINT_SOURCE" |
| 54 | + @go.create_test_command_script 'plugins/foo/bin/plugins/bar/bin/bar' \ |
| 55 | + "$PRINT_SOURCE" |
| 56 | + |
| 57 | + run "$TEST_GO_SCRIPT" 'foo' |
| 58 | + assert_success "$TEST_GO_SCRIPTS_DIR/plugins/foo/bin/bar" |
| 59 | +} |
| 60 | + |
| 61 | +@test "$SUITE: local plugins take precedence over top-level _GO_PLUGINS_DIR" { |
| 62 | + @go.create_test_command_script 'plugins/foo/bin/foo' '@go bar' |
| 63 | + @go.create_test_command_script 'plugins/bar/bin/bar' "$PRINT_SOURCE" |
| 64 | + @go.create_test_command_script 'plugins/foo/bin/plugins/bar/bin/bar' \ |
| 65 | + "$PRINT_SOURCE" |
| 66 | + |
| 67 | + run "$TEST_GO_SCRIPT" 'foo' |
| 68 | + assert_success "$TEST_GO_SCRIPTS_DIR/plugins/foo/bin/plugins/bar/bin/bar" |
| 69 | +} |
| 70 | + |
| 71 | +@test "$SUITE: circular dependencies in nested plugin dirs" { |
| 72 | + @go.create_test_command_script 'plugins/foo/bin/foo' '@go bar' |
| 73 | + @go.create_test_command_script 'plugins/foo/bin/baz' "$PRINT_SOURCE" |
| 74 | + @go.create_test_command_script 'plugins/foo/bin/plugins/bar/bin/bar' '@go baz' |
| 75 | + |
| 76 | + run "$TEST_GO_SCRIPT" 'foo' |
| 77 | + assert_success "$TEST_GO_SCRIPTS_DIR/plugins/foo/bin/baz" |
| 78 | +} |
| 79 | + |
| 80 | +@test "$SUITE: circular dependencies in top-level _GO_PLUGINS_DIR" { |
| 81 | + @go.create_test_command_script 'plugins/foo/bin/foo' '@go bar' |
| 82 | + @go.create_test_command_script 'plugins/foo/bin/baz' "$PRINT_SOURCE" |
| 83 | + @go.create_test_command_script 'plugins/bar/bin/bar' '@go baz' |
| 84 | + |
| 85 | + run "$TEST_GO_SCRIPT" 'foo' |
| 86 | + assert_success "$TEST_GO_SCRIPTS_DIR/plugins/foo/bin/baz" |
| 87 | +} |
| 88 | + |
| 89 | +@test "$SUITE: nested plugin's _GO_SCRIPTS_DIR precedes plugins" { |
| 90 | + @go.create_test_command_script 'plugins/foo/bin/foo' '@go bar' |
| 91 | + @go.create_test_command_script 'plugins/foo/bin/plugins/bar/bin/bar' '@go baz' |
| 92 | + |
| 93 | + @go.create_test_command_script 'plugins/foo/bin/plugins/bar/bin/baz' \ |
| 94 | + "$PRINT_SOURCE" |
| 95 | + @go.create_test_command_script \ |
| 96 | + 'plugins/foo/bin/plugins/bar/bin/plugins/baz/bin/baz' \ |
| 97 | + "$PRINT_SOURCE" |
| 98 | + @go.create_test_command_script 'plugins/foo/bin/plugins/baz/bin/baz' \ |
| 99 | + "$PRINT_SOURCE" |
| 100 | + @go.create_test_command_script 'plugins/baz/bin/baz' "$PRINT_SOURCE" |
| 101 | + |
| 102 | + run "$TEST_GO_SCRIPT" 'foo' |
| 103 | + assert_success "$TEST_GO_SCRIPTS_DIR/plugins/foo/bin/plugins/bar/bin/baz" |
| 104 | +} |
| 105 | + |
| 106 | +@test "$SUITE: nested plugin's plugins precede parents' plugins" { |
| 107 | + @go.create_test_command_script 'plugins/foo/bin/foo' '@go bar' |
| 108 | + @go.create_test_command_script 'plugins/foo/bin/plugins/bar/bin/bar' '@go baz' |
| 109 | + |
| 110 | + @go.create_test_command_script \ |
| 111 | + 'plugins/foo/bin/plugins/bar/bin/plugins/baz/bin/baz' \ |
| 112 | + "$PRINT_SOURCE" |
| 113 | + @go.create_test_command_script 'plugins/foo/bin/plugins/baz/bin/baz' \ |
| 114 | + "$PRINT_SOURCE" |
| 115 | + @go.create_test_command_script 'plugins/baz/bin/baz' "$PRINT_SOURCE" |
| 116 | + |
| 117 | + run "$TEST_GO_SCRIPT" 'foo' |
| 118 | + assert_success \ |
| 119 | + "$TEST_GO_SCRIPTS_DIR/plugins/foo/bin/plugins/bar/bin/plugins/baz/bin/baz" |
| 120 | +} |
| 121 | + |
| 122 | +@test "$SUITE: nested plugin's sibling precedes top-level _GO_PLUGINS_DIR" { |
| 123 | + @go.create_test_command_script 'plugins/foo/bin/foo' '@go bar' |
| 124 | + @go.create_test_command_script 'plugins/foo/bin/plugins/bar/bin/bar' '@go baz' |
| 125 | + |
| 126 | + @go.create_test_command_script 'plugins/foo/bin/plugins/baz/bin/baz' \ |
| 127 | + "$PRINT_SOURCE" |
| 128 | + @go.create_test_command_script 'plugins/baz/bin/baz' "$PRINT_SOURCE" |
| 129 | + |
| 130 | + run "$TEST_GO_SCRIPT" 'foo' |
| 131 | + assert_success "$TEST_GO_SCRIPTS_DIR/plugins/foo/bin/plugins/baz/bin/baz" |
| 132 | +} |
| 133 | + |
| 134 | +@test "$SUITE: nested plugin finds top-level _GO_PLUGINS_DIR plugin" { |
| 135 | + @go.create_test_command_script 'plugins/foo/bin/foo' '@go bar' |
| 136 | + @go.create_test_command_script 'plugins/foo/bin/plugins/bar/bin/bar' '@go baz' |
| 137 | + |
| 138 | + @go.create_test_command_script 'plugins/baz/bin/baz' "$PRINT_SOURCE" |
| 139 | + |
| 140 | + run "$TEST_GO_SCRIPT" 'foo' |
| 141 | + assert_success "$TEST_GO_SCRIPTS_DIR/plugins/baz/bin/baz" |
| 142 | +} |
| 143 | + |
| 144 | +@test "$SUITE: nested plugins dir doesn't leak to sibling plugin" { |
| 145 | + @go.create_test_command_script 'plugins/foo/bin/foo' '@go bar' |
| 146 | + @go.create_test_command_script 'plugins/foo/bin/plugins/bar/bin/bar' '@go baz' |
| 147 | + @go.create_test_command_script 'plugins/foo/bin/plugins/quux/bin/quux' \ |
| 148 | + "$PRINT_SOURCE" |
| 149 | + @go.create_test_command_script 'plugins/baz/bin/baz' '@go quux' |
| 150 | + |
| 151 | + run "$TEST_GO_SCRIPT" 'foo' |
| 152 | + assert_failure |
| 153 | + assert_line_equals 0 'Unknown command: quux' |
| 154 | +} |
0 commit comments