diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2016-11-18 17:28:46 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-11-18 17:30:47 +0200 |
commit | 6b7075adc71104c5f6ad652b99fb753565eb67d8 (patch) | |
tree | 1f4d91b7cd9ee7cca793f0ecc504ccc4d8dde0d2 /unit-tests/function/driver.cxx | |
parent | dd008d6e48b0bb66e1b9fdc489d9d1d9b4cb8d25 (diff) |
Add function machinery, implement path.normalize()
Note that multi-argument functions are not yet "callable" since there is
no support for value packs.
Diffstat (limited to 'unit-tests/function/driver.cxx')
-rw-r--r-- | unit-tests/function/driver.cxx | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/unit-tests/function/driver.cxx b/unit-tests/function/driver.cxx new file mode 100644 index 0000000..ba51662 --- /dev/null +++ b/unit-tests/function/driver.cxx @@ -0,0 +1,110 @@ +// file : unit-tests/function/driver.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include <iostream> + +#include <build2/types> +#include <build2/utility> + +#include <build2/parser> +#include <build2/context> +#include <build2/function> +#include <build2/variable> +#include <build2/diagnostics> + +using namespace std; + +namespace build2 +{ + static const optional<const value_type*> arg_bool[1] = + { + &value_traits<bool>::value_type + }; + + int + main () + { + init ("false", 1); // No build system driver, default verbosity. + reset (strings ()); // No command line variables. + + function_family f ("dummy"); + + f["fail"] = []() {error << "failed"; throw failed ();}; + f["fail_arg"] = [](names a) {return convert<uint64_t> (move (a[0]));}; + + f["null"] = [](names* a) {return a == nullptr;}; + f["optional"] = [](optional<names> a) {return !a;}; + + f["dummy0"] = []() {return "abc";}; + f["dummy1"] = [](string s) {return s;}; + + f["ambig"] = [](names a, optional<string>) {return a;}; + f["ambig"] = [](names a, optional<uint64_t>) {return a;}; + + f[".qual"] = []() {return "abc";}; + + f[".length"] = &string::size; // Member function. + f[".type"] = &name::type; // Data member. + + // Variadic function with first required argument of type bool. Returns + // number of arguments passed. + // + functions.insert ( + "variadic", + function_overload ( + nullptr, + 1, + function_overload::arg_variadic, + function_overload::types (arg_bool, 1), + [] (vector_view<value> args, const function_overload&) + { + return value (static_cast<uint64_t> (args.size ())); + })); + + // Dump arguments. + // + functions.insert ( + "dump", + function_overload ( + nullptr, + 0, + function_overload::arg_variadic, + function_overload::types (), + [] (vector_view<value> args, const function_overload&) + { + for (value& a: args) + { + if (a.null) + cout << "[null]"; + else if (!a.empty ()) + { + names storage; + cout << reverse (a, storage); + } + cout << endl; + } + return value (nullptr); + })); + + try + { + scope& s (*global_scope); + + parser p; + p.parse_buildfile (cin, path ("buildfile"), s, s); + } + catch (const failed&) + { + return 1; + } + + return 0; + } +} + +int +main () +{ + return build2::main (); +} |