suppress warnings in tests for deprecated functions
[folly.git] / folly / futures / test / then_compile_test.rb
1 #!/usr/bin/env ruby
2
3 # cd folly/futures/test && ruby then_compile_test.rb > ThenCompileTest.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       if param != "" then
49         both = "#{ret}, #{param}"
50         [
51           ["&aFunction<#{both}>"],
52           ["&SomeClass::aStaticMethod<#{both}>"],
53           ["&SomeClass::aMethod<#{both}>", "&anObject"],
54           ["aStdFunction<#{both}>()"],
55           ["[&](#{param}){return #{retval(ret)};}"],
56         ]
57       else
58         [["[&](){return #{retval(ret)};}"]]
59       end
60     }
61   }.flatten(2)
62 ).map {|a| test(a)}.flatten
63
64 print <<EOF
65 // This file is #{"@"}generated by then_compile_test.rb. Do not edit directly.
66
67 #include <folly/futures/test/ThenCompileTest.h>
68
69 using namespace folly;
70
71 TEST(Basic, thenVariants) {
72   SomeClass anObject;
73
74   #{tests.join("\n  ")}
75 }
76 EOF