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 +----------------------------------------------------------------------+
17 #include "hphp/test/ext/test.h"
18 #include "hphp/runtime/base/array-init.h"
19 #include "hphp/runtime/base/apc-file-storage.h"
20 #include "hphp/runtime/base/comparisons.h"
21 #include "hphp/compiler/option.h"
22 #include <folly/Format.h>
26 ///////////////////////////////////////////////////////////////////////////////
28 int Test::s_total
= 0;
29 int Test::s_passed
= 0;
30 int Test::s_skipped
= 0;
31 std::string
Test::s_suite
;
33 bool Test::s_quiet
= false;
35 TestLogger
Test::logger
;
37 ///////////////////////////////////////////////////////////////////////////////
39 bool Test::RunTests(std::string
&suite
, std::string
&which
, std::string
&set
) {
40 bool allPassed
= true;
43 size_t pos
= suite
.find("::");
44 if (pos
!= std::string::npos
) {
45 which
= suite
.substr(pos
+ 2);
46 suite
= suite
.substr(0, pos
);
49 if (!logger
.initializeRun()) {
50 printf("WARNING: couldn't initialize test logging\n");
53 RunTestsImpl(allPassed
, suite
, which
, set
);
55 if (!logger
.finishRun()) {
56 printf("WARNING: couldn't finish test logging\n");
60 printf("%d/%d unit tests skipped.\n", s_skipped
, s_total
);
64 assert(s_total
== s_passed
+ s_skipped
);
65 printf("%d/%d unit tests passed.\n", s_passed
, s_total
);
69 printf("ERROR: %d/%d unit tests failed.\n", s_total
- s_passed
- s_skipped
,
74 bool Test::logTestResults(std::string name
, std::string details
, int pass
,
76 if (!logger
.doLog()) {
80 long seconds
= finish
.tv_sec
- start
.tv_sec
;
81 long useconds
= finish
.tv_usec
- start
.tv_usec
;
82 long mseconds
= ((seconds
) * 1000 + useconds
/ 1000.0) + 0.5; // round up
84 auto summary
= folly::sformat("PASSED ({})", pass
);
85 const char* status
= "passed";
88 summary
+= folly::sformat(",SKIPPED ({})", skip
);
93 summary
+= folly::sformat("FAILED ({})", fail
);
96 ArrayInit
data(8, ArrayInit::Map
{});
97 data
.set(String("type"), "hphp");
98 data
.set(String("name"), name
);
99 data
.set(String("contacts"), null_array
);
100 data
.set(String("endedTime"), time(nullptr));
101 data
.set(String("durationSecs"), mseconds
/ 1000.0);
102 data
.set(String("status"), status
);
103 data
.set(String("summary"), std::string(summary
));
104 data
.set(String("details"), details
);
106 if (!logger
.logTest(data
.toArray())) {
107 printf("WARNING: Logging %s failed\n", name
.c_str());