|
1 | 1 | classdef TestTime < matlab.unittest.TestCase |
2 | 2 |
|
| 3 | +properties |
| 4 | +td |
| 5 | +end |
| 6 | + |
| 7 | +methods(TestClassSetup) |
| 8 | +function set_temp_wd(tc) |
| 9 | +if isMATLABReleaseOlderThan('R2022a') |
| 10 | + tc.td = tempname(); |
| 11 | + mkdir(tc.td); |
| 12 | +else |
| 13 | + tc.td = tc.createTemporaryFolder(); |
| 14 | +end |
| 15 | +end |
| 16 | +end |
| 17 | + |
| 18 | +methods(TestClassTeardown) |
| 19 | +function remove_temp_wd(tc) |
| 20 | +if isMATLABReleaseOlderThan('R2022a') |
| 21 | + [s, m, i] = rmdir(tc.td, 's'); |
| 22 | + if ~s, warning(i, "Failed to remove temporary directory %s: %s", tc.td, m); end |
| 23 | +end |
| 24 | +end |
| 25 | +end |
| 26 | + |
3 | 27 | methods (Test) |
4 | 28 |
|
5 | 29 | function test_get_modtime(tc) |
6 | 30 | tc.verifyEmpty(stdlib.get_modtime("")) |
7 | 31 | end |
8 | 32 |
|
9 | 33 |
|
| 34 | +function test_touch_modtime(tc) |
| 35 | +tc.assumeTrue(stdlib.has_java() || stdlib.has_python()) |
| 36 | + |
| 37 | +fn = fullfile(tc.td, "modtime.txt"); |
| 38 | + |
| 39 | +tc.verifyTrue(stdlib.touch(fn, datetime("yesterday"))) |
| 40 | +t0 = stdlib.get_modtime(fn); |
| 41 | + |
| 42 | +tc.verifyTrue(stdlib.set_modtime(fn, datetime("now"))) |
| 43 | +t1 = stdlib.get_modtime(fn); |
| 44 | + |
| 45 | +tc.verifyGreaterThanOrEqual(t1, t0) |
| 46 | +end |
| 47 | + |
| 48 | + |
| 49 | +function test_set_modtime(tc) |
| 50 | +tc.assumeTrue(stdlib.has_java() || stdlib.has_python()) |
| 51 | + |
| 52 | +tc.verifyEqual(stdlib.set_modtime("", datetime("now")), false) |
| 53 | +end |
| 54 | + |
| 55 | + |
10 | 56 | end |
11 | 57 |
|
12 | 58 | end |
0 commit comments