11classdef TestSymlink < matlab .unittest .TestCase
22
33properties
4- d
4+ target
5+ link
6+ tempDir
57end
68
79properties (TestParameter )
1012
1113
1214methods (TestClassSetup )
13-
1415function setup_symlink(tc )
15- import matlab .unittest .fixtures .CurrentFolderFixture
16- import matlab .unittest .fixtures .TemporaryFolderFixture
17-
18- fixture = tc .applyFixture(TemporaryFolderFixture );
19- td = stdlib .posix(fixture .Folder );
20- tc .applyFixture(CurrentFolderFixture(td ))
16+ tc.tempDir = stdlib .posix(tc .createTemporaryFolder());
2117
22- tc.d. link = td + " /my.lnk" ;
18+ tc.link = tc . tempDir + " /my.lnk" ;
2319
24- tc.d.this = stdlib .posix(mfilename(" fullpath" ) + " .m" );
25-
26- tc .assumeTrue(stdlib .create_symlink(tc .d .this , tc .d .link ), ...
27- " failed to create test link " + tc .d .link )
20+ tc.target = stdlib .posix(mfilename(" fullpath" ) + " .m" );
2821
22+ tc .assumeTrue(stdlib .create_symlink(tc .target , tc .link ), ...
23+ " failed to create test link " + tc .link )
2924end
3025end
3126
3227
3328methods (Test )
3429
3530function test_is_symlink(tc , p )
36- tc .verifyEqual(stdlib .is_symlink(p{1 }), p{2 })
31+ tc .verifyTrue(stdlib .is_symlink(tc .link ), " failed to detect own link" )
32+ tc .verifyEqual(stdlib .is_symlink(p{1 }), p{2 }, p{1 })
3733end
3834
3935
@@ -43,32 +39,32 @@ function test_read_symlink(tc)
4339tc .verifyEqual(stdlib .read_symlink(" " ), " " )
4440tc .verifyEqual(stdlib .read_symlink(" file:///" ), " " )
4541tc .verifyEqual(stdlib .read_symlink(" not-exist" ), " " )
46- tc .verifyEqual(stdlib .read_symlink(tc .d . this ), " " )
42+ tc .verifyEqual(stdlib .read_symlink(tc .target ), " " )
4743
48- t = stdlib .read_symlink(tc .d . link );
44+ t = stdlib .read_symlink(tc .link );
4945tc .verifyNotEmpty(t )
5046tc .verifyThat(t , IsOfClass(' string' ))
51- tc .verifyEqual(tc .d . this , t )
47+ tc .verifyEqual(tc .target , t )
5248
5349end
5450
5551
5652function test_create_symlink(tc )
57-
5853tc .verifyFalse(stdlib .create_symlink(" " , tempname ))
5954tc .verifyFalse(stdlib .create_symlink(" file:///" , tempname ))
60- tc .verifyFalse(stdlib .create_symlink(tc .d .this , tc .d .link ))
61- tc .verifyTrue(stdlib .create_symlink(tc .d .this , " another.lnk" ))
62- tc .verifyTrue(stdlib .is_symlink(" another.lnk" ))
55+ tc .verifyFalse(stdlib .create_symlink(tc .target , tc .link ), " should fail for existing symlink" )
6356
57+ ano = tc .tempDir + " /another.lnk" ;
58+ tc .verifyTrue(stdlib .create_symlink(tc .target , ano ))
59+ tc .verifyTrue(stdlib .is_symlink(ano ))
6460end
6561
6662end
6763end
6864
6965
7066function p = init_symlink()
71- p = {{" not-exist" , false }, { " my.lnk " , true }, ...
67+ p = {{" not-exist" , false }, ...
7268 {mfilename(" fullpath" ) + " .m" , false }, ...
7369 {" " , false }, ...
7470 {" file:///" , false }};
0 commit comments