Skip to content

Commit d61433f

Browse files
committed
shortname: improve logic and test
1 parent 0f6cc62 commit d61433f

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

+stdlib/windows_shortname.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
end
1616

1717
s = p;
18+
1819
if ispc
1920
fso = actxserver('Scripting.FileSystemObject');
2021

@@ -25,10 +26,11 @@
2526
end
2627

2728
delete(fso);
28-
end
29-
30-
s = string(s);
3129

30+
if isstring(p)
31+
s = string(s);
32+
end
33+
end
3234

3335
end
3436

test/TestWindowsCOM.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ function test_short_folder(tc)
1515
import matlab.unittest.constraints.IsFolder
1616

1717
progdir = stdlib.posix(getenv("PROGRAMFILES"));
18-
tc.assumeThat(progdir, IsFolder, "$Env:PROGRAMFILES is not a directory")
18+
if ispc()
19+
tc.assertThat(progdir, IsFolder, "$Env:PROGRAMFILES is not a directory")
20+
end
1921

2022
short = stdlib.windows_shortname(progdir);
2123

2224
if ispc
2325
tc.verifySubstring(short, "PROGRA~1")
24-
tc.verifyEqual(stdlib.canonical(short), string(progdir))
26+
tc.verifyTrue(stdlib.samepath(short, string(progdir)))
2527
else
26-
tc.verifyEqual(short, progdir)
28+
tc.verifyEqual(strlength(short), 0)
2729
end
2830

2931
end

0 commit comments

Comments
 (0)