Skip to content

sed command fails when using Windows paths - colon delimeter interferes with pathΒ #261

@ethanclevenger91

Description

@ethanclevenger91

Bug Report

Describe the current, buggy behavior

Scaffolding tests in Windows requires manual intervention in wp-tests-config.php (see this issue) when using the default tests path. Manually setting WP_CORE_DIR and WP_TESTS_DIR can prevent this by using something like C:\Users{User}\AppData\Local\Temp/wordpress/ and then running install-wp-tests. But the colon causes the following sed command to fail:

sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php

Describe how other contributors can replicate this bug

  • Pull down a plugin with tests to be run that were scaffolded with this package
  • Set environment variables for both WP_CORE_DIR and WP_TESTS_DIR with the format C:/somewhere/you/want/to/keep/tests as opposed to /c/somewhere/you/want/to/keep/tests:
export WP_TESTS_DIR='D:/dev/testing-wordpress/tests'
export WP_CORE_DIR='D:/dev/testing-wordpress/core'
  • Run install-wp-tests
  • Receive sed error: sed: -e expression #1, char 36: unknown option to `s'
  • Remove the directories that were created

Workaround-ish

  • Update env vars using the more "traditional"(?) format:
export WP_TESTS_DIR='/d/dev/testing-wordpress/tests'
export WP_CORE_DIR='/d/dev/testing-wordpress/core'
  • Remove the directories that were created (so start fresh)
  • Run install-wp-tests
  • Succeeds
  • Attempt to run tests
  • Get require_once error described here, which can be fixed with the last comment shared there

Describe what you would expect as the correct outcome

Ideally you would get started testing without manual intervention.

Let us know what environment you are running this on

OS:     Windows NT 10.0 build 18363 (Windows 10) AMD64
Shell:  C:\Program Files\Git\usr\bin\bash.exe
PHP binary:     C:/Users/ethan/bin/php/php
PHP version:    7.4.4
php.ini used:   C:\Users\ethan\bin\php\php.ini
WP-CLI root dir:        C:\Users\ethan\AppData\Roaming\Composer\vendor\wp-cli\wp-cli
WP-CLI vendor dir:      C:\Users\ethan\AppData\Roaming\Composer\vendor
WP_CLI phar path:
WP-CLI packages dir:    C:\Users\ethan/.wp-cli/packages/
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.4.0

Provide a possible solution

The colon is the problem and either needs to be escaped or another delimiter used. Maybe |? The PR for that is like two lines and I've successfully tested that as an alternative, so I can provide if necessary.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions