Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test::MockFileSys Prototype #115

Open
toddr opened this issue Jan 28, 2022 · 3 comments
Open

Test::MockFileSys Prototype #115

toddr opened this issue Jan 28, 2022 · 3 comments
Labels
Feature Request New feature or request

Comments

@toddr
Copy link
Member

toddr commented Jan 28, 2022

my $mock_fs = Test::MockFileSys->new;
$mock_fs->file('/foo/bar'); # push $self->{foo}->@*, Test::MockFile->file('/foo/bar');
$mock_fs->file('/foo/baz');
$mock_fs->dir('/foo');
$mock_fs->file('/foo/bar', '...'); # Retrieves existing object or creates new if missing.
@atoomic
Copy link
Contributor

atoomic commented Jan 28, 2022

then we could have

my $fs = Test::MockFileSys->new;
$fs->file( '/a/b/c' );

$fs->file( '/a/b/c' )->write( q[content] );
...
$fs->file( '/a/b/c' )->read;
$fs->file( '/a/b/c' )->unlink;

@toddr toddr added the Feature Request New feature or request label Jan 28, 2022
@toddr
Copy link
Member Author

toddr commented Jan 28, 2022

then we could have

$fs->file( '/a/b/c' )->unlink;

I think there are limits here.... how is that better than
unlink '/a/b/c'

@toddr
Copy link
Member Author

toddr commented Feb 17, 2022

# Grabs existing objects?
my $fs = Test::MockFileSys->new; # Singleton Only one at a time.

# Just mock not there
$fs->dir('/foo');
$fs->file('/foo/bar');

# make the thing and set perms, etc.
$fs->write_file('/foo/bar', "", { perms => 0755 });
$fs->symlink('data', '/foo/link');
$fs->mkdir( '/foo', 0755); # Auto mocks in strict mode.

# automock in strict mode.
symlink('data', '/foo/link');
mkdir '/foo', 0755;
chmod 0755, '/foo/bar';
unlink '/foo/link';

$fs->overwrite('/foo/bar', "new stuff"); # Also a getter with no 2nd arg.

# Get the object
$fs->path('/foo/bar');

# unmock the thing.
$fs->unmock('/foo/bar');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request New feature or request
Development

No branches or pull requests

2 participants