wp-cli / wp-cli-tests

WP-CLI testing framework
MIT License
38 stars 23 forks source link

cp -r causes issues with symlinks on MacOS #182

Closed mrsdizzie closed 11 months ago

mrsdizzie commented 11 months ago

This function is used in a lot of the tests:

https://github.com/wp-cli/wp-cli-tests/blob/c2d228bbfe6eecc0cab3cfe71ea0d04c4ae1e095/src/Context/FeatureContext.php#L826-L828

On MacOS I have tests that fail with errors like:

--- Failed steps:

001 Scenario: Composer stack with both WordPress and wp-cli as dependencies (command line) # features/bootstrap.feature:321
      And a dependency on current wp-cli                                                   # features/bootstrap.feature:323
        $ cp -r '/Users/isla/source/wp-cli-dev/wp-cli'/* '/var/folders/v6/gqkd9_rd74171hsndwtjrxww0000gn/T/wp-cli-composer-local-652be01cc7a8d9.06666196/'

        cp: vendor/rmccue: No such file or directory
        cp: vendor/wp-cli/wp-cli-tests/vendor/rmccue: No such file or directory
        cp: vendor/wp-cli/wp-cli-tests/vendor/wp-cli: directory causes a cycle
        cp: vendor/wp-cli/find-command/vendor/rmccue: No such file or directory
        cp: vendor/wp-cli/find-command/vendor/wp-cli: directory causes a cycle
        cp: vendor/wp-cli/media-command/vendor/rmccue: No such file or directory

etc...

I believe this is caused by trying to copy symlinks around, as discussed here: https://unix.stackexchange.com/questions/500379/cp-works-differently-on-a-mac

I thought I could get around this by installing GNU cp from homebrew, but it doesn't work because even though I have it in my PATH, I think wp-cli is setting an empty ENV here:

https://github.com/wp-cli/wp-cli/blob/main/php/WP_CLI/Process.php#L52-L60

I'm not exactly sure what the solution is, but just want to document it here. Options seem to be:

danielbachhuber commented 11 months ago

Thanks for the report, @mrsdizzie !

I think the fix can be as simple as a conditional based on PHP_OS: https://github.com/wp-cli/wp-cli-tests/pull/183

We have some of these conditionals elsewhere (see use of is_windows()), so I think it's fine to use another in this case.