Skip to content

Commit 7af1cd4

Browse files
committed
move *version from mat_gemini
1 parent ccaca71 commit 7af1cd4

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

+stdlib/+test/TestVersion.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
classdef TestVersion < matlab.unittest.TestCase
2+
3+
methods (Test)
4+
5+
function test_version(tc)
6+
tc.verifyTrue(stdlib.version_atleast("3.19.0.33", "3.19.0"))
7+
tc.verifyFalse(stdlib.version_atleast("3.19.0.33", "3.19.0.34"))
8+
end
9+
10+
end
11+
12+
end

+stdlib/cmake_atleast.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function r = cmake_atleast(min_version)
2+
arguments
3+
min_version (1,1) string {mustBeNonzeroLengthText}
4+
end
5+
6+
[ret, msg] = system("cmake --version");
7+
8+
assert(ret==0, "problem getting CMake version " + msg)
9+
10+
match = regexp(msg, "(?<=cmake version )(\d+\.\d+\.\d+)", 'match');
11+
12+
r = stdlib.version_atleast(match{1}, min_version);
13+
14+
end

+stdlib/version_atleast.m

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
function r = version_atleast(in, ref)
2+
% compare two string verions: major.minor.rev.patch
3+
% uses strings to compare so mixed number/string is OK
4+
%
5+
% parameters
6+
% ------------
7+
% in: version to examine (string)
8+
% ref: version to compare against (at least this version is true)
9+
%
10+
% returns
11+
% -------
12+
% r: logical
13+
14+
arguments
15+
in (1,1) string
16+
ref (1,1) string
17+
end
18+
19+
in = split(in, ' ');
20+
in = split(in(1), '.');
21+
22+
ref = split(ref, '.');
23+
24+
for i = 1:min(length(in), length(ref))
25+
if in(i) > ref(i)
26+
r = true;
27+
return
28+
elseif in(i) < ref(i)
29+
r = false;
30+
return
31+
end
32+
end
33+
34+
r = in(end) >= ref(end);
35+
36+
end % function

0 commit comments

Comments
 (0)