exception_ptr -> exception_wrapper migration
[folly.git] / folly / wangle / futures / test / thens.rb
1 #!/usr/bin/env ruby
2
3 # ruby thens.rb > Thens.cpp
4
5 # An exercise in combinatorics.
6 # (ordinary/static function, member function, std::function, lambda)
7 # X
8 # returns (Future<R>, R)
9 # X
10 # accepts (Try<T>&&, Try<T> const&, Try<T>, T&&, T const&, T, nothing)
11
12 def test(*args)
13   args = args.join(", ")
14   [
15   "{Future<B> f = someFuture<A>().then(#{args});}",
16   #"{Future<B> f = makeFuture(A()).then(#{args}, anExecutor);}",
17   ]
18 end
19
20 def retval(ret)
21   {
22     "Future<B>" => "someFuture<B>()",
23     "Try<B>" => "Try<B>(B())",
24     "B" => "B()"
25   }[ret]
26 end
27
28 return_types = [
29   "Future<B>",
30   "B",
31   #"Try<B>",
32 ]
33 param_types = [
34     "Try<A>&&",
35     #"Try<A> const&",
36     #"Try<A>",
37     #"Try<A>&",
38     "A&&",
39     #"A const&",
40     #"A",
41     #"A&",
42     #"",
43   ]
44
45 tests = (
46   return_types.map { |ret|
47     param_types.map { |param|
48       both = "#{ret}, #{param}"
49       [
50         ["&aFunction<#{both}>"],
51         ["&SomeClass::aStaticMethod<#{both}>"],
52         # TODO switch these around (std::bind-style)
53         ["&anObject", "&SomeClass::aMethod<#{both}>"],
54         ["aStdFunction<#{both}>()"],
55         ["[&](#{param}){return #{retval(ret)};}"],
56       ]
57     }
58   }.flatten(2) + [
59     #[""],
60   ]
61 ).map {|a| test(a)}.flatten
62
63 print <<EOF
64 // This file is #{"@"}generated by thens.rb. Do not edit directly.
65
66 // TODO: fails to compile with clang:dev.  See task #4412111
67 #ifndef __clang__
68
69 #include <folly/wangle/futures/test/Thens.h>
70
71 TEST(Future, thenVariants) {
72   SomeClass anObject;
73   folly::Executor* anExecutor;
74
75   #{tests.join("\n  ")}
76 }
77
78 #endif
79 EOF