Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tasty: properly detect top-level testCases that are referenced by a testGroup elsewhere #107

Open
mrcjkb opened this issue Jun 18, 2023 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@mrcjkb
Copy link
Owner

mrcjkb commented Jun 18, 2023

Do you think tree-sitter could be able to walk up the tree of nodes and detect the testGroup that's just up ahead of the function that defines the list of tests?

Originally posted by @Kleidukos in #102 (comment)

Example:

specs :: TestTree
specs =
  testGroup
    "Parser Tests"
    [ testGroup "Stage 1" stage1Tests
    , testGroup "Stage 2" stage2Tests
    , testGroup "Stage 3" stage3Tests
    , testGroup "Stage 4" stage4Tests
    ]

stage1Tests :: [TestTree]
stage1Tests =
  [ testCase "Multi-digit return" testMultiDigitReturn
  , testCase "Bunch of newlines" testBunchOfNewlines
  , testCase "No newlines" testNoNewlines
  , testCase "Missing closing paren" testMissingClosingParen
  , testCase "Missing return value" testMissingReturnValue
  , testCase "Missing closing brace" testMissingClosingBrace
  ]

should be detected as

  • namespace: "Parser Tests:
    • namespace: "Stage 1
      • [test] -> test cases

Currently, the test groups and test cases are not associated with each other, because there are no tree-sitter queries that link tests with test groups in other trees.

I'm not sure if this is possible with scheme queries, but it is worth looking into.

@mrcjkb
Copy link
Owner Author

mrcjkb commented Jun 20, 2023

Note to self:

This query properly links the stage1Tests function with testGroup "Stage 1" stage1Tests, but there does not seem to be a way to capture both as a @namespace.definition. It looks like only the second @namespace.definition capture is applied.
I don't think scheme is powerful enough to define a capture that encompasses both the testGroup exp_apply and the function.

;; testGroups that call functions with testCases
(
(_
(_
(_
(exp_apply
  (exp_name) @ns_func_name
  (#lua-match? @ns_func_name "^.*testGroup")
  (exp_literal (string) @namespace.name)
  (_ (variable) @ref_name)
) @namespace.definition
)
)
)
(function
  name: (variable) @ref_name
(_
  (exp_apply
    (exp_name) @test_func_name
    (#lua-match? @test_func_name "^.*testCase")
    (exp_literal) @test.name
  ) @test.definition
)
) @namespace.definition
)

@mrcjkb mrcjkb added the help wanted Extra attention is needed label Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant