diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2017-03-29 00:45:30 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2017-04-04 13:35:14 +0300 |
commit | dd973d03bf5f3f439dcdacbb22470105e66e698a (patch) | |
tree | 6856ab313c75f3459df80511c98d3f788bf1c22b /tests/variable/driver.cxx | |
parent | c72bbd5d04084547c53e9593af4d76d9e5135a53 (diff) |
Implement manifests and build_config
Diffstat (limited to 'tests/variable/driver.cxx')
-rw-r--r-- | tests/variable/driver.cxx | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/variable/driver.cxx b/tests/variable/driver.cxx new file mode 100644 index 0000000..88167ad --- /dev/null +++ b/tests/variable/driver.cxx @@ -0,0 +1,61 @@ +// file : tests/variable/driver.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include <ios> // ios_base::failbit, ios_base::badbit +#include <string> +#include <cassert> +#include <cstddef> // size_t +#include <iostream> + +#include <butl/utility> // operator<<(ostream,exception) + +#include <bbot/variable> + +using namespace std; +using namespace butl; +using namespace bbot; + +// Usage: argv[0] [-u] +// +// Read variables from STDIN (one per line) and serialize them to STDOUT (also +// one per line). +// +// -u output variables being unquoted beforehand +// +int +main (int argc, char* argv[]) +{ + assert (argc <= 2); + bool unquote (false); + + if (argc == 2) + { + assert (argv[1] == string ("-u")); + unquote = true; + } + + cin.exceptions (ios_base::badbit); + cout.exceptions (ios_base::failbit | ios_base::badbit); + + string s; + for (size_t l (1); getline (cin, s); ++l) + { + try + { + variable v (move (s)); + + cout << (unquote + ? v.unquoted () + : static_cast<const string&> (v)) + << '\n'; + } + catch (const invalid_variable& e) + { + cerr << l << ':' << 1 + e.pos << ": error: " << e << endl; + return 1; + } + } + + return 0; +} |