GithubHelp home page GithubHelp logo

briandfoy / test-file Goto Github PK

View Code? Open in Web Editor NEW
13.0 6.0 16.0 458 KB

(Perl) Check file attributes

Home Page: https://metacpan.org/pod/Test::File

License: Other

Perl 95.21% XS 4.79%
perl testing perl-module

test-file's Introduction

Coverage Status

The Test::File module

This is the README for the Test::File Perl module, which provides convenience test functions to check file attributes and data in a Test::More fashion.

You're probably looking at this because you don't know where else to find what you're looking for. Read this once and you might never have to read one again for any Perl module.

Documentation

To read about Test::File, look at the embedded documentation in the module itself. Inside the distribution, you can format it with perldoc:

% perldoc lib/Test/File.pm

If you have already installed the module, you can specify the module name instead of the file location:

% perldoc Test::File

You can read the documentation and inspect the meta data at MetaCPAN.

The standard module documentation has example uses in the SYNOPSIS section, but you can also look in the examples/ directory (if it's there), or look at the test files in t/.

Installation

You can install this module with a CPAN client, which will resolve and install the dependencies:

% cpan Test::File
% cpanm Test::File

You can also install directly from the distribution directory, which will also install the dependencies:

% cpan .
% cpanm .

You could install just this module manually:

% perl Makefile.PL
% make
% make test
% make install

You probably don't want to do that unless you're fiddling with the module and only want to run the tests without installing anything.

Source location

The meta data, such as the source repository and bug tracker, is in Makefile.PL or the META.* files it creates. You can find that on those CPAN web interfaces, but you can also look at files directly in the source repository:

If you find a problem, file a ticket in the issue tracker:

Getting help

Although I'm happy to hear from module users in private email, that's the best way for me to forget to do something.

Besides the issue trackers, you can find help at Perlmonks or Stackoverflow, both of which have many competent Perlers who can answer your question, almost in real time. They might not know the particulars of this module, but they can help you diagnose your problem.

You might like to read brian's Guide to Solving Any Perl Problem.

You should have received a LICENSE file, but the license is also noted in the module files. About the only thing you can't do is pretend that you wrote code that you didn't.

Good luck!

Enjoy,

brian d foy, [email protected]

test-file's People

Contributors

barefootcoder avatar briandfoy avatar chorny avatar grinnz avatar haarg avatar hakonhagland avatar ioanrogers avatar jddurand avatar jraspass avatar nawglan avatar rjbs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

test-file's Issues

symlink_target_is_absolute_ok

This is commented out in the code and displays in the docs in MetaCPAN. IS that =pod right before the definition intentional.

Tests fails on Windows 10, MSYS2

System: Windows 10, MSYS2, perl version 5.32.0 :

$ cpanm -v Test::File
cpanm (App::cpanminus) 1.7044 on perl 5.032000 built for x86_64-msys-thread-multi
Work directory is /home/hakon/.cpanm/work/1595166881.25026
You have make /usr/bin/make
You have LWP 6.46
You have /usr/bin/tar: tar (GNU tar) 1.32
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by John Gilmore and Jay Fenlason.
Searching Test::File () on cpanmetadb ...
--> Working on Test::File
Fetching http://www.cpan.org/authors/id/B/BD/BDFOY/Test-File-1.443.tar.gz ... OK
Unpacking Test-File-1.443.tar.gz
Test-File-1.443/
Test-File-1.443/Changes
Test-File-1.443/examples/
Test-File-1.443/INSTALL.SKIP
Test-File-1.443/lib/
Test-File-1.443/LICENSE
Test-File-1.443/Makefile.PL
Test-File-1.443/MANIFEST
Test-File-1.443/MANIFEST.SKIP
Test-File-1.443/META.json
Test-File-1.443/META.yml
Test-File-1.443/README.pod
Test-File-1.443/t/
Test-File-1.443/xt/
Test-File-1.443/xt/changes.t
Test-File-1.443/t/dm_skeleton.t
Test-File-1.443/t/file_contains.t
Test-File-1.443/t/file_contains_encoded.t
Test-File-1.443/t/file_contains_utf8.t
Test-File-1.443/t/file_mtime.t
Test-File-1.443/t/file_sizes.t
Test-File-1.443/t/line_counters.t
Test-File-1.443/t/link_counts.t
Test-File-1.443/t/links.t
Test-File-1.443/t/load.t
Test-File-1.443/t/normalize.t
Test-File-1.443/t/obviously_non_multi_user.t
Test-File-1.443/t/owner.t
Test-File-1.443/t/pod.t
Test-File-1.443/t/pod_coverage.t
Test-File-1.443/t/rt/
Test-File-1.443/t/setup_common
Test-File-1.443/t/test_dirs.t
Test-File-1.443/t/test_files.t
Test-File-1.443/t/test_manifest
Test-File-1.443/t/win32.t
Test-File-1.443/t/rt/30346.t
Test-File-1.443/lib/Test/
Test-File-1.443/lib/Test/File.pm
Test-File-1.443/examples/README
Entering Test-File-1.443
Checking configure dependencies from META.json
Checking if you have File::Spec::Functions 0 ... Yes (3.78)
Checking if you have ExtUtils::MakeMaker 6.64 ... Yes (7.44)
Running Makefile.PL
Configuring Test-File-1.443 ... Checking if your kit is complete...
Looks good
WARNING: Older versions of ExtUtils::MakeMaker may errantly install README.pod as part of this distribution. It is recommended to avoid using this path in CPAN modules.
Generating a Unix-style Makefile
Writing Makefile for Test::File
Writing MYMETA.yml and MYMETA.json
OK
Checking dependencies from MYMETA.json ...
Checking if you have Test::utf8 0 ... Yes (1.02)
Checking if you have Test::Builder::Tester 1.04 ... Yes (1.302175)
Checking if you have Test::More 0.95 ... Yes (1.302175)
Checking if you have Test::Builder 1.001006 ... Yes (1.302175)
Building and testing Test-File-1.443 ... cp lib/Test/File.pm blib/lib/Test/File.pm
Manifying 1 pod document
PERL_DL_NONLAZY=1 "/usr/bin/perl.exe" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/dm_skeleton.t ............... 1/?     # MSWin32
    # Looks like you planned 0 tests but ran 2.
    # Looks like you planned 0 tests but ran 2.
t/dm_skeleton.t ............... ok
t/file_contains.t ............. 1/?
#   Failed test at t/file_contains.t line 37.
# STDERR is:
# > #   Failed test 'not_readable contains (?^:(?mx:^ xxxxxxxxxxx    $))'
# > #   at t/file_contains.t line 36.
# > #                   ''
# > #     doesn't match '(?^:(?mx:^ xxxxxxxxxxx    $))'
# not:
# > # File [not_readable] is not readable!
# > /#\s+Failed\ test.*?\n?.*?at\ t\/file_contains\.t line 36.*\n?/
# >
# >
# as expected

#   Failed test at t/file_contains.t line 65.
# STDOUT is:
# > ok 1 - not_readable doesn't contain (?^:(?mx:^ xxxxxxxxxxxxxxxxxxxx $))
# not:
# > not ok 1 - not_readable doesn't contain (?^:(?mx:^ xxxxxxxxxxxxxxxxxxxx $))
# as expected
# STDERR is:
# >
# >
# not:
# > # File [not_readable] is not readable!
# > /#\s+Failed\ test.*?\n?.*?at\ t\/file_contains\.t line 64.*\n?/
# as expected

#   Failed test at t/file_contains.t line 99.
# STDOUT is:
#   not ok 1 - not_readable contains (?^:(?mx:^ xxxxxxxxxxx    $))
# > not ok 2 - not_readable contains (?^:(?mx:^ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    $))
# not:
#   not ok 1 - not_readable contains (?^:(?mx:^ xxxxxxxxxxx    $))
# >
# as expected
# STDERR is:
# > #   Failed test 'not_readable contains (?^:(?mx:^ xxxxxxxxxxx    $))'
# > #   at t/file_contains.t line 98.
# > #                   ''
# > #     doesn't match '(?^:(?mx:^ xxxxxxxxxxx    $))'
# > #   Failed test 'not_readable contains (?^:(?mx:^ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    $))'
# > #   at t/file_contains.t line 98.
# > #                   ''
# > #     doesn't match '(?^:(?mx:^ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    $))'
# not:
# > # File [not_readable] is not readable!
# > /#\s+Failed\ test.*?\n?.*?at\ t\/file_contains\.t line 98.*\n?/
# >
# >
# >
# >
# >
# >
# as expected

#   Failed test at t/file_contains.t line 134.
# STDOUT is:
# > ok 1 - not_readable doesn't contain (?^:(?mx:^ xxxxxxxxxxxxxxxxxxxx $))
# > ok 2 - not_readable doesn't contain (?^:(?mx:^ xxxxxxxxxxxxxxxxxxxx $))
# not:
# > not ok 1 - not_readable doesn't contain (?^:(?mx:^ xxxxxxxxxxxxxxxxxxxx $))
# >
# as expected
# STDERR is:
# >
# >
# not:
# > # File [not_readable] is not readable!
# > /#\s+Failed\ test.*?\n?.*?at\ t\/file_contains\.t line 133.*\n?/
# as expected
t/file_contains.t ............. Failed 4/23 subtests
t/file_contains_encoded.t ..... ok
t/file_contains_utf8.t ........ ok
t/file_mtime.t ................ ok
t/file_sizes.t ................ 1/?     # Looks like you planned 0 tests but ran 5.
    # Looks like you planned 0 tests but ran 7.
    # Looks like you planned 0 tests but ran 6.
t/file_sizes.t ................ ok
t/line_counters.t ............. 1/?     # Looks like you planned 0 tests but ran 5.
    # Looks like you planned 0 tests but ran 6.
    # Looks like you planned 0 tests but ran 4.
    # Looks like you planned 0 tests but ran 4.
t/line_counters.t ............. ok
t/link_counts.t ............... 1/?     # Looks like you planned 0 tests but ran 2.
    # Looks like you planned 0 tests but ran 3.
t/link_counts.t ............... ok
t/links.t ..................... 1/?     # Looks like you planned 0 tests but ran 8.
t/links.t ..................... 7/?     # Looks like you planned 0 tests but ran 12.
    # Looks like you planned 0 tests but ran 7.
    # Looks like you planned 0 tests but ran 2.
    # Looks like you planned 0 tests but ran 1.
    # Looks like you planned 0 tests but ran 1.
t/links.t ..................... ok
t/load.t ...................... ok
t/normalize.t ................. ok
t/obviously_non_multi_user.t .. ok
t/owner.t ..................... ok
t/pod.t ....................... ok
t/pod_coverage.t .............. skipped: Test::Pod::Coverage required for testing POD
t/test_dirs.t ................. ok
t/test_files.t ................ 1/?
#   Failed test at t/test_files.t line 33.
# STDOUT is:
# > not ok 1 - writeable is not readable
# not:
# > ok 1 - writeable is not readable
# as expected
# STDERR is:
# > # File [writeable] is readable!
# > #   Failed test 'writeable is not readable'
# > #   at t/test_files.t line 32.
# not:
# >
# >
# >
# as expected

#   Failed test at t/test_files.t line 54.
# STDOUT is:
# > not ok 1 - executable is executable
# not:
# > ok 1 - executable is executable
# as expected
# STDERR is:
# > # File [executable] is not executable!
# > #   Failed test 'executable is executable'
# > #   at t/test_files.t line 53.
# not:
# >
# >
# >
# as expected

#   Failed test at t/test_files.t line 72.
# STDOUT is:
# > not ok 1 - executable mode is 0100
# not:
# > ok 1 - executable mode is 0100
# as expected
# STDERR is:
# > # File [executable] mode is not 0100!
# > #   Failed test 'executable mode is 0100'
# > #   at t/test_files.t line 71.
# not:
# >
# >
# >
# as expected

#   Failed test at t/test_files.t line 81.
# STDOUT is:
# > not ok 1 - executable mode has all bits of 0100
# not:
# > ok 1 - executable mode has all bits of 0100
# as expected
# STDERR is:
# > # File [executable] mode is missing component 0100!
# > #   Failed test 'executable mode has all bits of 0100'
# > #   at t/test_files.t line 80.
# not:
# >
# >
# >
# as expected

#   Failed test at t/test_files.t line 98.
# STDERR is:
# > # File [executable] mode is missing component 0111!
#   #   Failed test 'executable mode has all bits of 0111'
#   #   at t/test_files.t line 96.
# not:
# > # File [executable] mode is missing component 0011!
#   #   Failed test 'executable mode has all bits of 0111'
#   #   at t/test_files.t line 96.
# as expected

#   Failed test at t/test_files.t line 133.
# STDOUT is:
# > ok 1 - executable mode has no bits of 0111
# not:
# > not ok 1 - executable mode has no bits of 0111
# as expected
# STDERR is:
# >
# >
# >
# not:
# > # File [executable] mode has forbidden component 0100!
# > #   Failed test 'executable mode has no bits of 0111'
# > #   at t/test_files.t line 131.
# as expected

#   Failed test at t/test_files.t line 142.
# STDOUT is:
# > not ok 1 - readable mode is 0400
# not:
# > ok 1 - readable mode is 0400
# as expected
# STDERR is:
# > # File [readable] mode is not 0400!
# > #   Failed test 'readable mode is 0400'
# > #   at t/test_files.t line 141.
# not:
# >
# >
# >
# as expected

#   Failed test at t/test_files.t line 160.
# STDOUT is:
# > not ok 1 - writeable mode is 0200
# not:
# > ok 1 - writeable mode is 0200
# as expected
# STDERR is:
# > # File [writeable] mode is not 0200!
# > #   Failed test 'writeable mode is 0200'
# > #   at t/test_files.t line 159.
# not:
# >
# >
# >
# as expected
t/test_files.t ................ Failed 8/23 subtests
t/win32.t ..................... 1/?     # Looks like you planned 0 tests but ran 4.
t/win32.t ..................... ok

Test Summary Report
-------------------
t/file_contains.t           (Wstat: 0 Tests: 23 Failed: 4)
  Failed tests:  8, 12, 17, 22
t/test_files.t              (Wstat: 0 Tests: 23 Failed: 8)
  Failed tests:  9, 12, 14-16, 19-20, 22
Files=18, Tests=190, 19 wallclock secs ( 0.12 usr  0.09 sys +  2.79 cusr  3.98 csys =  6.99 CPU)
Result: FAIL
Failed 2/18 test programs. 12/190 subtests failed.
make: *** [Makefile:900: test_dynamic] Error 255
FAIL
! Installing Test::File failed. See /home/hakon/.cpanm/work/1595166881.25026/build.log for details. Retry with --force to force install it.

can not install using CPANPLUS 0.9160, perl 5.10.1

Installing Test::File (1.442)
[MSG] Using cached file '/home/martin/.cpanplus/authors/id/B/BD/BDFOY/CHECKSUMS' on disk; ttl (3600s) is not exceeded
[MSG] Checksum matches for 'Test-File-1.442.tar.gz'
[MSG] Extracting 'Test-File-1.442.tar.gz'
[MSG] Extracted 'Test::File' to '/home/martin/.cpanplus/5.10.1/build/aoDF6d2Ga3/Test-File-1.442'
==> MISSING Signature file! <==
Running [/usr/bin/perl -e use strict; BEGIN { my $old = select STDERR; $|++; select $old; $|++; $0 = shift(@argv); my $rv = do($0); die $@ if $@; } /home/martin/.cpanplus/5.10.1/build/aoDF6d2Ga3/Test-File-1.442/Makefile.PL]...
Use of uninitialized value $makestat in numeric lt (<) at /usr/share/perl5/CPANPLUS/Dist/MM.pm line 413.
Use of uninitialized value $makestat in subtraction (-) at /usr/share/perl5/CPANPLUS/Dist/MM.pm line 414.
[ERROR] File '/home/martin/.cpanplus/5.10.1/build/aoDF6d2Ga3/Test-File-1.442/Makefile' is not readable or does not exist

Key 'file' (/home/martin/.cpanplus/5.10.1/build/aoDF6d2Ga3/Test-File-1.442/Makefile) is of invalid type for 'CPANPLUS::Dist::MM::_find_prereqs' provided by CPANPLUS::Dist::MM::prepare at /usr/share/perl5/CPANPLUS/Module.pm line 823.
[ERROR] Unable to scan '/home/martin/.cpanplus/5.10.1/build/aoDF6d2Ga3/Test-File-1.442/Makefile' for prereqs

[ERROR] Unable to create a new distribution object for 'Test::File' -- cannot continue

Request for feature: file_contains_ok

Okay, here's the next thing I need. Something like this:

file_contains_ok($myfile, qw/^\d{8}:/m, 'file has a datestamped line in the expected format');

IOW, it slurps in the file contents and checks it against the supplied regex. Obviously no good for very large files, but that's okay in my particular use case. Since I'm already in the groove with the other changes, I'd just as soon crank it out now, if you agree it would be a useful change.

Alternate name suggestion: file_like ... I think I might like that better, actually. Your call. (Or, another thought: file_contents_like. Whichever one you think is best.)

Does this sound good?

Don't allow plain file tests to run on non-plain files

Imagine my surprise when file_not_empty_ok() and friends return ok on a directory:

% perl -MTest::File -e 'file_not_empty_ok("/etc")'
ok 1 - /etc is not empty
# Tests were run but no plan was declared and done_testing() was not seen.

A perusal of File.pm does indeed show it doesn't actually test to make sure the file tests are actually against .... files.

Failed test 'file_mtime_lt_ok success works'

In rare cases, the test suite may fail like this:

#   Failed test 'file_mtime_lt_ok success works'
#   at t/file_mtime.t line 48.
# STDOUT is:
#   ok 1 - file_mtime_lt_ok success
# > ok 2 - mtime_file mtime less than unix timestamp 1644348548
# not:
#   ok 1 - file_mtime_lt_ok success
# > ok 2 - mtime_file mtime less than unix timestamp 1644348547
# as expected
t/file_mtime.t ................ 
Failed 1/17 subtests 

Probably a race condition --- time() is called here three times, but there's no guarantee that the clock is returning the same epoch on every call. This can be easily demonstrated by adding an artitifical sleep like this:

--- a/t/file_mtime.t
+++ b/t/file_mtime.t
@@ -43,6 +43,7 @@ test_test( 'file_mime_age_ok failure works' );
 # file_mtime_lt_ok
 test_out( 'ok 1 - file_mtime_lt_ok success' );
 test_out( 'ok 2 - mtime_file mtime less than unix timestamp ' . time() );
+sleep 1;
 file_mtime_lt_ok( $mtime_file, time(), 'file_mtime_lt_ok success' );
 file_mtime_lt_ok( $mtime_file, time() );
 test_test( 'file_mtime_lt_ok success works' );

[PATCH] After the removal of cwd from @INC t/setup_common is not found.

In Debian we are currently applying the following patch to Test-File.
We thought you might be interested in it too.

Description: After the removal of cwd from @INC t/setup_common is not found.
 Change the requires in the tests to use ./t/setup_common.
Origin: vendor
Bug-Debian: https://bugs.debian.org/837237
Author: gregor herrmann <[email protected]>
Last-Update: 2016-09-10

The patch is tracked in our Git repository at
https://anonscm.debian.org/cgit/pkg-perl/packages/libtest-file-perl.git/plain/debian/patches/t_setup_common_require_cwd.patch

Thanks for considering,
gregor herrmann,
Debian Perl Group

Tests fail on some cygwin systems

On some cygwin installations the test suite fails. Here's a fail report at CPAN Testers: http://www.cpantesters.org/cpan/report/05b8e62e-a914-1014-a63b-77b394f39f87

I stumbled over the problem while running tests on appveyor using cygwin's perl:
https://ci.appveyor.com/project/eserte/slay-makefile/build/1.0.16#L1099

A guess: it seems that some (or all?) of the failing tests are about unreadable files. These are skipped if uid==0. Windows (and cygwin) systems behave different for unreadable files. It's probably just luck that $< is always zero on Windows, and maybe most of the time also zero on cygwin systems, but not always, and so these tests are skipped on most installations.

Check file contents in utf8 or other encoding

Hi,

I need to test some files with utf8 content and I thought I should get your opinion on my intended solution before coding it.

file_contains_utf8_like ( FILENAME, PATTERN [, NAME ] )
file_contains_utf8_unlike ( FILENAME, PATTERN [, NAME ] )
file_contains_encoded_like ( ENCODING, FILENAME, PATTERN [, NAME ] )
file_contains_encoded_unlike ( ENCODING, FILENAME, PATTERN [, NAME ] )

Then call _file_contains with the required encoding and call binmode FH ':encoding($encoding)'

What do you think?

Test::Manifest changes which tests run

Depending on if Test::Manifest is installed, different tests will be run. With Test::Manifest, t/rt/30346.t will run because it is mentioned in t/test_manifest. Without Test::Manifest it will not run because EUMM does not run tests in subdirectories of t/ by default. Test::Manifest will prevent t/file_contains_utf8.t from running because it is not mentioned in the manifest.

Test::File does not account for user names that are only numbers

https://stackoverflow.com/questions/66426472/cannot-install-testfile-on-perl-5-32-0-macos-sierra/66427502#66427502

I'm attempting to install DateTime on my perlbrew 5.32.0, but the tests for its dependency Test::File are failing. The important part is as follows:

t/owner.t ..................... # File [blib] belongs to 703404669 (729761796), not 703404669 (703404669)!
t/owner.t ..................... 1/? 
#   Failed test 'owner_is with text username'
#   at t/owner.t line 99.

#   Failed test 'Intentional owner_isnt failure'
#   at t/owner.t line 146.
# STDOUT is:
# > ok 1 - blib doesn't belong to 703404669
# not:
# > not ok 1 - blib doesn't belong to 703404669
# as expected
# STDERR is:
# > 
# > 
# > 
# not:
# > # File [blib] belongs to 703404669 (729761796)!
# > #   Failed test 'blib doesn't belong to 703404669'
# > #   at t/owner.t line 145.

I got similar errors earlier, but almost every package within my ~/.cpan directory has a blib so I'm not sure which directory cpan is talking about.

My OS is MacOS Sierra 10.12.6 (16G2136)

this error was resolved by Schwern:

The problem is your user name is a number and Test::File does not seem to account for that.

owner_is checks if a file is owned by the given user. It accepts a user name or numeric user ID. If its given a number it assumes it's a numeric ID. If 703404669 is your username it will get confused and use that as a user id. Your user id is really 729761796. 703404669 != 729761796.

Test::File can guard against this ambiguity by verifying with getpwuid and/or checking getpwnam first.

Request for feature: dir_exists_ok

Would you be willing to accept a patch to add a function such as:

dir_exists_ok( FILENAME [, NAME ] )

    Ok if the file exists and is a directory, not ok if the file doesn't exist or exists but isn't a directory.

Could also call it file_is_dir_ok if that's preferable.

I would also be interested in possibly adding something like:

dir_exists_ok( DIRECTORY, FILENAME [, NAME ] )

    Ok if the directory exists and contains a file named FILENAME, not ok otherwise.

but the first one is the main one I need. If you think this is a valuable addition, I'll code it up and issue a pull request.

Would you welcome merge for file_mtime_?_ok

Hi, i was going to start writing some tests that need to confirm that the modified time of a file is within a given timeframe and was curious if you would like them added to File::Test.

If so, suggestions for names? Some options I was thinking about:
file_mtime_age_ok ( FILENAME, SECONDS, [NAME])
takes difference of FILENAME mtime and current system time. Ok if modified <= to SECONDS.

file_mtime_gt_ok ( FILENAME, UNIXTIME, SECONDS, [NAME])
file_mtime_lt_ok ( FILENAME, UNIXTIME, SECONDS, [NAME])

takes the difference FILENAME mtime to the provided UNIXTIME and compares to SECONDS

What do you think?

If you are one to worry about hurt feelings, please don't with me, but If you think there is a better place/name/way to go about doing this, I'd really like to hear! Recommendations for making sure this ports to windows is always welcome as well.

I'll be happy to provide code and tests.

Thanks,

- Mike

t\links.t on systems that support symlink but when current user is not allowed (Windows case)

Using a perl-5.36.0 built myself using cl of Visual Studio 2022 Community Edition, on a Windows 10 box, version 21H1.

I wonder if using the test at https://perldoc.perl.org/functions/symlink is enough. Indeed, on recent versions of Windows 10, this is supported, though not guaranteed to work. My test case is a Windows box symlink seems to be supported:

C:\Users\jddfr\git\perlbuildwindows-build>"C:\perl\5.36.0\bin\MSWin32-x86-multi-thread\perl.exe" -e "symlink('','')"

C:\Users\jddfr\git\perlbuildwindows-build>echo %ERRORLEVEL%
0

but where I am not allowed to do so:

C:\Users\jddfr\git\perlbuildwindows-build>if exist testFile del /Q /F testFile

C:\Users\jddfr\git\perlbuildwindows-build>if exist testFile2 del /Q /F testFile2

C:\Users\jddfr\git\perlbuildwindows-build>echo TEST > testFile

C:\Users\jddfr\git\perlbuildwindows-build>"C:\perl\5.36.0\bin\MSWin32-x86-multi-thread\perl.exe" -e "symlink(shift,shift) || print $!" "testFile" "testFile2"
Operation not permitted

As a consequence t\links.t is likely to fail, at least this is what I observe.

Please note that the suggestion from perlport#symlink seems worth to look at:

C:\Users\jddfr\git\perlbuildwindows-build>"C:\perl\5.36.0\bin\MSWin32-x86-multi-thread\perl.exe" -MWin32 -e "print Win32::IsSymlinkCreationAllowed() ? 'ok' : 'ko'"
ko

All in all here is the full test using cpanm:

Building and testing Test-File-1.992

Microsoft (R) Program Maintenance Utility Version 14.32.31332.0
Copyright (C) Microsoft Corporation. Tous droits réservés.

cp lib/Test/File.pm blib\lib\Test\File.pm

Microsoft (R) Program Maintenance Utility Version 14.32.31332.0
Copyright (C) Microsoft Corporation. Tous droits réservés.

	"C:\perl\5.36.0\bin\MSWin32-x86-multi-thread\perl.exe" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib\lib', 'blib\arch')" t\*.t t\*\*.t
    # MSWin32
t\dm_skeleton.t ............... ok
t\file_contains.t ............. ok
t\file_contains_encoded.t ..... ok
t\file_contains_utf8.t ........ ok
t\file_mtime.t ................ ok
t\file_sizes.t ................ ok
t\line_counters.t ............. ok
t\link_counts.t ............... ok
    # file [readable_sym] does not exist

    #   Failed test 'readable_sym exists'
    #   at t\links.t line 64.
    # file [dangle_sym] does not exist

    #   Failed test 'dangle_sym exists'
    #   at t\links.t line 65.
    # file [dangle_sym] is not a symlink

    #   Failed test 'dangle_sym is a symlink'
    #   at t\links.t line 66.
    # file [dangle_sym] is not a symlink

    #   Failed test 'dangle_sym is a symlink'
    #   at t\links.t line 70.

    #   Failed test at t\links.t line 78.
    # STDOUT is:
    # >     not ok 1 - readable_sym is a symlink
    # not:
    # >     ok 1 - readable_sym is a symlink
    # as expected
    # STDERR is:
    # >     # file [readable_sym] is not a symlink
    # >     #   Failed test 'readable_sym is a symlink'
    # >     #   at t\links.t line 77.
    # not:
    # > 
    # > 
    # > 
    # as expected

    #   Failed test at t\links.t line 82.
    # STDOUT is:
    # >     not ok 1 - This is my test name
    # not:
    # >     ok 1 - This is my test name
    # as expected
    # STDERR is:
    # >     # file [readable_sym] is not a symlink
    # >     #   Failed test 'This is my test name'
    # >     #   at t\links.t line 81.
    # not:
    # > 
    # > 
    # > 
    # as expected

    #   Failed test at t\links.t line 86.
    # STDOUT is:
    # >     not ok 1 - This is my test name
    # not:
    # >     ok 1 - This is my test name
    # as expected
    # STDERR is:
    # >     # file [dangle_sym] is not a symlink
    # >     #   Failed test 'This is my test name'
    # >     #   at t\links.t line 85.
    # not:
    # > 
    # > 
    # > 
    # as expected

    #   Failed test at t\links.t line 90.
    # STDOUT is:
    # >     not ok 1 - This is my test name
    # not:
    # >     ok 1 - This is my test name
    # as expected
    # STDERR is:
    # >     # file [readable_sym] is not a symlink
    # >     #   Failed test 'This is my test name'
    # >     #   at t\links.t line 89.
    # not:
    # > 
    # > 
    # > 
    # as expected

    #   Failed test at t\links.t line 95.
    # STDOUT is:
    # >     not ok 1 - readable_sym is a symlink
    # >     not ok 2 - This is my test name
    # not:
    # >     ok 1 - readable_sym is a symlink
    # >     ok 2 - This is my test name
    # as expected
    # STDERR is:
    # >     # file [readable_sym] is not a symlink
    # >     #   Failed test 'readable_sym is a symlink'
    # >     #   at t\links.t line 93.
    # >     # file [readable_sym] is not a symlink
    # >     #   Failed test 'This is my test name'
    # >     #   at t\links.t line 94.
    # not:
    # > 
    # > 
    # > 
    # > 
    # > 
    # > 
    # as expected
    # Looks like you failed 3 tests of 13.

#   Failed test 'should_work'
#   at t\links.t line 97.

    #   Failed test at t\links.t line 158.
    # STDERR is:
    # >     # file [readable_sym] is not a symlink
    #       #   Failed test 'readable_sym is a symlink'
    #       #   at t\links.t line 157.
    # not:
    # >     # symlink [readable_sym] points to non-existent target [not_there]
    #       #   Failed test 'readable_sym is a symlink'
    #       #   at t\links.t line 157.
    # as expected

    #   Failed test at t\links.t line 168.
    # STDERR is:
    # >     # file [readable_sym] is not a symlink
    # >     #   Failed test 'symlink readable_sym points to not_there'
    # >     #   at t\links.t line 167.
    # > 
    # not:
    # >     #   Failed test 'symlink readable_sym points to not_there'
    # >     #   at t\links.t line 167.
    # >     #        got: readable
    # >     #   expected: not_there
    # as expected
    # Looks like you failed 2 tests of 2.

#   Failed test 'bad_target_does_not_exist'
#   at t\links.t line 170.

    #   Failed test at t\links.t line 182.
    # STDERR is:
    # >     # file [readable_sym] is not a symlink
    # >     #   Failed test 'readable_sym is a symlink'
    # >     #   at t\links.t line 181.
    # > 
    # > 
    # not:
    # >     # symlink [readable_sym] points to
    # >     #          got: readable
    # >     #     expected: writable
    # >     #   Failed test 'readable_sym is a symlink'
    # >     #   at t\links.t line 181.
    # as expected
    # Looks like you failed 1 test of 1.

#   Failed test 'bad_target_does_exists'
#   at t\links.t line 184.

    #   Failed test at t\links.t line 201.
    # STDERR is:
    # >     # file [readable_sym] is not a symlink
    #       #   Failed test 'This is my test name'
    #       #   at t\links.t line 199.
    # >     # file [readable_sym] is not a symlink
    #       #   Failed test 'readable_sym is a symlink'
    #       #   at t\links.t line 200.
    # not:
    # >     # symlink [readable_sym] points to existing file [readable] but shouldn't
    #       #   Failed test 'This is my test name'
    #       #   at t\links.t line 199.
    # >     # symlink [readable_sym] points to existing file [readable] but shouldn't
    #       #   Failed test 'readable_sym is a symlink'
    #       #   at t\links.t line 200.
    # as expected
    # Looks like you failed 1 test of 1.

#   Failed test 'dangling_exists'
#   at t\links.t line 203.
# Looks like you failed 4 tests of 11.
t\links.t ..................... 
Dubious, test returned 4 (wstat 1024, 0x400)
Failed 4/11 subtests 
t\load.t ...................... ok
t\normalize.t ................. ok
t\obviously_non_multi_user.t .. ok
t\owner.t ..................... skipped: I can't find a file to test with: The getpwuid function is unimplemented at t\owner.t line 22.
t\pod.t ....................... ok
t\pod_coverage.t .............. skipped: Test::Pod::Coverage 1.00 required for testing POD coverage
    # File is min_file with size 53 bytes
t\rt\30346.t .................. ok
t\test_dirs.t ................. ok
# Warnings about file_writeable_ok are fine. It's a deprecated name that still works.
t\test_files.t ................ ok
t\win32.t ..................... ok

Test Summary Report
-------------------
t\links.t                   (Wstat: 1024 (exited 4) Tests: 11 Failed: 4)
  Failed tests:  7, 9-11
  Non-zero exit status: 4
Files=19, Tests=181,  4 wallclock secs ( 0.06 usr +  0.02 sys =  0.08 CPU)
Result: FAIL
Failed 1/19 test programs. 4/181 subtests failed.
NMAKE : fatal error U1077: 'C:\perl\5.36.0\bin\MSWin32-x86-multi-thread\perl.exe' : code retour '0xff'
Stop.

Mismatching license

LICENSE reads:

The Test::File module is licensed under the same terms as perl
itself, under the Artistic License 2.0.

That paragraph contradicts itself because Perl is not licensed under "Artistic License 2.0" but under "GPL version 1 or later, or Artistic 1 license" https://dev.perl.org/licenses/. The "Artistic License" link on the Perl web page points to https://dev.perl.org/licenses/artistic.html. That's a different license than the LICENSE file quotes underneath.

Could please correct the LICENSE text so that it does not mention Artistic 2.0 license as this is what you (or whoever wrote it) probably mean?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.