Skip to content

Commit c932fb2

Browse files
Chris Dinhfacebook-github-bot
authored andcommitted
Tests for simple suffix
Summary: # Bug Description Watchman would return with missing path components S468253 # This Diff Adds tests for relative root path evaluation Reviewed By: jdelliot Differential Revision: D65908843 fbshipit-source-id: c62c60eda0a324731a94e68b518468d8011e91b8
1 parent a6a75aa commit c932fb2

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This source code is licensed under the MIT license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
# pyre-unsafe
7+
8+
from watchman.integration.lib import WatchmanEdenTestCase
9+
10+
11+
def populate(repo) -> None:
12+
# We ignore ".hg" here just so some of the tests that list files don't have to
13+
# explicitly filter out the contents of this directory. However, in most situations
14+
# the .hg directory normally should not be ignored.
15+
repo.write_file(".watchmanconfig", '{"ignore_dirs":[".hg"]}')
16+
17+
# Create multiple nested directories to test the relative_root option
18+
repo.write_file("foo.c", "1\n")
19+
repo.write_file("subdir/bar.c", "1\n")
20+
repo.write_file("subdir/bar.h", "1\n")
21+
repo.write_file("subdir/subdir2/baz.c", "1\n")
22+
repo.write_file("subdir/subdir2/baz.h", "1\n")
23+
repo.write_file("subdir/subdir2/subdir3/baz.c", "1\n")
24+
25+
repo.commit("initial commit.")
26+
27+
28+
class TestEdenQuery(WatchmanEdenTestCase.WatchmanEdenTestCase):
29+
def test_simple_suffix(self) -> None:
30+
root = self.makeEdenMount(populate)
31+
self.watchmanCommand("watch", root)
32+
33+
# Test each permutation of relative root
34+
relative_roots = ["", "subdir", "subdir/subdir2", "subdir/subdir2/subdir3"]
35+
expected_output = [
36+
[
37+
"foo.c",
38+
"subdir/bar.c",
39+
"subdir/subdir2/baz.c",
40+
"subdir/subdir2/subdir3/baz.c",
41+
],
42+
[
43+
"bar.c",
44+
"subdir2/baz.c",
45+
"subdir2/subdir3/baz.c",
46+
],
47+
[
48+
"baz.c",
49+
"subdir3/baz.c",
50+
],
51+
[
52+
"baz.c",
53+
],
54+
]
55+
for relative_root, output in zip(relative_roots, expected_output):
56+
# Test Simple suffix eval
57+
self.assertFileListsEqual(
58+
self.watchmanCommand(
59+
"query",
60+
root,
61+
{
62+
"relative_root": relative_root,
63+
"expression": ["allof", ["type", "f"], ["suffix", ["c"]]],
64+
"fields": ["name"],
65+
},
66+
)["files"],
67+
output,
68+
)
69+
70+
# Check that it is the same as normal suffix eval
71+
self.assertFileListsEqual(
72+
self.watchmanCommand(
73+
"query",
74+
root,
75+
{
76+
"relative_root": relative_root,
77+
"expression": [
78+
"allof",
79+
# Adding a true expression causes watchman to
80+
# evaluate this normally instead of as a simple suffix
81+
["true"],
82+
["type", "f"],
83+
["suffix", ["c"]],
84+
],
85+
"fields": ["name"],
86+
},
87+
)["files"],
88+
output,
89+
)

0 commit comments

Comments
 (0)