Skip to content

Commit d9d5afd

Browse files
committed
[incrParse] Refactor the test utility to be more modular
This way we can use the same core of the test utility to verify round-tripness of incrementally transferring the syntax tree to swiftSyntax.
1 parent c8226d1 commit d9d5afd

File tree

10 files changed

+469
-314
lines changed

10 files changed

+469
-314
lines changed

test/incrParse/funcs.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %incparse-test %s --test-case NO_CHANGES
3-
// RUN: %incparse-test %s --test-case ADD_FUNC_PARENS
4-
// RUN: %incparse-test %s --test-case ADD_OPENING_BRACE
5-
// RUN: %incparse-test %s --test-case REMOVE_FUNC_KEYWORD
6-
// RUN: %incparse-test %s --test-case ADD_PARAM_NAME
7-
// RUN: %incparse-test %s --test-case ADD_PARAM_TYPE
2+
// RUN: %validate-incrparse %s --test-case NO_CHANGES
3+
// RUN: %validate-incrparse %s --test-case ADD_FUNC_PARENS
4+
// RUN: %validate-incrparse %s --test-case ADD_OPENING_BRACE
5+
// RUN: %validate-incrparse %s --test-case REMOVE_FUNC_KEYWORD
6+
// RUN: %validate-incrparse %s --test-case ADD_PARAM_NAME
7+
// RUN: %validate-incrparse %s --test-case ADD_PARAM_TYPE
88

99
func start() {}
1010

test/incrParse/invalid.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %incparse-test %s --test-case NO_CHANGES
3-
// RUN: %incparse-test %s --test-case NESTED_INITIALIZERS
2+
// RUN: %validate-incrparse %s --test-case NO_CHANGES
3+
// RUN: %validate-incrparse %s --test-case NESTED_INITIALIZERS
44

55
func start() {}
66

test/incrParse/reuse.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %incparse-test %s --test-case ADD_PROPERTY
3-
// RUN: %incparse-test %s --test-case WRAP_IN_CLASS
4-
// RUN: %incparse-test %s --test-case UNWRAP_CLASS
5-
// RUN: %incparse-test %s --test-case NEXT_TOKEN_CALCULATION
2+
// RUN: %validate-incrparse %s --test-case ADD_PROPERTY
3+
// RUN: %validate-incrparse %s --test-case WRAP_IN_CLASS
4+
// RUN: %validate-incrparse %s --test-case UNWRAP_CLASS
5+
// RUN: %validate-incrparse %s --test-case NEXT_TOKEN_CALCULATION
66

77
func start() {}
88

test/incrParse/simple.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %incparse-test %s --test-case REPLACE
3-
// RUN: %incparse-test %s --test-case REPLACE_BY_LONGER
4-
// RUN: %incparse-test %s --test-case REPLACE_BY_SHORTER
5-
// RUN: %incparse-test %s --test-case INSERT
6-
// RUN: %incparse-test %s --test-case REMOVE
7-
// RUN: %incparse-test %s --test-case ATTACH_TO_PREV_NODE
8-
// RUN: %incparse-test %s --test-case CLASS_SURROUNDING
9-
// RUN: %incparse-test %s --test-case MULTI_EDIT
10-
// RUN: %incparse-test %s --test-case MULTI_EDIT_SAME_LINE
11-
// RUN: %incparse-test %s --test-case REPLACE_WITH_MULTI_BYTE_CHAR
12-
// RUN: %incparse-test %s --test-case REPLACE_MULTI_BYTE_CHAR_WITH_SHORTER
13-
// RUN: %incparse-test %s --test-case LAST_CHARACTER_OF_STRUCT
14-
// RUN: %incparse-test %s --test-case ADD_ARRAY_CLOSE_BRACKET
15-
// RUN: %incparse-test %s --test-case ADD_IF_OPEN_BRACE
2+
// RUN: %validate-incrparse %s --test-case REPLACE
3+
// RUN: %validate-incrparse %s --test-case REPLACE_BY_LONGER
4+
// RUN: %validate-incrparse %s --test-case REPLACE_BY_SHORTER
5+
// RUN: %validate-incrparse %s --test-case INSERT
6+
// RUN: %validate-incrparse %s --test-case REMOVE
7+
// RUN: %validate-incrparse %s --test-case ATTACH_TO_PREV_NODE
8+
// RUN: %validate-incrparse %s --test-case CLASS_SURROUNDING
9+
// RUN: %validate-incrparse %s --test-case MULTI_EDIT
10+
// RUN: %validate-incrparse %s --test-case MULTI_EDIT_SAME_LINE
11+
// RUN: %validate-incrparse %s --test-case REPLACE_WITH_MULTI_BYTE_CHAR
12+
// RUN: %validate-incrparse %s --test-case REPLACE_MULTI_BYTE_CHAR_WITH_SHORTER
13+
// RUN: %validate-incrparse %s --test-case LAST_CHARACTER_OF_STRUCT
14+
// RUN: %validate-incrparse %s --test-case ADD_ARRAY_CLOSE_BRACKET
15+
// RUN: %validate-incrparse %s --test-case ADD_IF_OPEN_BRACE
1616

1717
func start() {}
1818

test/lit.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ shutil.rmtree(completion_cache_path, ignore_errors=True)
342342
ccp_opt = "-completion-cache-path %r" % completion_cache_path
343343
lit_config.note("Using code completion cache: " + completion_cache_path)
344344

345-
config.substitutions.append( ('%incparse-test', '%utils/incrparse_test_util.py --temp-dir %t --swift-syntax-test %swift-syntax-test') )
345+
config.substitutions.append( ('%validate-incrparse', '%utils/incrparse/validate_parse.py --temp-dir %t --swift-syntax-test %swift-syntax-test') )
346346
config.substitutions.append( ('%swift_obj_root', config.swift_obj_root) )
347347
config.substitutions.append( ('%swift_src_root', config.swift_src_root) )
348348
config.substitutions.append( ('%{python}', sys.executable) )

tools/swift-syntax-test/swift-syntax-test.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ IncrementalReuseLog("incremental-reuse-log",
143143
"describes all the nodes reused during "
144144
"incremental parsing."));
145145

146+
static llvm::cl::opt<bool>
147+
OmitNodeIds("omit-node-ids",
148+
llvm::cl::desc("If specified, the serialized syntax tree will not "
149+
"include the IDs of the serialized nodes."));
150+
146151
static llvm::cl::opt<std::string>
147152
OutputFilename("output-filename",
148153
llvm::cl::desc("Path to the output file"));
@@ -684,6 +689,17 @@ int doFullParseRoundTrip(const char *MainExecutablePath,
684689
int doSerializeRawTree(const char *MainExecutablePath,
685690
const StringRef InputFile) {
686691
return parseFile(MainExecutablePath, InputFile, [](SourceFile *SF) -> int {
692+
auto SerializeTree = [](llvm::raw_ostream &os, RC<RawSyntax> Root) {
693+
swift::json::Output::UserInfoMap JsonUserInfo;
694+
if (options::OmitNodeIds) {
695+
JsonUserInfo[swift::json::DontSerializeNodeIdsUserInfoKey] =
696+
(void *)true;
697+
}
698+
swift::json::Output out(os, JsonUserInfo);
699+
out << *Root;
700+
os << "\n";
701+
};
702+
687703
auto Root = SF->getSyntaxRoot().getRaw();
688704

689705
if (!options::OutputFilename.empty()) {
@@ -692,13 +708,9 @@ int doSerializeRawTree(const char *MainExecutablePath,
692708
llvm::sys::fs::F_None);
693709
assert(!errorCode && "Couldn't open output file");
694710

695-
swift::json::Output out(os);
696-
out << *Root;
697-
os << "\n";
711+
SerializeTree(os, Root);
698712
} else {
699-
swift::json::Output out(llvm::outs());
700-
out << *Root;
701-
llvm::outs() << "\n";
713+
SerializeTree(llvm::outs(), Root);
702714
}
703715
return EXIT_SUCCESS;
704716
});

utils/deserialize-incremental-syntax-tree.swift

Whitespace-only changes.

0 commit comments

Comments
 (0)