diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2017-04-25 11:53:11 +0200 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2017-04-26 14:19:50 +0300 |
commit | 1bea889fd59b4ac3a32232e8f7a9ba34506717dc (patch) | |
tree | 1f67ea3eb8f1ee9eab528a4ca57ce27530ed8bd3 /tests/standard-version | |
parent | aef93c360bb8de3dd49138e9f9a065ef631a303c (diff) |
Add standard_version class
Diffstat (limited to 'tests/standard-version')
-rw-r--r-- | tests/standard-version/buildfile | 7 | ||||
-rw-r--r-- | tests/standard-version/driver.cxx | 136 | ||||
-rw-r--r-- | tests/standard-version/testscript | 190 |
3 files changed, 333 insertions, 0 deletions
diff --git a/tests/standard-version/buildfile b/tests/standard-version/buildfile new file mode 100644 index 0000000..4afb691 --- /dev/null +++ b/tests/standard-version/buildfile @@ -0,0 +1,7 @@ +# file : tests/tab-parser/buildfile +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +exe{driver}: cxx{driver} ../../butl/lib{butl} test{testscript} + +include ../../butl/ diff --git a/tests/standard-version/driver.cxx b/tests/standard-version/driver.cxx new file mode 100644 index 0000000..1299090 --- /dev/null +++ b/tests/standard-version/driver.cxx @@ -0,0 +1,136 @@ +// file : tests/standard-version/driver.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include <ios> // ios::failbit, ios::badbit +#include <string> +#include <cassert> +#include <iostream> +#include <stdexcept> // invalid_argument + +#include <butl/utility> // operator<<(ostream,exception) +#include <butl/standard-version> + +using namespace std; +using namespace butl; + +// Create standard version from string, and also test another ctors. +// +static standard_version +version (const string& s) +{ + standard_version r (s); + + try + { + standard_version v (r.epoch, + r.version, + r.snapshot () + ? r.string_snapshot () + : string (), + r.revision); + + assert (r == v); + + if (r.epoch == 0 && r.revision == 0) + { + standard_version v (r.version, + r.snapshot () + ? r.string_snapshot () + : string ()); + assert (r == v); + + if (!r.snapshot ()) + { + standard_version v (r.version); + assert (r == v); + } + } + + if (r.snapshot ()) + { + standard_version v (r.epoch, + r.version, + r.snapshot_sn, + r.snapshot_id, + r.revision); + assert (r == v); + } + + } + catch (const invalid_argument& e) + { + cerr << e << endl; + assert (false); + } + + return r; +} + +// Usages: +// +// argv[0] -a <version> +// argv[0] -b <version> +// argv[0] -c <version> <version> +// argv[0] +// +// -a output 'y' for alpha-version, 'n' otherwise +// -b output 'y' for beta-version, 'n' otherwise +// -c output 0 if versions are equal, -1 if the first one is less, 1 otherwise +// +// If no options are specified, then create versions from STDIN lines, and +// print them to STDOUT. +// +int +main (int argc, char* argv[]) +try +{ + cin.exceptions (ios::badbit); + cout.exceptions (ios::failbit | ios::badbit); + + if (argc > 1) + { + string o (argv[1]); + + if (o == "-a") + { + assert (argc == 3); + char r (version (argv[2]).alpha () + ? 'y' + : 'n'); + + cout << r << endl; + } + else if (o == "-b") + { + assert (argc == 3); + char r (version (argv[2]).beta () + ? 'y' + : 'n'); + + cout << r << endl; + } + else if (o == "-c") + { + assert (argc == 4); + + int r (version (argv[2]).compare (version (argv[3]))); + cout << r << endl; + } + else + assert (false); + + return 0; + } + + string s; + while (getline (cin, s)) + cout << version (s) << endl; + + return 0; +} +catch (const invalid_argument& e) +{ + cerr << e << endl; + return 1; +} diff --git a/tests/standard-version/testscript b/tests/standard-version/testscript new file mode 100644 index 0000000..335bed9 --- /dev/null +++ b/tests/standard-version/testscript @@ -0,0 +1,190 @@ +# file : tests/standard-version/testscript +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +: valid +: +: Roundtrip version. +: +{ + : non-prerelease + : + $* <<EOF >>EOF + 1.2.3 + EOF + + : prerelease + : + { + : final + : + $* <<EOF >>EOF + 1.2.3-a.1 + 1.2.3-b.1 + EOF + + : snapshot + : + $* <<EOF >>EOF + 1.2.3-a.1.z + 1.2.3-a.0.456 + 1.2.3-a.1.456.340c0a26a5ef + EOF + } + + : revision + : + $* <<EOF >>EOF + 1.2.3+4 + 1.2.3-a.4+5 + 1.2.3-a.4.z+5 + 1.2.3-a.4.567+8 + 1.2.3-a.4.567.340c0a26a5ef+8 + EOF + + : epoch + : + $* <<EOF >>EOF + 4~1.2.3 + EOF +} + +: invalid +: +{ + : major + : + $* <'a' 2>'invalid major version' == 1 + + : no-major-dot + : + $* <'1' 2>"'.' expected after major version" == 1 + + : minor + : + $* <'1.a' 2>'invalid minor version' == 1 + + : no-minor-dot + : + $* <'1.2' 2>"'.' expected after minor version" == 1 + + : bugfix + : + $* <'1.2.a' 2>'invalid bugfix version' == 1 + + : zero-version + : + $* <'1~0.0.0' 2>'0.0.0 version' == 1 + + : a-b-expected1 + : + $* <'1.2.3-' 2>"'a' or 'b' expected in pre-release" == 1 + + : a-b-expected2 + : + $* <'1.2.3-k' 2>"'a' or 'b' expected in pre-release" == 1 + + : prerelease-dot-expected + : + $* <'1.2.3-a' 2>"'.' expected after pre-release letter" == 1 + + : prerelease + : + $* <'1.2.3-a.b' 2>'invalid pre-release' == 1 + + : final-prerelease + : + $* <'1.2.3-b.0' 2>'invalid final pre-release' == 1 + + : snapshot-num + : + $* <'1.2.3-a.1.0' 2>'invalid snapshot number' == 1 + + : snapshot-id + : + $* <'1.2.3-a.1.1.@' 2>'invalid snapshot id' == 1 + + : revision + : + { + : non-prerelease + : + $* <'1.2.3+a' 2>'invalid revision' == 1 + + : prerelease + : + $* <'1.2.3-a.1+a' 2>'invalid revision' == 1 + + : snapshot-num + : + $* <'1.2.3-a.0.1+a' 2>'invalid revision' == 1 + + : snapshot-id + : + $* <'1.2.3-a.0.1.83jdgsf+0' 2>'invalid revision' == 1 + } + + : trailing-junk-after + : + { + : snapshot-num + : + $* <'1.2.3-a.1.z.a' 2>'junk after version' == 1 + + : revision + : + $* <'1.2.3-a.1.z+1a' 2>'junk after version' == 1 + } +} + +: alpha +: +{ + test.options += -a + + $* '1.2.3' >n: non-prerelease + $* '1.2.3-b.1' >n: beta + $* '1.2.3-a.1' >y: final + $* '1.2.3-a.0.1' >y: snapshot +} + +: beta +: +{ + test.options += -b + + $* '1.2.3' >n: non-prerelease + $* '1.2.3-a.1' >n: alpha + $* '1.2.3-b.1' >y: final + $* '1.2.3-b.0.1' >y: snapshot +} + +: compare +: +{ + test.options += -c + + : epoch + : + { + $* '4~1.2.3' '4~1.2.3' >'0' : equal + $* '1.2.4' '4~1.2.3' >'-1': less + } + + : non-prerelease + : + { + $* '1.2.3' '1.2.3' >'0' : equal + $* '1.2.3' '1.2.4' >'-1' : less + } + + : prerelease + : + { + $* '1.2.3-a.1' '1.2.3-a.1' >'0' : equal + $* '1.2.3' '1.2.3-a.1' >'1' : release-gt-prereleas + $* '1.2.3-a.2' '1.2.3-b.1' >'-1' : a-lt-b + $* '1.2.3-a.1' '1.2.3-a.1.2' >'-1' : final-lt-snapshot + $* '1.2.3-a.1.2.xy' '1.2.3-a.1.2' >'0' : ignore-snapshot-id + } +} |