Skip to content

Commit

Permalink
Do not import tests in other tests!
Browse files Browse the repository at this point in the history
Summary:
Doing this breaks isolation of tests at the level of *file* isolation, which
is a disaster for iteration because it's impossible to even list tests without
running them, much less isolate them.

It's much better to just duplicate a little helper than to import it and wind
up running the test suite multiple times.

Reviewed By: grievejia

Differential Revision: D57171314

fbshipit-source-id: cc58442199c3fff5115c938918ec4951a52fd78d
  • Loading branch information
stroxler authored and facebook-github-bot committed May 10, 2024
1 parent 527660f commit 7f0b890
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
18 changes: 17 additions & 1 deletion source/errpy_parser/test/locationTest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,23 @@ let statements_print_to_sexp statements =
Base.Sexp.to_string_hum ((Base.List.sexp_of_t Statement.sexp_of_t) statements)


let assert_parsed = StatementTest.assert_parsed
let assert_parsed ~expected text _context =
let check_ast (actual_ast : Ast.Statement.t list) =
assert_equal
~cmp:statements_location_insensitive_equal
~printer:statements_print_to_sexp
expected
actual_ast
in
match PyreErrpyParser.parse_module text with
| Result.Error error -> (
match error with
| PyreErrpyParser.ParserError.Recoverable recoverable -> check_ast recoverable.recovered_ast
| PyreErrpyParser.ParserError.Unrecoverable message ->
let message = Stdlib.Format.sprintf "Unexpected parsing failure: %s" message in
assert_failure message)
| Result.Ok actual_ast -> check_ast actual_ast


let test_assert_locations =
let assert_parsed = assert_parsed in
Expand Down
20 changes: 19 additions & 1 deletion source/menhir_parser/test/locationTest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,25 @@ open Expression
open Statement
open Test

let parse source = Test.trim_extra_indentation source |> GeneratorTest.parse_untrimmed
let parse_untrimmed source =
match PyreMenhirParser.Parser.parse (String.split source ~on:'\n') with
| Result.Ok statements -> Source.create statements
| Result.Error
{
PyreMenhirParser.Parser.Error.location = { Location.start = { Location.line; column }; _ };
_;
} ->
let error =
Format.asprintf
"Could not parse test source at line %d, column %d. Test input:\n%s"
line
column
source
in
failwith error


let parse source = Test.trim_extra_indentation source |> parse_untrimmed

let assert_source_locations source statements =
let parsed_source = parse source in
Expand Down

0 comments on commit 7f0b890

Please sign in to comment.