Skip to content

Commit bd7bcbf

Browse files
committed
Split PegtlTests.cpp into 3 grammar variants to speeed up build
1 parent 78513c6 commit bd7bcbf

File tree

4 files changed

+190
-142
lines changed

4 files changed

+190
-142
lines changed

test/CMakeLists.txt

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,35 @@ target_link_libraries(argument_tests PRIVATE
5050
add_bigobj_flag(argument_tests)
5151
gtest_add_tests(TARGET argument_tests)
5252

53-
add_executable(pegtl_tests PegtlTests.cpp)
54-
target_link_libraries(pegtl_tests PRIVATE
53+
add_executable(pegtl_combined_tests PegtlCombinedTests.cpp)
54+
target_link_libraries(pegtl_combined_tests PRIVATE
5555
taocpp::pegtl
5656
GTest::GTest
5757
GTest::Main)
58-
target_include_directories(pegtl_tests PUBLIC
58+
target_include_directories(pegtl_combined_tests PUBLIC
5959
${CMAKE_CURRENT_SOURCE_DIR}/../include
6060
${CMAKE_CURRENT_SOURCE_DIR}/../PEGTL/include)
61-
gtest_add_tests(TARGET pegtl_tests)
61+
gtest_add_tests(TARGET pegtl_combined_tests)
62+
63+
add_executable(pegtl_executable_tests PegtlExecutableTests.cpp)
64+
target_link_libraries(pegtl_executable_tests PRIVATE
65+
taocpp::pegtl
66+
GTest::GTest
67+
GTest::Main)
68+
target_include_directories(pegtl_executable_tests PUBLIC
69+
${CMAKE_CURRENT_SOURCE_DIR}/../include
70+
${CMAKE_CURRENT_SOURCE_DIR}/../PEGTL/include)
71+
gtest_add_tests(TARGET pegtl_executable_tests)
72+
73+
add_executable(pegtl_schema_tests PegtlSchemaTests.cpp)
74+
target_link_libraries(pegtl_schema_tests PRIVATE
75+
taocpp::pegtl
76+
GTest::GTest
77+
GTest::Main)
78+
target_include_directories(pegtl_schema_tests PUBLIC
79+
${CMAKE_CURRENT_SOURCE_DIR}/../include
80+
${CMAKE_CURRENT_SOURCE_DIR}/../PEGTL/include)
81+
gtest_add_tests(TARGET pegtl_schema_tests)
6282

6383
add_executable(response_tests ResponseTests.cpp)
6484
target_link_libraries(response_tests PRIVATE
@@ -96,6 +116,8 @@ if(WIN32 AND BUILD_SHARED_LIBS)
96116
add_dependencies(client_tests copy_test_dlls)
97117
add_dependencies(nointrospection_tests copy_test_dlls)
98118
add_dependencies(argument_tests copy_test_dlls)
99-
add_dependencies(pegtl_tests copy_test_dlls)
119+
add_dependencies(pegtl_combined_tests copy_test_dlls)
120+
add_dependencies(pegtl_executable_tests copy_test_dlls)
121+
add_dependencies(pegtl_schema_tests copy_test_dlls)
100122
add_dependencies(response_tests copy_test_dlls)
101123
endif()

test/PegtlCombinedTests.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
#include <gtest/gtest.h>
5+
6+
#include "graphqlservice/GraphQLGrammar.h"
7+
8+
#include <tao/pegtl/contrib/analyze.hpp>
9+
10+
using namespace graphql;
11+
using namespace graphql::peg;
12+
13+
using namespace tao::graphqlpeg;
14+
15+
TEST(PegtlCombinedCase, AnalyzeMixedGrammar)
16+
{
17+
ASSERT_EQ(0, analyze<mixed_document>(true))
18+
<< "there shouldn't be any infinite loops in the PEG version of the grammar";
19+
}

test/PegtlExecutableTests.cpp

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
#include <gtest/gtest.h>
5+
6+
#include "graphqlservice/GraphQLGrammar.h"
7+
8+
#include <tao/pegtl/contrib/analyze.hpp>
9+
10+
using namespace graphql;
11+
using namespace graphql::peg;
12+
13+
using namespace tao::graphqlpeg;
14+
15+
TEST(PegtlExecutableCase, ParseKitchenSinkQuery)
16+
{
17+
memory_input<> input(R"gql(
18+
# Copyright (c) 2015-present, Facebook, Inc.
19+
#
20+
# This source code is licensed under the MIT license found in the
21+
# LICENSE file in the root directory of this source tree.
22+
23+
query queryName($foo: ComplexType, $site: Site = MOBILE) {
24+
whoever123is: node(id: [123, 456]) {
25+
id ,
26+
... on User @defer {
27+
field2 {
28+
id ,
29+
alias: field1(first:10, after:$foo,) @include(if: $foo) {
30+
id,
31+
...frag
32+
}
33+
}
34+
}
35+
... @skip(unless: $foo) {
36+
id
37+
}
38+
... {
39+
id
40+
}
41+
}
42+
}
43+
44+
mutation likeStory {
45+
like(story: 123) @defer {
46+
story {
47+
id
48+
}
49+
}
50+
}
51+
52+
subscription StoryLikeSubscription($input: StoryLikeSubscribeInput) {
53+
storyLikeSubscribe(input: $input) {
54+
story {
55+
likers {
56+
count
57+
}
58+
likeSentence {
59+
text
60+
}
61+
}
62+
}
63+
}
64+
65+
fragment frag on Friend {
66+
foo(size: $size, bar: $b, obj: {key: "value", block: """
67+
68+
block string uses \"""
69+
70+
"""})
71+
}
72+
73+
{
74+
unnamed(truthy: true, falsey: false, nullish: null),
75+
query
76+
})gql",
77+
"ParseKitchenSinkQuery");
78+
79+
const bool result = parse<executable_document>(input);
80+
81+
ASSERT_TRUE(result) << "we should be able to parse the doc";
82+
}
83+
84+
TEST(PegtlExecutableCase, ParseTodayQuery)
85+
{
86+
memory_input<> input(R"gql(
87+
query Everything {
88+
appointments {
89+
edges {
90+
node {
91+
id
92+
subject
93+
when
94+
isNow
95+
}
96+
}
97+
}
98+
tasks {
99+
edges {
100+
node {
101+
id
102+
title
103+
isComplete
104+
}
105+
}
106+
}
107+
unreadCounts {
108+
edges {
109+
node {
110+
id
111+
name
112+
unreadCount
113+
}
114+
}
115+
}
116+
})gql",
117+
"ParseTodayQuery");
118+
119+
const bool result = parse<executable_document>(input);
120+
121+
ASSERT_TRUE(result) << "we should be able to parse the doc";
122+
}
123+
124+
TEST(PegtlExecutableCase, ParseVariableDefaultEmptyList)
125+
{
126+
memory_input<> input(R"gql(
127+
query QueryWithEmptyListVariable($empty: [Boolean!]! = []) {
128+
fieldWithArg(arg: $empty)
129+
})gql",
130+
"ParseVariableDefaultEmptyList");
131+
132+
const bool result = parse<executable_document>(input);
133+
134+
ASSERT_TRUE(result) << "we should be able to parse the doc";
135+
}
136+
137+
TEST(PegtlExecutableCase, AnalyzeExecutableGrammar)
138+
{
139+
ASSERT_EQ(0, analyze<executable_document>(true))
140+
<< "there shouldn't be any infinite loops in the PEG version of the grammar";
141+
}

test/PegtlTests.cpp renamed to test/PegtlSchemaTests.cpp

Lines changed: 3 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -12,76 +12,7 @@ using namespace graphql::peg;
1212

1313
using namespace tao::graphqlpeg;
1414

15-
TEST(PegtlCase, ParseKitchenSinkQuery)
16-
{
17-
memory_input<> input(R"gql(
18-
# Copyright (c) 2015-present, Facebook, Inc.
19-
#
20-
# This source code is licensed under the MIT license found in the
21-
# LICENSE file in the root directory of this source tree.
22-
23-
query queryName($foo: ComplexType, $site: Site = MOBILE) {
24-
whoever123is: node(id: [123, 456]) {
25-
id ,
26-
... on User @defer {
27-
field2 {
28-
id ,
29-
alias: field1(first:10, after:$foo,) @include(if: $foo) {
30-
id,
31-
...frag
32-
}
33-
}
34-
}
35-
... @skip(unless: $foo) {
36-
id
37-
}
38-
... {
39-
id
40-
}
41-
}
42-
}
43-
44-
mutation likeStory {
45-
like(story: 123) @defer {
46-
story {
47-
id
48-
}
49-
}
50-
}
51-
52-
subscription StoryLikeSubscription($input: StoryLikeSubscribeInput) {
53-
storyLikeSubscribe(input: $input) {
54-
story {
55-
likers {
56-
count
57-
}
58-
likeSentence {
59-
text
60-
}
61-
}
62-
}
63-
}
64-
65-
fragment frag on Friend {
66-
foo(size: $size, bar: $b, obj: {key: "value", block: """
67-
68-
block string uses \"""
69-
70-
"""})
71-
}
72-
73-
{
74-
unnamed(truthy: true, falsey: false, nullish: null),
75-
query
76-
})gql",
77-
"ParseKitchenSinkQuery");
78-
79-
const bool result = parse<executable_document>(input);
80-
81-
ASSERT_TRUE(result) << "we should be able to parse the doc";
82-
}
83-
84-
TEST(PegtlCase, ParseKitchenSinkSchema)
15+
TEST(PegtlSchemaCase, ParseKitchenSinkSchema)
8516
{
8617
memory_input<> input(R"gql(
8718
# Copyright (c) 2015-present, Facebook, Inc.
@@ -169,47 +100,7 @@ TEST(PegtlCase, ParseKitchenSinkSchema)
169100
ASSERT_TRUE(result) << "we should be able to parse the doc";
170101
}
171102

172-
TEST(PegtlCase, ParseTodayQuery)
173-
{
174-
memory_input<> input(R"gql(
175-
query Everything {
176-
appointments {
177-
edges {
178-
node {
179-
id
180-
subject
181-
when
182-
isNow
183-
}
184-
}
185-
}
186-
tasks {
187-
edges {
188-
node {
189-
id
190-
title
191-
isComplete
192-
}
193-
}
194-
}
195-
unreadCounts {
196-
edges {
197-
node {
198-
id
199-
name
200-
unreadCount
201-
}
202-
}
203-
}
204-
})gql",
205-
"ParseTodayQuery");
206-
207-
const bool result = parse<executable_document>(input);
208-
209-
ASSERT_TRUE(result) << "we should be able to parse the doc";
210-
}
211-
212-
TEST(PegtlCase, ParseTodaySchema)
103+
TEST(PegtlSchemaCase, ParseTodaySchema)
213104
{
214105
memory_input<> input(R"gql(
215106
# Copyright (c) Microsoft Corporation. All rights reserved.
@@ -326,32 +217,7 @@ TEST(PegtlCase, ParseTodaySchema)
326217
ASSERT_TRUE(result) << "we should be able to parse the doc";
327218
}
328219

329-
TEST(PegtlCase, ParseVariableDefaultEmptyList)
330-
{
331-
memory_input<> input(R"gql(
332-
query QueryWithEmptyListVariable($empty: [Boolean!]! = []) {
333-
fieldWithArg(arg: $empty)
334-
})gql",
335-
"ParseVariableDefaultEmptyList");
336-
337-
const bool result = parse<executable_document>(input);
338-
339-
ASSERT_TRUE(result) << "we should be able to parse the doc";
340-
}
341-
342-
TEST(PegtlCase, AnalyzeMixedGrammar)
343-
{
344-
ASSERT_EQ(0, analyze<mixed_document>(true))
345-
<< "there shouldn't be any infinite loops in the PEG version of the grammar";
346-
}
347-
348-
TEST(PegtlCase, AnalyzeExecutableGrammar)
349-
{
350-
ASSERT_EQ(0, analyze<executable_document>(true))
351-
<< "there shouldn't be any infinite loops in the PEG version of the grammar";
352-
}
353-
354-
TEST(PegtlCase, AnalyzeSchemaGrammar)
220+
TEST(PegtlSchemaCase, AnalyzeSchemaGrammar)
355221
{
356222
ASSERT_EQ(0, analyze<schema_document>(true))
357223
<< "there shouldn't be any infinite loops in the PEG version of the grammar";

0 commit comments

Comments
 (0)