Make initializer methods pure
[hiphop-php.git] / hphp / runtime / test / backtrace.cpp
blob9ba0123b9f6384797f350366c960f9bc326e4dac
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
16 #include "hphp/runtime/base/backtrace.h"
18 #include <folly/portability/GTest.h>
19 #include <folly/test/JsonTestUtil.h>
21 #include "hphp/runtime/base/array-init.h"
22 #include "hphp/runtime/base/type-array.h"
23 #include "hphp/runtime/base/type-string.h"
25 #include "hphp/util/struct-log.h"
27 namespace HPHP {
29 const StaticString
30 s_file("file"),
31 s_line("line"),
32 s_function("function"),
33 s_class("class"),
34 s_type("type"),
35 s_arrow("->"),
36 s_object("object"),
37 s_double_colon("::");
39 //////////////////////////////////////////////////////////////////////
40 Array mockBacktrace() {
41 return make_vec_array(
42 make_dict_array(
43 s_file, "filename",
44 s_line, "42",
45 s_function, "function_name",
46 s_type, s_double_colon,
47 s_class, "Class"
52 TEST(Backtrace, FullFunctionNames) {
53 StructuredLogEntry sample;
55 auto bt = mockBacktrace();
56 addBacktraceToStructLog(bt, sample);
58 auto const expectedDescription = "{\"vecs\":{\"php_lines\":[\"42\"],"
59 "\"php_functions\":[\"Class::function_name\"],\"php_files\":[\"filename\"]}"
60 ",\"sets\":{},\"ints\":{}}";
61 FOLLY_EXPECT_JSON_EQ(show(sample), expectedDescription);
64 TEST(Backtrace, FunctionNameWithObject) {
65 StructuredLogEntry sample;
67 auto bt = make_vec_array(
68 make_dict_array(
69 s_file, "filename",
70 s_line, "42",
71 s_function, "function_name",
72 s_type, s_arrow,
73 s_object, "this",
74 s_class, "Class"
77 addBacktraceToStructLog(bt, sample);
79 auto const expectedDescription = "{\"vecs\":{\"php_lines\":[\"42\"],"
80 "\"php_functions\":[\"Class->function_name\"],\"php_files\":[\"filename\"]}"
81 ",\"sets\":{},\"ints\":{}}";
82 FOLLY_EXPECT_JSON_EQ(show(sample), expectedDescription);
85 TEST(Backtrace, LongFunctionNames) {
86 StructuredLogEntry sample;
88 auto bt = make_vec_array(
89 make_dict_array(
90 s_file, "filenameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
91 s_line, "42---------------------------------------------------------------------------------",
92 s_function, "function_name--------------------------------------------------------------------",
93 s_type, s_arrow,
94 s_object, "this-------------------------------------------------------------------------------",
95 s_class, "Class-----------------------------------------------------------------------------------------"
98 addBacktraceToStructLog(bt, sample);
100 auto const expectedDescription = "{\"vecs\":{\"php_lines\":[\"42-------------"
101 "--------------------------------------------------------------------\"],"
102 "\"php_functions\":[\"Class------------------------------------------------"
103 "------------------------------------------>function_name------------------"
104 "--------------------------------------------------\"],\"php_files\":[\"fil"
105 "enameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
106 "eeeeeee\"]}"
107 ",\"sets\":{},\"ints\":{}}";
108 FOLLY_EXPECT_JSON_EQ(show(sample), expectedDescription);
112 //////////////////////////////////////////////////////////////////////