Commit graph

60 commits

Author SHA1 Message Date
Ben Wiederhake
f1a683d45f mktemp+tests: remove unused spell-checker:disable 2024-04-30 18:28:20 +02:00
Sylvestre Ledru
ee198126af mktemp: adjust the error message to match 9.5 2024-03-29 21:52:48 +01:00
Sylvestre Ledru
bfca6bf70f Add license headers on all files 2023-08-21 10:49:27 +02:00
Terts Diepraam
964b1d6e10 mktemp: fix both_tmpdir_flags_present test on windows 2023-07-18 12:46:05 +02:00
Thayne McCombs
536db164bf Fix mktemp test for windows 2023-07-18 12:46:05 +02:00
Thayne McCombs
6262a3e9d9 Add tests for mktemp tmpdir flags
And set overrides_with for tmpdir flags.

Tests were copied from #4275

Co-authored-by: David Matos <davidmatos06@gmail.com>
2023-07-18 12:46:05 +02:00
Daniel Hofstetter
698fafad68 mktemp: prioritize TMPDIR over -p when using -t 2023-05-20 08:02:37 +02:00
Daniel Hofstetter
a01dc20c30 mktemp: remove TEST_TEMPLATE9 2023-05-19 10:42:52 +02:00
Daniel Hofstetter
5be5f85043 mktemp: simplify test_default_missing_value() 2023-05-19 10:38:04 +02:00
Sylvestre Ledru
cd189b2391 Fix mktemp -t -p ~/projects/playground foo.XXXX 2023-05-18 11:08:55 +02:00
Sylvestre Ledru
35b5fd6a40 mktemp -t foo.XXXX should create in TMPDIR 2023-05-18 11:08:55 +02:00
Sylvestre Ledru
0f268428fe
Merge pull request #4379 from ZauJulio/hotfix-mktemp
mktemp: fix PrefixContainsDirSeparator verification
2023-04-26 18:28:56 +02:00
Sylvestre Ledru
6a69894f60
Merge pull request #4297 from jfinkels/mktemp-uncomment-fixed-test
mktemp: uncomment fixed test case
2023-03-27 21:11:29 +02:00
Miles Liu
81a4e8fb7d
Remove keep_env from the test framework 2023-03-24 14:25:37 +08:00
Daniel Hofstetter
6988eb7ec6 tests: expand wildcard imports 2023-03-20 15:32:35 +01:00
Jeffrey Finkelstein
1de1a84ed2 mktemp: uncomment fixed test case
Uncomment a test case fixed by commit
53c4b0b81e (pull request
https://github.com/uutils/coreutils/pull/4091).
2023-03-19 13:20:10 -04:00
ZauJulio
b94a0d2ebe
mktemp: fix test fmt 2023-03-02 15:30:55 -03:00
ZauJulio
e9bd69e051
mktemp: fix test_prefix_template_separator adding -p param 2023-03-01 15:45:41 -03:00
ZauJulio
9b4fb0cb6e
mktemp: add tests UNIX and POSIX to check path in prefix 2023-02-28 12:38:18 -03:00
ZauJulio
dc1fd027a6
mktemp: fix fmt of test_prefix_template_separator 2023-02-25 18:35:35 -03:00
Zaú Júlio
59490e4a17
Merge branch 'main' into hotfix-mktemp 2023-02-22 20:23:36 -03:00
ZauJulio
3d2f3fc5b1
mktemp: add test to . in template prefix 2023-02-22 20:22:16 -03:00
Joining7943
1c230fd779 tests/util: Refactor UCommand and TestScenario.
Summary of changes in UCommand:
* Extend UCommand by builder methods and simplify methods in TestScenario
* Simplify code structures where possible. Add documentation.
* Store bin_path as PathBuf and util_name as String in all structs
* Remove UCommand::util and make bin_path, temp_dir private
* Rename UCommand::with_limit -> UCommand::limit

Summary of changes in TestScenario:
* Rename some parameters in TestScenario methods to be more descriptive
* Remove ucmd_keepenv, cmd_keepenv from TestScenario. Use UCommand::keep_env instead.
2023-02-18 23:38:20 +01:00
Daniel Hofstetter
f6b646e4e5 clippy: fix warnings introduced with Rust 1.67.0 2023-01-27 17:37:56 +01:00
Roy Ivy III
d78e1e7399 tests: revise/standardize usage error testing (for dd, install, mktemp, rm, seq, and touch) 2023-01-13 22:14:48 -06:00
David Matos
53c4b0b81e mktemp: allow default missing value 2022-11-03 08:27:08 +01:00
Jeffrey Finkelstein
60ca9a03bb mktemp: add message for directory not found
Add special handling in `mktemp` for when the directory that will
contain the temporary file is not found. This situation now produces
the message

    mktemp: failed to create file via template 'XXX': No such file or directory

to match the behavior of GNU mktemp.
2022-09-21 21:26:39 -04:00
Jeffrey Finkelstein
7b35749ea6 mktemp: match GNU error message on too many args
Update the usage message when too many template arguments are given on
the command line to match that of GNU mktemp:

    mktemp: too many templates
    Try 'mktemp --help' for more information.

This fixes the test case `too-many` in the GNU test suite file
`tests/misc/mktemp.pl`.
2022-09-21 10:02:56 +02:00
Jeffrey Finkelstein
61345cbdc9 mktemp: respect TMPDIR environment variable
Change `mktemp` so that it respects the value of the `TMPDIR`
environment variable if no directory is otherwise specified in its
arguments. For example, before this commit

    $ TMPDIR=. mktemp
    /tmp/tmp.WDJ66MaS1T

After this commit,

    $ TMPDIR=. mktemp
    ./tmp.h96VZBhv8P

This matches the behavior of GNU `mktemp`.
2022-09-13 19:38:25 -04:00
Junji Wei
1ba0bfc67a mktemp: respect POSIXLY_CORRECT env var when parsing args
Signed-off-by: Junji Wei <harukawei99@gmail.com>
2022-06-09 20:51:51 +08:00
Jeffrey Finkelstein
6da070cdd3 mktemp: error on empty --suffix in some situations
Make `mktemp` exit with an error if the `--suffix` option is the empty
string and the template argument does not end in an "X". Previously,
the program succeeded.

Before this commit,

    $ mktemp --suffix= aXXXb
    apBEb

After this commit,

    $ mktemp --suffix= aXXXb
    mktemp: with --suffix, template 'aXXXb' must end in X
2022-06-06 21:24:59 -04:00
Sylvestre Ledru
3f203c7ab1
Merge pull request #3586 from jfinkels/mktemp-multiple-x-sequences
mktemp: only replace last contiguous block of Xs
2022-06-06 10:06:44 +02:00
Jeffrey Finkelstein
a9e008f230 mktemp: add test for combining --tmpdir, subdir
Add a unit test for combining the directory given in `--tmpdir` with
any subdirectory structure appearing in the prefix of the template
string. For example,

    $ mktemp --tmpdir=a b/cXXX
    a/b/cNqJ

This behavior is currently working, but a unit test was missing.
2022-06-01 18:22:17 -04:00
Jeffrey Finkelstein
cff7833bf6 mktemp: only replace last contiguous block of Xs
Fix a bug in which `mktemp` would replace everything in the template
argument from the first 'X' to the last 'X' with random bytes, instead
of just replacing the last contiguous block of 'X's.

Before this commit,

    $ mktemp XXX_XXX
    2meCpfM

After this commit,

    $ mktemp XXX_XXX
    XXX_Rp5

This fixes test cases `suffix2f` and `suffix2d` in
`tests/misc/mktemp.pl` in the GNU coreutils test suite.
2022-06-01 18:21:21 -04:00
Jeffrey Finkelstein
43e9fb73b1 mktemp: simplify file path parameter logic
Simplify the logic of computing the file path parameters (the
directory, prefix, suffix, and number of random characters) for the
temporary file created by `mktemp`. This commits adds an `Options`
struct as a layer of indirection between the application logic and
`clap`, and a `Params` struct whose associated function is responsible
for determining the file path parameters from the `Options`. This is
an improvement because the previous code had some logic for
determining file path parameters in one place and some in another
place.
2022-05-31 19:35:01 -04:00
Jeffrey Finkelstein
dfc1c8a2dd mktemp: exit with status 1 on usage errors 2022-05-30 09:30:47 -04:00
Sylvestre Ledru
fa577603c2
Merge pull request #3471 from 353fc443/mktemp-set-dir-mode
mktemp: change directory permission after creation
2022-05-25 14:56:45 +02:00
Jeffrey Finkelstein
35fb4e6ea1 mktemp: include suffix in error message
Include the suffix in the error message produced by `mktemp` when
there are too few Xs in the template. Before this commit,

    $ mktemp --suffix=X aXX
    mktemp: too few X's in template 'aXX'

After this commit,

    $ mktemp --suffix=X aXX
    mktemp: too few X's in template 'aXXX'

This matches the behavior of GNU `mktemp`.
2022-05-21 21:59:06 -04:00
Sylvestre Ledru
d92107362b
Merge pull request #3521 from jfinkels/mktemp-tmpdir-absolute-path
mktemp: correct error message on absolute path
2022-05-21 09:40:33 +02:00
Jeffrey Finkelstein
6260333415 mktemp: fix error msg when suffix has path sep.
Correct the error message when the template argument contains a path
separator in its suffix. Before this commit:

    $ mktemp aXXX/b
    mktemp: too few X's in template 'b'

After this commit:

    $ mktemp aXXX/b
    mktemp: invalid suffix '/b', contains directory separator

This error message is more appropriate and matches the behavior of GNU
mktemp.
2022-05-19 15:46:04 +02:00
Jeffrey Finkelstein
8a941db20a mktemp: correct error message on absolute path
Correct the error message produced by `mktemp` when `--tmpdir` is
given and the template is an absolute path:

    $ mktemp --tmpdir=a /XXX
    mktemp: invalid template, '/XXX'; with --tmpdir, it may not be absolute
2022-05-17 20:16:47 -04:00
353fc443 aka Seagull
2086d04996
Merge branch 'main' into mktemp-set-dir-mode 2022-05-17 04:58:03 +00:00
353fc443
2383950403
mktemp: Added tests for checking directory permissions 2022-05-16 18:05:59 +00:00
Jeffrey Finkelstein
2874f18950 mktemp: error on path separator in template prefix
Correct the error that arises from a path separator in the prefix
portion of a template argument provided to `mktemp`. Before this
commit, the error message was incorrect:

    $ mktemp -t a/bXXX
    mktemp: failed to create file via template 'a/bXXX': No such file or directory (os error 2) at path "/tmp/a/bege"

After this commit, the error message is correct:

    $ mktemp -t a/bXXX
    mktemp: invalid template, 'a/bXXX', contains directory separator

The code was failing to check for a path separator in the prefix
portion of the template.
2022-05-11 12:59:44 +02:00
Jeffrey Finkelstein
08816a4f05 fixup! mktemp: respect path given in template argument 2022-05-01 16:51:25 -04:00
Jeffrey Finkelstein
aa6aefbd64 mktemp: respect path given in template argument
Fix a bug in `mktemp` where it was not respecting the path given by
the positional argument. Previously, it would place the temporary file
whose name is induced by a given template in the `/tmp` directory,
like this:

    $ mktemp XXX
    /tmp/LJr

    $ mktemp d/XXX
    /tmp/d/IhS

After this commit, it respects the directory given in the template
argument:

    $ mktemp XXX
    LJr

    $ mktemp d/XXX
    d/IhS

Fixes #3440.
2022-05-01 13:03:18 -04:00
Terts Diepraam
73a7ead857 mktemp: adapt to standardized error handling 2021-06-28 13:55:55 +02:00
Michael Debertol
622504467f mktemp: note that windows uses a different env var for tmpdir
On windows `std::env::temp_dir` uses the `TMP` environment variable
instead of `TMPDIR`.
2021-06-22 17:44:45 +02:00
Michael Debertol
e5a7bcbb9d tests: keep env vars for the temporary directory
On some Windows machines this would otherwise cause `std::env::temp_dir`
to fall back to a path that is not writeable (C:\\Windows).
Since by default integration tests don't inherit env vars from the
parent, we have to override this in some cases.
2021-06-22 17:43:46 +02:00
Roy Ivy III
3f35e0a421 refactor ~ cargo make format 2021-05-31 08:23:58 -05:00