Skip to content

Commit

Permalink
Tests for simple suffix
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Chris Dinh authored and facebook-github-bot committed Nov 13, 2024
1 parent a6a75aa commit c932fb2
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions watchman/integration/eden/test_eden_suffix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

# pyre-unsafe

from watchman.integration.lib import WatchmanEdenTestCase


def populate(repo) -> None:
# We ignore ".hg" here just so some of the tests that list files don't have to
# explicitly filter out the contents of this directory. However, in most situations
# the .hg directory normally should not be ignored.
repo.write_file(".watchmanconfig", '{"ignore_dirs":[".hg"]}')

# Create multiple nested directories to test the relative_root option
repo.write_file("foo.c", "1\n")
repo.write_file("subdir/bar.c", "1\n")
repo.write_file("subdir/bar.h", "1\n")
repo.write_file("subdir/subdir2/baz.c", "1\n")
repo.write_file("subdir/subdir2/baz.h", "1\n")
repo.write_file("subdir/subdir2/subdir3/baz.c", "1\n")

repo.commit("initial commit.")


class TestEdenQuery(WatchmanEdenTestCase.WatchmanEdenTestCase):
def test_simple_suffix(self) -> None:
root = self.makeEdenMount(populate)
self.watchmanCommand("watch", root)

# Test each permutation of relative root
relative_roots = ["", "subdir", "subdir/subdir2", "subdir/subdir2/subdir3"]
expected_output = [
[
"foo.c",
"subdir/bar.c",
"subdir/subdir2/baz.c",
"subdir/subdir2/subdir3/baz.c",
],
[
"bar.c",
"subdir2/baz.c",
"subdir2/subdir3/baz.c",
],
[
"baz.c",
"subdir3/baz.c",
],
[
"baz.c",
],
]
for relative_root, output in zip(relative_roots, expected_output):
# Test Simple suffix eval
self.assertFileListsEqual(
self.watchmanCommand(
"query",
root,
{
"relative_root": relative_root,
"expression": ["allof", ["type", "f"], ["suffix", ["c"]]],
"fields": ["name"],
},
)["files"],
output,
)

# Check that it is the same as normal suffix eval
self.assertFileListsEqual(
self.watchmanCommand(
"query",
root,
{
"relative_root": relative_root,
"expression": [
"allof",
# Adding a true expression causes watchman to
# evaluate this normally instead of as a simple suffix
["true"],
["type", "f"],
["suffix", ["c"]],
],
"fields": ["name"],
},
)["files"],
output,
)

0 comments on commit c932fb2

Please sign in to comment.