Commit graph

79 commits

Author SHA1 Message Date
Adam Spiers
1282acf6b5 t/stow: use like() instead of ok(... =~ /.../) 2024-04-01 23:58:17 +01:00
Adam Spiers
2c255af187 t/unstow_orig: split into subtests 2024-04-01 22:39:32 +01:00
Adam Spiers
86f03d115d t/dotfiles.t: switch to subtests 2024-04-01 22:39:32 +01:00
Adam Spiers
a328c2cd4b t/stow: convert to subtests() 2024-04-01 22:39:32 +01:00
Adam Spiers
8c09d41054 add unit tests for adjust_dotfiles() 2024-03-31 23:52:00 +01:00
Adam Spiers
2f762e3908 Merge commit 'pullreqs/70' into dev 2024-03-31 23:41:02 +01:00
Adam Spiers
8436768144 Eliminate erroneous warning when unstowing (#65)
When unstowing a package, cleanup_invalid_links() is invoked to remove
any invalid links owned by Stow.  It was invoking link_owned_by_package()
to check whether each existing link is owned by Stow.  This in turn
called find_stowed_path() which since 40a0807185 was not allowing for
the possibility that it could be passed a symlink *not* owned by Stow
with an absolute target and consequently emitting an erroneous warning.

So remove this erroneous warning, and refactor find_stowed_path()
to use two new helper functions for detecting stow directories:
link_dest_within_stow_dir() and find_containing_marked_stow_dir().
Also refactor the logic within each to be simpler and more accurate,
and add more test cases to the corresponding parts of the test suite.

Fixes #65.
Closes #103.

https://github.com/aspiers/stow/issues/65
2024-03-31 14:03:47 +01:00
Adam Spiers
877fc0ce7e cleanup_invalid_links: add test for non-cleanup of an unowned link 2024-03-31 12:24:02 +01:00
Adam Spiers
08b06ccb40 t/cleanup_invalid_links: divide into subtests
This makes the code and test output both more legible.
2024-03-31 12:16:42 +01:00
Adam Spiers
a2beb7b371 Separate treatment of .stow and .nonstow marked dirs
Placing a .stow file in a directory tells Stow that this directory
should be considered a Stow directory.  This is already
well-documented.

There was an undocumented and slightly broken feature where placing a
.nonstow file in a directory was treated in exactly the same way.  The
intention was for .nonstow to cause Stow to skip stowing into and
unstowing from that directory and any of its descendants.  However, it
also caused Stow to consider symlinks into any of those directories as
owned by Stow, even though that was clearly not the intention.  So
separate treatment of .stow and .nonstow markers, so that while both
provide protection against Stow stowing and unstowing, only .stow
affects the symlink ownership logic in find_stowed_path() and
marked_stow_dir().

Probably no one uses the undocumented .nonstow feature, so it may make
sense to remove this in future.
2024-03-31 12:15:53 +01:00
Adam Spiers
4d711fc4ac Make join_paths correctly handle absolute paths
Previously join_paths() was incorrectly handling absolute paths, for
example join_paths('a/b', '/c/d') would return 'a/b/c/d' rather than
'/c/d'.  This was a problem when following a symlink in
find_stowed_path(), because if the symlink was not owned by Stow and
pointed to an absolute path, find_stowed_path() might accidentally
deem the link owned by Stow, if c/d was a valid path relative to the
current directory.
2024-03-31 12:02:58 +01:00
Adam Spiers
d1480195b6 Move setting of cperl-indent-level to .dir-locals.el
This removes duplication.
2024-03-31 12:02:58 +01:00
Adam Spiers
1657c5b772 t/find_stowed_path.t: Add a couple of missing spaces 2024-03-10 17:40:17 +00:00
Adam Spiers
9db0de3005 Add some helpful comments
Explain a few things in preparation for a bugfix.
2024-03-10 17:40:17 +00:00
Adam Spiers
457fa98527 dotfiles.t: improve comment descriptions 2024-03-09 17:57:04 +00:00
Adam Spiers
5d4e68291e testutil: Add sanity check for cwd 2024-03-09 17:56:57 +00:00
Adam Spiers
cb4b0c6a9a Remove trailing whitespace 2024-03-09 17:56:41 +00:00
Adam Spiers
a426a5979d testutil: clarify reason for default paths in new_Stow() 2024-03-09 17:56:29 +00:00
ATuinDev
056d648d53
Add more tests for testing directories in dotfiles.t 2020-05-25 22:23:23 +02:00
Adam Spiers
b6ee2d10d6 cli.t: test with the right Perl executable
t/cli.t calls scripts which run with the first perl found in the
user's PATH (usually the system perl), not with the perl used for the
build, as reported here:

    https://rt.cpan.org/Ticket/Display.html?id=129944

Thanks to Slaven Rezic for spotting this and reporting it!
2019-07-15 16:12:26 -04:00
Adam Spiers
9ce10eb3b1 Remove dependencies on Hash::Merge and Clone::Choose
stow 2.3.0 added external runtime dependencies on Hash::Merge and
Clone::Choose. Historically stow hasn't had runtime dependencies other
than Perl itself, which is a useful property if you're managing the
installation of Perl using stow; the bootstrapping instructions in
stow's manual would need updating to describe how to install these two
modules (and any dependencies they have now or in the future) as well.

However, Hash::Merge is much more general than stow actually needs, so
replace the merge() call with a few lines of equivalent code -- this
avoids the external dependencies, and is clearer than the merge()
call.

Many thanks to Adam Sampson for this patch:

https://lists.gnu.org/archive/html/bug-stow/2019-06/msg00001.html
2019-06-29 13:42:19 +01:00
Adam Spiers
74f0182834 Add separate tests for .stowrc from $HOME and $PWD
.stowrc can be obtained from $HOME and/or the current working
directory; however only the $HOME case was tested before, because
during tests Stow was being run from $HOME.

So switch $TEST_DIR to an absolute path, create a new run_from/
subdirectory, and chdir to that before invoking any Stow code.  This
allows us to test the behaviour of .stowrc in $HOME and run_from/
separately.
2019-06-28 16:39:53 +01:00
Adam Spiers
ac74d75a98 Split up is_deeply() assertions in find_stowed_path.t
This makes the tests and any failures more readable.
2019-06-28 15:24:50 +01:00
Adam Spiers
e4f6a6742b Add examples of how to enable debugging in tests 2019-06-28 15:24:50 +01:00
Adam Spiers
6233298a91 Replace testutil::make_dir with File::Path::make_path
No need for a custom function here.
2019-06-28 01:02:48 +01:00
Adam Spiers
ba48fd3908 Rename $OUT_DIR to $TEST_DIR
This is a more accurate reflection of what it is.
2019-06-28 00:53:12 +01:00
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