2 +----------------------------------------------------------------------+
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"
32 s_function("function"),
39 //////////////////////////////////////////////////////////////////////
40 Array
mockBacktrace() {
41 return make_vec_array(
45 s_function
, "function_name",
46 s_type
, s_double_colon
,
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(
71 s_function
, "function_name",
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(
90 s_file
, "filenameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
91 s_line
, "42---------------------------------------------------------------------------------",
92 s_function
, "function_name--------------------------------------------------------------------",
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"
107 ",\"sets\":{},\"ints\":{}}";
108 FOLLY_EXPECT_JSON_EQ(show(sample
), expectedDescription
);
112 //////////////////////////////////////////////////////////////////////