Commit graph

53 commits

Author SHA1 Message Date
Adam Spiers
0979a9c7bd Change #!/usr/local/bin/perl to #!/usr/bin/perl in t/*.t
This doesn't really matter, since these are not executed directly, but
it's more consistent with everything else and modern systems.
2019-06-27 20:37:50 +01:00
Adam Spiers
27796720d5 Upgrade to GPL v3 and add headers to files (#44)
Following advice from maintainers@gnu.org, bring Stow in line with
other GNU projects by upgrading it from GPL v2 to v3

  https://www.gnu.org/prep/maintain/html_node/Licensing-of-GNU-Packages.html#Licensing-of-GNU-Packages

as obtained in plain text and texinfo formats from

  https://www.gnu.org/licenses/

and adding appropriate headers:

  https://www.gnu.org/prep/maintain/html_node/License-Notices-for-Code.html#License-Notices-for-Code

Fixes #44: https://github.com/aspiers/stow/issues/44
2019-06-27 20:37:40 +01:00
Charles LeDoux
dc42c34107 Add function to expand ~ in .stowrc files (#14)
Add a new expand_tilde() function that performs tilde expansion of
strings, and corresponding unit tests:

    * A ~ at the beginning of a path is expanded to the user's home
      directory.
    * Literal '~' can be provided with '\~'

Combine this with expand_environment() in a new expand_filepath()
function which applies all (both) required expansion functions to a
string, and use that in get_config_file_options() to expand .stowrc
options.

Add more tests to check that tilde expanded in correct places, i.e.:

    * expanded for --target and --dir
    * not expanded for --ignore, --defer, or --override

Update documentation on stowrc files according to this functionality
change.

Fixes #14: https://github.com/aspiers/stow/issues/14
2019-06-25 19:38:43 +01:00
Charles LeDoux
9674738792 Apply environment expansion to options in .stowrc files
Expand environment variables used in stowrc, as requested in

    https://savannah.gnu.org/bugs/?41826

This is achieved by creating a new function expand_environment() that
replaces any substring of the form '$VAR' or '${VAR}' with contents of
environment variable $VAR.  Literal '$' can be given by '\$'.

N.B. The function is only applied to the --target and --dir options,
and only for options specified in .stowrc; cli options are left
untouched.

Undefined variables are expanded to the empty string, as they would be
in normal shell parameter expansion.

Unit tests added accordingly:

  - Test expand_environment():
    * Expand $HOME
    * Expand ${HOME}
    * Expand ${WITH SPACE}
    * Expand '\$HOME'. Expected is '$HOME'
    * Expand ${UNDEFINED}. Expected is ''.

  - Test that it's applied to the correct options.

  - Test that CLI options are not expanded.
2019-06-25 19:38:26 +01:00
Charles LeDoux
ebc895a540 Add test for conflicting stowrc and cli args
Why:

* Want to add feature to stowrc parsing.
* Missing regression test for conflicting cli and stowrc options.

This change addresses the need by:

* Add missing regression tests to rc_options.t
    * Two types of tests for the two types of options possible.

* For scalar options such as --target, cli arguments should overwrite
  stowrc arguments.

* For options that result in a list, such as --ignore, the arguments
  from cli and stowrc files should be merged.
2019-06-25 19:38:25 +01:00
Charles LeDoux
237288fb7e Add test harness for stowrc files
Why:

* Planning on developing a new feature for parsing of stowrc files.
* Need a test harness that performs initialization and clean up
    * Initialization: Create directory structure that allows creation of
      stowrc files without worrying about squashing existing files.
    * Clean up: Remove all files created during testing.

This change addresses the need by:

* Add intialization and cleanup harness in t/rc_options.t
    * Define the location to write stowrc files to in $RC_FILE
    * Ensures that location $RC_FILE does not already exist.
    * Calls the init_test_dirs to bootstrap directory tree.
    * After all tests are run, removes $RC_FILE and the testing
      directory tree.

* Add basic test of stowrc parsing to t/rc_options.t
    * Provides a template of how to create and test a stowrc file.

* Newly created t/rc_options.t file added to MANIFEST
2019-06-25 19:38:25 +01:00
Charles LeDoux
048203b7f9 Change init_test_dirs to point $HOME at $OUT_DIRS
Why:

* Want to add a new feature to parsing of stowrc files.
* Need ability to write .stowrc files for testing without risk of
  squashing existing files.

This change addresses the need by:

* Reusing logic in init_test_dirs
    * init_test_dirs already creates new directory structure and overwrites
      $HOME to point into /tmp.
* This commit changes init_test_dirs to point $HOME at the newly created
  directory structure ($OUT_DIR) instead of /tmp.
    * Grants ability to write .stowrc to $HOME without fear.
    * Pointing $HOME at $OUT_DIR instead of /tmp also makes cleanup easier.
        * Remove $OUT_DIR vs remove specific files in /tmp.
2019-06-25 19:38:25 +01:00
Adam Spiers
e79c5938bc Return non-zero exit code when invalid option is specified (#34)
Also add a unit test for this.

Fixes #34: https://github.com/aspiers/stow/issues/34
2019-06-25 15:43:08 +01:00
Adam Spiers
8394507891 Add cli.t for testing invocation of stow executable
Unlike the other tests, this actually treats stow(1) as a black box
script, running it directly rather than require-ing it as a library.
This allows us to check things like the exit codes returned.
2019-06-25 15:26:25 +01:00
Adam Spiers
bd4241b3e4 Make dotfiles.t executable for consistency with other tests 2019-06-25 14:30:30 +01:00
Joris Vankerschaver
182acbbb64 Special processing for dotfiles 2016-10-04 17:51:01 +01:00
Lucas Theisen
c171ca8d83 fixed testutil to support cygwin which reports -z = true on directories 2016-02-28 13:39:03 +00:00
LE Manh Cuong
8544b2f0f5 Allow directory with trailing and leading spaces
- The `sanitize_path_options` functions remove all trailing
 and leading spaces. So any valid directory like ` 123`,
 `123 ` can not be used

 - Also if there are two directories ` 123` and `123`, and if
 user pick the ` 123` as option to `-d` or `-t`, then stow pick
 directory `123` as the argument instead of ` 123` as user want.

    ```
    STOW_DIR=. stow -n -v3 -t \ 123 456
    stow dir is /tmp/test
    stow dir path relative to target 123 is ..
    cwd now 123
    cwd restored to /tmp/test
    cwd now 123
    Planning stow of package 456...
    Stowing contents of ../456 (cwd=/tmp/test/123)
    Planning stow of package 456... done
    cwd restored to /tmp/test
    WARNING: in simulation mode so not modifying filesystem.
    ```
 - This commit remove the check in `sanitize_path_options` function,
 and now stow can work with those directories. There have been a check
 for valid directory, so we are safe.
2015-11-13 20:17:58 +07:00
Adam Spiers
7b43622dd9 fix stowing of relative links when --no-folding is used
With a tree like this:

    .
    |-- stow
    |   `-- pkg
    |       `-- lib
    |           |-- itk-current -> itk4.0.0
    |           `-- itk4.0.0
    |               `-- libitk4.0.0.so
    `-- target
        `-- lib
            |-- itk4.0.0 -> ../../stow/pkg/lib/itk4.0.0
            `-- libfoo-1.2.3.so

stowing pkg with the --no-folding option resulted in itk-current
being "unpacked":

    .
    `-- target
        `-- lib
            |-- itk-current
            |   `-- libitk4.0.0.so -> ../../../stow/pkg/lib/itk-current/libitk4.0.0.so
            |-- itk4.0.0
            |   `-- libitk4.0.0.so -> ../../../stow/pkg/lib/itk4.0.0/libitk4.0.0.so
            `-- libfoo-1.2.3.so

This commit fixes it so that it gets stowed as a symlink:

  .
  `-- target
      `-- lib
          ...
          |-- itk-current -> ../../stow/pkg/lib/itk-current
          ...

Thanks to Gabriele Balducci for reporting this problem:

    http://thread.gmane.org/gmane.comp.gnu.stow.general/6676
2015-01-01 19:02:46 +00:00
Adam Spiers
07a84541f1 make it more obvious when target (sub)directory is skipped
This should avoid the sort of confusion seen in:

  https://github.com/aspiers/shell-env/issues/1
2014-09-23 01:37:54 +01:00
Adam Spiers
497a067621 trim trailing whitespace 2014-09-23 01:37:54 +01:00
Adam Spiers
af36a44bcb Remove accidentally duplicated code. 2012-02-19 19:16:00 +00:00
Adam Spiers
ed12c787df Add --no-folding option. 2012-02-18 20:33:34 +00:00
Adam Spiers
91c816e32d Use make_invalid_link() to reliably setup symlink fixtures. 2012-02-18 20:33:34 +00:00
Adam Spiers
1847b36e18 Make shared library tests match real-world scenarios.
Typically, libfoo.so.X.Y.Z is the file, and libfoo.so is the symlink
which points to it.
2012-02-18 12:28:00 +00:00
Adam Spiers
8357dca645 Remove "There are no outstanding operations to perform" warning.
This is more in keeping with the UNIX convention of no output on success,
and is also the way Stow v1.x behaved.  Thanks to Adam Sampson for the suggestion.
2012-01-11 14:01:40 +00:00
Adam Spiers
0c6d5639e3 Rename test files to reflect their purpose. 2012-01-09 22:12:49 +00:00
Adam Spiers
c3c866a00b Rename stow.t to be more consistent with its purpose. 2012-01-09 22:12:49 +00:00
Adam Spiers
7e44666640 Add --adopt / -a option. 2012-01-09 21:29:34 +00:00
Adam Spiers
4dce3d0ce8 Use get_conflict_count() in tests since get_conflicts() no longer returns a flat structure. 2012-01-09 18:32:06 +00:00
Adam Spiers
7c90000393 Add another ignore example to the manual and test suite. 2011-12-21 11:45:43 +00:00
Adam Spiers
bcac91d68a Remove quote stripping code.
I'm guessing it was added due to a misunderstanding of how shell
quoting works.  When you invoke

   stow --ignore=".#.*" ...

the shell strips out the quotes before the Perl process ever sees them.
I can't imagine any sensible scenario in which you would need to invoke

   stow --ignore='"foo"'

but if the user has a filename containing quotes at the beginning and
end, they can now choose to ignore it (prior to this patch, they couldn't).
2011-11-26 16:34:57 +00:00
Adam Spiers
3d414dc071 Improve conflict reporting 2011-11-26 16:34:57 +00:00
Adam Spiers
10ea9c6f4b Numerous fixes so that `make distcheck' succeeds.
Moves temporary test trees into a separate directory.
2011-11-26 16:34:57 +00:00
Adam Spiers
0db112441f Strip superfluous quotes from $hash{'lookups'} 2011-11-26 16:34:54 +00:00
Adam Spiers
ea82ef5b8b Add support for ignore lists. 2011-11-26 16:34:48 +00:00
Adam Spiers
8960a4f1fb Add another test to join_paths.t 2011-11-26 15:10:28 +00:00
Adam Spiers
7bef0fb700 Clean up coding style in tests 2011-11-26 15:10:28 +00:00
Adam Spiers
2244539b6b Test stow/unstow with stow dir / target dir as absolute paths. 2011-11-26 15:10:28 +00:00
Adam Spiers
dc61da22d4 Major refactoring of code into separate Stow and Stow::Util Perl modules 2011-11-24 16:56:11 +00:00
Adam Spiers
fbe547c132 Test unstowing when target contains a real file generates a conflict. 2011-11-24 16:55:55 +00:00
Adam Spiers
6e7ed071c1 Test unstowing stuff which doesn't exist in the target tree. 2011-11-24 16:55:55 +00:00
Adam Spiers
a1246072dd Remove setting of verbosity from tests 2011-11-24 16:55:55 +00:00
Adam Spiers
80826b96e2 Add protection against stowing into stow dirs 2011-11-24 16:55:55 +00:00
Adam Spiers
9012dd8aa8 Test unstowing an already unstowed package 2011-11-24 16:55:54 +00:00
Adam Spiers
28dbad2933 Sync t/unstow_contents{,_orig}.t 2011-11-24 16:55:54 +00:00
Adam Spiers
c26236d93c Debug with maximum verbosity to STDOUT when running tests. 2011-11-24 16:55:54 +00:00
Adam Spiers
497f272c12 Refactored reset_state() into t/util.pm 2011-11-24 16:55:54 +00:00
Adam Spiers
1d3f45580b Don't tolerate '' as value for $target parameter to (un)stow_contents 2011-11-24 16:55:54 +00:00
Adam Spiers
85f1f8619c Fix inconsistencies in coding style. 2011-11-24 16:55:53 +00:00
Adam Spiers
801446a5eb Use File::Spec->abs2rel() instead of home-grown relative_path
which actually gets some inputs wrong (e.g. "/" relative to "/")
2011-11-24 16:55:53 +00:00
Adam Spiers
d674d13a68 Fix typos 2011-11-24 16:55:52 +00:00
Adam Spiers
8de15394bb Catch warnings in tests when no outstanding operations to perform.
Tests now all pass completely cleanly.
2011-11-24 16:55:52 +00:00
Adam Spiers
d74ae26f89 Fix %Options typo in several tests 2011-11-24 16:55:52 +00:00
Adam Spiers
4296500c94 Fix t/stow.t 2011-11-24 16:55:52 +00:00