11classdef (SharedTestFixtures = { matlab .unittest .fixtures .PathFixture(fileparts(fileparts(mfilename(' fullpath' ))))}, ...
2- TestTags = {' R2021a ' , ' symlink' , ' impure' }) ...
2+ TestTags = {' R2019b ' , ' symlink' , ' impure' }) ...
33 TestSymlink < matlab .unittest .TestCase
44
55properties
1212 {mfilename(" fullpath" ) + " .m" , false }, ...
1313 {" " , false }};
1414Pre = {' ' , " " , tempname()}
15- B_create_symlink
16- B_read_symlink
17- B_is_symlink
18- end
19-
20-
21- methods (TestParameterDefinition , Static )
22- function [B_create_symlink , B_read_symlink , B_is_symlink ] = setupBackends()
23- B_create_symlink = init_backend(" create_symlink" );
24- B_read_symlink = init_backend(" read_symlink" );
25- B_is_symlink = init_backend(" is_symlink" );
26- end
15+ B_create_symlink = {' native' , ' dotnet' , ' python' , ' sys' }
16+ B_is_symlink = {' native' , ' java' , ' python' , ' dotnet' , ' sys' }
2717end
2818
2919
@@ -50,46 +40,85 @@ function test_is_symlink(tc, p, B_is_symlink)
5040[i , b ] = stdlib .is_symlink(tc .link , B_is_symlink );
5141
5242tc .assertEqual(char(b ), B_is_symlink )
43+
44+ if ismember(B_is_symlink , stdlib .Backend().select(' is_symlink' ))
5345tc .assertTrue(i , " failed to detect own link " + tc .link )
5446
5547tc .verifyEqual(stdlib .is_symlink(p{1 }, B_is_symlink ), p{2 }, p{1 })
48+ else
49+ tc .verifyEmpty(i )
50+ end
5651end
5752
5853
59- function test_read_symlink_empty(tc , Pre , B_read_symlink )
60- [r , b ] = stdlib .read_symlink(Pre , B_read_symlink );
61- tc .assertEqual(char(b ), B_read_symlink )
54+ function test_read_symlink_empty(tc , Pre , B_is_symlink )
55+ [r , b ] = stdlib .read_symlink(Pre , B_is_symlink );
56+ tc .assertEqual(char(b ), B_is_symlink )
6257
6358tc .verifyEqual(r , string .empty )
6459end
6560
6661
67- function test_read_symlink(tc , B_read_symlink )
68- r = stdlib .read_symlink(tc .link , B_read_symlink );
62+ function test_read_symlink(tc , B_is_symlink )
63+ r = stdlib .read_symlink(tc .link , B_is_symlink );
6964tc .verifyClass(r , ' string' )
70- tc .verifyEqual(r , string(tc .target ))
65+
66+ if ismember(B_is_symlink , stdlib .Backend().select(' read_symlink' ))
67+ tc .verifyEqual(r , string(tc .target ))
68+ else
69+ tc .verifyEmpty(r )
70+ end
7171end
7272
7373
7474function test_create_symlink(tc , B_create_symlink )
7575tc .applyFixture(matlab .unittest .fixtures .SuppressedWarningsFixture([" MATLAB:io:filesystem:symlink:TargetNotFound" ," MATLAB:io:filesystem:symlink:FileExists" ]))
7676
7777ano = fullfile(pwd(), ' another.lnk' );
78+ tc .assertThat(ano , ~matlab .unittest .constraints .IsFile )
79+ tc .assertFalse(stdlib .is_symlink(ano ))
7880
79- h = @ stdlib .create_symlink ;
81+ r = stdlib .create_symlink( tc . target , ano , B_create_symlink ) ;
8082
81- [i , b ] = h(' ' , tempname(), B_create_symlink );
83+ if ismember(B_create_symlink , stdlib .Backend().select(' create_symlink' ))
84+ tc .verifyTrue(r )
85+ elseif ispc() && B_create_symlink == " native"
86+ tc .verifyTrue(r || isempty(r ))
87+ else
88+ tc .verifyEmpty(r )
89+ end
90+ end
91+
92+
93+ function test_create_symlink_empty(tc , B_create_symlink )
94+ [i , b ] = stdlib .create_symlink(' ' , tempname(), B_create_symlink );
8295tc .assertEqual(char(b ), B_create_symlink )
8396
84- tc .verifyFalse(i )
85- tc .verifyFalse(h(tc .target , tc .link , B_create_symlink ), " should fail for existing symlink" )
97+ if ismember(B_create_symlink , stdlib .Backend().select(' create_symlink' ))
98+ if ispc() && B_create_symlink == " native"
99+ tc .verifyTrue( isempty(i ) || ~i )
100+ else
101+ tc .verifyFalse(i )
102+ end
103+ else
104+ tc .verifyTrue( isempty(i ) || ~i )
105+ end
106+ end
107+
86108
87- exp = true ;
109+ function test_create_symlink_exist(tc , B_create_symlink )
110+ i = stdlib .create_symlink(tc .target , tc .link , B_create_symlink );
88111
89- tc .assertThat(ano , ~matlab .unittest .constraints .IsFile )
90- tc .assertFalse(stdlib .is_symlink(ano ))
112+ if ismember(B_create_symlink , stdlib .Backend().select(' create_symlink' ))
113+ if ispc() && B_create_symlink == " native"
114+ tc .verifyTrue( isempty(i ) || ~i )
115+ else
116+ tc .verifyFalse(i , " should fail for existing symlink" )
117+ end
118+ else
119+ tc .verifyTrue( isempty(i ) || ~i )
120+ end
91121
92- tc .verifyEqual(h(tc .target , ano , B_create_symlink ), exp )
93122end
94123
95124end
0 commit comments