|
1 | 1 | classdef TestFileImpure < matlab.unittest.TestCase
|
2 | 2 |
|
3 |
| -methods(TestClassSetup) |
4 |
| - |
5 |
| -function setup_path(tc) |
6 |
| -import matlab.unittest.fixtures.PathFixture |
7 |
| -cwd = fileparts(mfilename("fullpath")); |
8 |
| -top = fullfile(cwd, ".."); |
9 |
| -tc.applyFixture(PathFixture(top)) |
| 3 | +properties (ClassSetupParameter) |
| 4 | + classToTest = {"TestFileImpure"}; |
| 5 | +end |
10 | 6 |
|
| 7 | +properties(TestParameter) |
| 8 | +in_exists = {pwd, string(mfilename("fullpath"))+".m", "not-exists"} |
| 9 | +ref_exists = {true, true, false} |
| 10 | +% on CI matlabroot can be writable! |
| 11 | +in_is_write = {pwd, "not-exists"}; |
| 12 | +ref_is_write = {true, false} |
| 13 | +in_expand = {"", "~abc", "~", "~/foo"} |
| 14 | +ref_expand |
| 15 | +in_same = {"", tempname, "~/b/..", "."} |
| 16 | +other_same = {"", tempname, "~/c/..", fullfile(pwd, "a/..")} |
| 17 | +ref_same = {false, false, true, true} |
11 | 18 | end
|
12 | 19 |
|
| 20 | +properties |
| 21 | +tobj |
13 | 22 | end
|
14 | 23 |
|
15 |
| -methods (Test) |
16 | 24 |
|
17 |
| -function test_exists(tc) |
| 25 | +methods (TestParameterDefinition, Static) |
18 | 26 |
|
19 |
| -tc.verifyTrue(stdlib.exists(pwd)) |
20 |
| -tc.verifyTrue(stdlib.exists(string(mfilename("fullpath"))+".m")) |
21 |
| -tc.verifyFalse(stdlib.exists("not-exists")) |
| 27 | +function ref_expand = init_expand(classToTest) %#ok<INUSD> |
| 28 | +cwd = fileparts(mfilename("fullpath")); |
| 29 | +top = fullfile(cwd, ".."); |
| 30 | +addpath(top) |
22 | 31 |
|
| 32 | +ref_expand = {"", "~abc", stdlib.fileio.homedir, stdlib.join(stdlib.fileio.homedir, "foo")}; |
| 33 | +end |
23 | 34 | end
|
24 | 35 |
|
25 | 36 |
|
26 |
| -function test_is_readable(tc) |
27 |
| - |
28 |
| -tc.verifyTrue(stdlib.is_readable(pwd)) |
29 |
| -tc.verifyTrue(stdlib.is_readable(string(mfilename("fullpath"))+".m")) |
30 |
| -tc.verifyFalse(stdlib.is_readable("not-exists")) |
| 37 | +methods(TestClassSetup) |
31 | 38 |
|
| 39 | +function classSetup(tc, classToTest) |
| 40 | +constructor = str2func(classToTest); |
| 41 | +tc.tobj = constructor(); |
32 | 42 | end
|
33 | 43 |
|
34 |
| - |
35 |
| -function test_is_writable(tc) |
36 |
| - |
37 |
| -tc.verifyTrue(stdlib.is_writable(pwd)) |
38 |
| -% tc.verifyFalse(stdlib.is_writable(matlabroot)) % on CI this can be writable! |
39 |
| -tc.verifyFalse(stdlib.is_writable("not-exists")) |
| 44 | +function setup_path(tc) |
| 45 | +import matlab.unittest.fixtures.PathFixture |
| 46 | +cwd = fileparts(mfilename("fullpath")); |
| 47 | +top = fullfile(cwd, ".."); |
| 48 | +tc.applyFixture(PathFixture(top)) |
| 49 | +end |
40 | 50 |
|
41 | 51 | end
|
42 | 52 |
|
| 53 | +methods (Test, ParameterCombination = 'sequential') |
43 | 54 |
|
| 55 | +function test_exists(tc, in_exists, ref_exists) |
| 56 | +tc.verifyEqual(stdlib.exists(in_exists), ref_exists) |
| 57 | +end |
44 | 58 |
|
45 |
| -function test_expanduser(tc) |
46 | 59 |
|
47 |
| -tc.verifyEqual(stdlib.expanduser(""), "") |
| 60 | +function test_is_readable(tc, in_exists, ref_exists) |
| 61 | +tc.verifyEqual(stdlib.is_readable(in_exists), ref_exists) |
| 62 | +end |
48 | 63 |
|
49 |
| -tc.verifyEqual(stdlib.expanduser("~abc"), "~abc") |
50 | 64 |
|
51 |
| -h = stdlib.fileio.homedir(); |
52 |
| -tc.verifyEqual(stdlib.expanduser("~"), h) |
| 65 | +function test_is_writable(tc, in_is_write, ref_is_write) |
| 66 | +tc.verifyEqual(stdlib.is_writable(in_is_write), ref_is_write) |
| 67 | +end |
53 | 68 |
|
54 |
| -e = stdlib.expanduser("~/foo"); |
55 |
| -tc.verifyEqual(e, stdlib.fileio.join(h, "foo")) |
56 | 69 |
|
| 70 | +function test_expanduser(tc, in_expand, ref_expand) |
| 71 | +tc.verifyEqual(stdlib.expanduser(in_expand), ref_expand) |
57 | 72 | end
|
58 | 73 |
|
59 | 74 |
|
60 | 75 | function test_touch_modtime(tc)
|
61 | 76 |
|
62 | 77 | fn = tempname;
|
63 | 78 | tc.verifyTrue(stdlib.touch(fn))
|
64 |
| - |
65 | 79 | t0 = stdlib.get_modtime(fn);
|
66 |
| -pause(1.1) |
| 80 | + |
| 81 | +pause(0.4) % empirical to avoid failing >= |
67 | 82 | tc.verifyTrue(stdlib.set_modtime(fn))
|
68 | 83 | t1 = stdlib.get_modtime(fn);
|
69 | 84 |
|
70 |
| -tc.verifyGreaterThan(t1, t0) |
| 85 | +tc.verifyGreaterThanOrEqual(t1, t0) |
71 | 86 |
|
72 | 87 | end
|
73 | 88 |
|
@@ -115,7 +130,6 @@ function test_canonical(tc)
|
115 | 130 | tc.verifyThat(pabs, StartsWithSubstring("2foo"))
|
116 | 131 |
|
117 | 132 | par1 = stdlib.canonical("../2foo");
|
118 |
| -tc.verifyNotEmpty(par1) |
119 | 133 | tc.verifyThat(par1, StartsWithSubstring(".."))
|
120 | 134 |
|
121 | 135 | pt1 = stdlib.canonical("bar/../2foo");
|
@@ -194,12 +208,8 @@ function test_makedir(tc)
|
194 | 208 | end
|
195 | 209 |
|
196 | 210 |
|
197 |
| -function test_samepath(tc) |
198 |
| - |
199 |
| -tc.verifyFalse(stdlib.samepath("", ""), "empty not same") |
200 |
| -tc.verifyFalse(stdlib.samepath(tempname, tempname), "tempname not same") |
201 |
| -tc.verifyTrue(stdlib.samepath("~/b/..", "~/c/.."), "tilde path ..") |
202 |
| -tc.verifyTrue(stdlib.samepath(".", fullfile(pwd, "a/..")), "dot path ..") |
| 211 | +function test_samepath(tc, in_same, other_same, ref_same) |
| 212 | +tc.verifyEqual(stdlib.samepath(in_same, other_same), ref_same) |
203 | 213 | end
|
204 | 214 |
|
205 | 215 |
|
|
0 commit comments