Skip to content

Commit

Permalink
Split test_query_pysa into query-specific tests
Browse files Browse the repository at this point in the history
Summary:
The `defines(...)` query is a stable query, where by stable I mean we
are not actively working on it, that happens to be used by some existing
pysa infra.

The `callees_with_location(...)` query on the other hand is used not only
by Pysa but by some other static analysis partner teams who are actively
requesting feature changes.

Let's separate out the tests for these two; this will make iterating on
`callees_with_location` more convenient. Test cases are not split
because they share a single scratch project, so I can live with having to
run the entire test in one shot at least for now.

Reviewed By: rchen152

Differential Revision: D61581345

fbshipit-source-id: 6395f27d15264faf36378dfee3fd40440961a91e
  • Loading branch information
stroxler authored and facebook-github-bot committed Aug 21, 2024
1 parent 2cdaf3e commit 6ceda47
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions source/server/test/queryTest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2044,18 +2044,18 @@ let test_handle_query_with_build_system context =
|> ScratchProject.test_server_with ~f:test_query


let test_handle_query_pysa context =
let test_handle_query_callees_with_location context =
let queries_and_expected_responses =
[
( "callees_with_location(wait.bar)",
( "callees_with_location(example.bar)",
{|
{
"response": {
"callees": [
{
"locations": [
{
"path":"wait.py",
"path":"example.py",
"start": {
"line": 4,
"column": 2
Expand All @@ -2067,14 +2067,14 @@ let test_handle_query_pysa context =
}
],
"kind": "function",
"target": "wait.await_me"
"target": "example.await_me"
}
]
}
}
|}
);
( "callees_with_location(wait.does_not_exist)",
( "callees_with_location(example.does_not_exist)",
{|
{
"response": {
Expand All @@ -2083,6 +2083,31 @@ let test_handle_query_pysa context =
}
|}
);
]
in
assert_queries_with_local_root
~context
~sources:
[
( "example.py",
{|
async def await_me() -> int: ...
async def bar():
await_me()
|}
);
]
(List.map queries_and_expected_responses ~f:(fun (query, response) ->
( query,
fun _ ->
response
|> Yojson.Safe.from_string
|> fun json -> `List [`String "Query"; json] |> Yojson.Safe.to_string )))


let test_handle_query_defines context =
let queries_and_expected_responses =
[
( "defines(test)",
{|
{
Expand Down Expand Up @@ -2931,7 +2956,9 @@ let () =
"handle_query_types" >:: OUnitLwt.lwt_wrapper test_handle_types_query;
"handle_query_with_build_system"
>:: OUnitLwt.lwt_wrapper test_handle_query_with_build_system;
"handle_query_pysa" >:: OUnitLwt.lwt_wrapper test_handle_query_pysa;
"handle_query_callees_with_location"
>:: OUnitLwt.lwt_wrapper test_handle_query_callees_with_location;
"handle_query_defines" >:: OUnitLwt.lwt_wrapper test_handle_query_defines;
"expression_level_coverage" >:: OUnitLwt.lwt_wrapper test_expression_level_coverage;
"hover" >:: OUnitLwt.lwt_wrapper test_type_at_location;
"dump_call_graph" >:: OUnitLwt.lwt_wrapper test_dump_call_graph;
Expand Down

0 comments on commit 6ceda47

Please sign in to comment.