rbtr-lang-bash 2026.9.0.dev1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rbtr_lang_bash-2026.9.0.dev1/LICENSE +21 -0
- rbtr_lang_bash-2026.9.0.dev1/PKG-INFO +72 -0
- rbtr_lang_bash-2026.9.0.dev1/README.md +45 -0
- rbtr_lang_bash-2026.9.0.dev1/pyproject.toml +59 -0
- rbtr_lang_bash-2026.9.0.dev1/pyproject.toml.orig +62 -0
- rbtr_lang_bash-2026.9.0.dev1/src/rbtr_lang_bash/__init__.py +1 -0
- rbtr_lang_bash-2026.9.0.dev1/src/rbtr_lang_bash/bash.scm +50 -0
- rbtr_lang_bash-2026.9.0.dev1/src/rbtr_lang_bash/plugin.py +64 -0
- rbtr_lang_bash-2026.9.0.dev1/src/rbtr_lang_bash/py.typed +0 -0
- rbtr_lang_bash-2026.9.0.dev1/src/rbtr_lang_bash/tests/__init__.py +0 -0
- rbtr_lang_bash-2026.9.0.dev1/src/rbtr_lang_bash/tests/__snapshots__/test_samples/test_edges_match_snapshot.json +4 -0
- rbtr_lang_bash-2026.9.0.dev1/src/rbtr_lang_bash/tests/__snapshots__/test_samples/test_extraction_matches_snapshot.json +325 -0
- rbtr_lang_bash-2026.9.0.dev1/src/rbtr_lang_bash/tests/cases_docstrings.py +112 -0
- rbtr_lang_bash-2026.9.0.dev1/src/rbtr_lang_bash/tests/cases_extraction.py +138 -0
- rbtr_lang_bash-2026.9.0.dev1/src/rbtr_lang_bash/tests/samples/bash/bash.sh +40 -0
- rbtr_lang_bash-2026.9.0.dev1/src/rbtr_lang_bash/tests/samples/bash/lib/colours.sh +4 -0
- rbtr_lang_bash-2026.9.0.dev1/src/rbtr_lang_bash/tests/test_docstrings.py +50 -0
- rbtr_lang_bash-2026.9.0.dev1/src/rbtr_lang_bash/tests/test_extraction.py +80 -0
- rbtr_lang_bash-2026.9.0.dev1/src/rbtr_lang_bash/tests/test_samples.py +82 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alejandro Giacometti
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rbtr-lang-bash
|
|
3
|
+
Version: 2026.9.0.dev1
|
|
4
|
+
Summary: rbtr — Bash language plugin
|
|
5
|
+
Keywords: code-search,code-index,tree-sitter,static-analysis,semantic-search,developer-tools,bash,shell
|
|
6
|
+
Author: Alejandro Giacometti
|
|
7
|
+
Author-email: Alejandro Giacometti <alejandro.giacometti@gmail.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Unix Shell
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
16
|
+
Classifier: Topic :: Text Processing :: Indexing
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
Requires-Dist: rbtr==2026.9.0.dev1
|
|
19
|
+
Requires-Dist: tree-sitter-bash
|
|
20
|
+
Requires-Python: >=3.13
|
|
21
|
+
Project-URL: Homepage, https://github.com/janrito/rbtr
|
|
22
|
+
Project-URL: Repository, https://github.com/janrito/rbtr
|
|
23
|
+
Project-URL: Documentation, https://github.com/janrito/rbtr/tree/main/packages/rbtr-lang-bash#readme
|
|
24
|
+
Project-URL: Issues, https://github.com/janrito/rbtr/issues
|
|
25
|
+
Project-URL: Changelog, https://github.com/janrito/rbtr/releases
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# rbtr-lang-bash
|
|
29
|
+
|
|
30
|
+
Bash / shell support for [rbtr]. **Default** — installed with
|
|
31
|
+
core `rbtr`, no extra required.
|
|
32
|
+
|
|
33
|
+
[rbtr]: https://github.com/janrito/rbtr/tree/main/packages/rbtr#readme
|
|
34
|
+
|
|
35
|
+
## What it ingests
|
|
36
|
+
|
|
37
|
+
- **Functions** — both `name() { ... }` and `function name { ... }`
|
|
38
|
+
forms. All functions are top-level (bash has no nesting).
|
|
39
|
+
- **Top-level variable assignments** — `MAX=100`, and `alias` names.
|
|
40
|
+
- **Imports** — `source file` and `. file` commands.
|
|
41
|
+
- **Top-level statements** — every other command, pipeline, conditional and
|
|
42
|
+
loop at the top level becomes an anonymous **doc-section** chunk. A script
|
|
43
|
+
that defines nothing is what it does, so `rsync -a ./build/ "$DEST"` is as
|
|
44
|
+
findable as a function.
|
|
45
|
+
|
|
46
|
+
Bash has no classes, methods, or module structure, so none are emitted.
|
|
47
|
+
|
|
48
|
+
## Chunks produced
|
|
49
|
+
|
|
50
|
+
`scope` is always empty. `name` is the function/variable identifier.
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
deploy() { echo deploying; } # function "deploy"
|
|
54
|
+
function setup { ...; } # function "setup"
|
|
55
|
+
MAX=100 # variable "MAX"
|
|
56
|
+
alias ll="ls -l" # variable "ll" (the fused `=` is stripped)
|
|
57
|
+
source ./env.sh # import "./env.sh"
|
|
58
|
+
. /etc/profile # import "/etc/profile"
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
A leading `#` comment run above a function is attached as its
|
|
62
|
+
documentation; a `#!/bin/bash` shebang attaches to the first function
|
|
63
|
+
only when no blank line separates them.
|
|
64
|
+
|
|
65
|
+
## Embedded / injected chunks
|
|
66
|
+
|
|
67
|
+
None. Bash does not embed other languages.
|
|
68
|
+
|
|
69
|
+
## Grammar & dependencies
|
|
70
|
+
|
|
71
|
+
Uses the `tree-sitter-bash` grammar. No dependency on other language
|
|
72
|
+
plugins.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# rbtr-lang-bash
|
|
2
|
+
|
|
3
|
+
Bash / shell support for [rbtr]. **Default** — installed with
|
|
4
|
+
core `rbtr`, no extra required.
|
|
5
|
+
|
|
6
|
+
[rbtr]: https://github.com/janrito/rbtr/tree/main/packages/rbtr#readme
|
|
7
|
+
|
|
8
|
+
## What it ingests
|
|
9
|
+
|
|
10
|
+
- **Functions** — both `name() { ... }` and `function name { ... }`
|
|
11
|
+
forms. All functions are top-level (bash has no nesting).
|
|
12
|
+
- **Top-level variable assignments** — `MAX=100`, and `alias` names.
|
|
13
|
+
- **Imports** — `source file` and `. file` commands.
|
|
14
|
+
- **Top-level statements** — every other command, pipeline, conditional and
|
|
15
|
+
loop at the top level becomes an anonymous **doc-section** chunk. A script
|
|
16
|
+
that defines nothing is what it does, so `rsync -a ./build/ "$DEST"` is as
|
|
17
|
+
findable as a function.
|
|
18
|
+
|
|
19
|
+
Bash has no classes, methods, or module structure, so none are emitted.
|
|
20
|
+
|
|
21
|
+
## Chunks produced
|
|
22
|
+
|
|
23
|
+
`scope` is always empty. `name` is the function/variable identifier.
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
deploy() { echo deploying; } # function "deploy"
|
|
27
|
+
function setup { ...; } # function "setup"
|
|
28
|
+
MAX=100 # variable "MAX"
|
|
29
|
+
alias ll="ls -l" # variable "ll" (the fused `=` is stripped)
|
|
30
|
+
source ./env.sh # import "./env.sh"
|
|
31
|
+
. /etc/profile # import "/etc/profile"
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
A leading `#` comment run above a function is attached as its
|
|
35
|
+
documentation; a `#!/bin/bash` shebang attaches to the first function
|
|
36
|
+
only when no blank line separates them.
|
|
37
|
+
|
|
38
|
+
## Embedded / injected chunks
|
|
39
|
+
|
|
40
|
+
None. Bash does not embed other languages.
|
|
41
|
+
|
|
42
|
+
## Grammar & dependencies
|
|
43
|
+
|
|
44
|
+
Uses the `tree-sitter-bash` grammar. No dependency on other language
|
|
45
|
+
plugins.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["uv_build>=0.11.26,<1"]
|
|
3
|
+
build-backend = "uv_build"
|
|
4
|
+
|
|
5
|
+
[tool.uv.build-backend]
|
|
6
|
+
module-name = "rbtr_lang_bash"
|
|
7
|
+
|
|
8
|
+
[tool.uv.sources.rbtr]
|
|
9
|
+
workspace = true
|
|
10
|
+
|
|
11
|
+
[project]
|
|
12
|
+
name = "rbtr-lang-bash"
|
|
13
|
+
version = "2026.9.0-dev1"
|
|
14
|
+
description = "rbtr — Bash language plugin"
|
|
15
|
+
readme = "README.md"
|
|
16
|
+
license = "MIT"
|
|
17
|
+
license-files = ["LICENSE"]
|
|
18
|
+
keywords = [
|
|
19
|
+
"code-search",
|
|
20
|
+
"code-index",
|
|
21
|
+
"tree-sitter",
|
|
22
|
+
"static-analysis",
|
|
23
|
+
"semantic-search",
|
|
24
|
+
"developer-tools",
|
|
25
|
+
"bash",
|
|
26
|
+
"shell",
|
|
27
|
+
]
|
|
28
|
+
classifiers = [
|
|
29
|
+
"Development Status :: 4 - Beta",
|
|
30
|
+
"Intended Audience :: Developers",
|
|
31
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
32
|
+
"Programming Language :: Python :: 3.13",
|
|
33
|
+
"Programming Language :: Unix Shell",
|
|
34
|
+
"Topic :: Software Development :: Libraries",
|
|
35
|
+
"Topic :: Text Processing :: Indexing",
|
|
36
|
+
"Typing :: Typed",
|
|
37
|
+
]
|
|
38
|
+
requires-python = ">=3.13"
|
|
39
|
+
dependencies = [
|
|
40
|
+
"rbtr==2026.9.0-dev1",
|
|
41
|
+
"tree-sitter-bash",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[[project.authors]]
|
|
45
|
+
name = "Alejandro Giacometti"
|
|
46
|
+
email = "alejandro.giacometti@gmail.com"
|
|
47
|
+
|
|
48
|
+
[project.urls]
|
|
49
|
+
Homepage = "https://github.com/janrito/rbtr"
|
|
50
|
+
Repository = "https://github.com/janrito/rbtr"
|
|
51
|
+
Documentation = "https://github.com/janrito/rbtr/tree/main/packages/rbtr-lang-bash#readme"
|
|
52
|
+
Issues = "https://github.com/janrito/rbtr/issues"
|
|
53
|
+
Changelog = "https://github.com/janrito/rbtr/releases"
|
|
54
|
+
|
|
55
|
+
[project.entry-points."rbtr.languages"]
|
|
56
|
+
bash = "rbtr_lang_bash.plugin:bash"
|
|
57
|
+
|
|
58
|
+
[dependency-groups]
|
|
59
|
+
dev = ["rbtr[test]"]
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["uv_build>=0.11.26,<1"]
|
|
3
|
+
build-backend = "uv_build"
|
|
4
|
+
|
|
5
|
+
[tool.uv.build-backend]
|
|
6
|
+
module-name = "rbtr_lang_bash"
|
|
7
|
+
# No source-exclude: the plugin's tests, samples, and snapshots ship
|
|
8
|
+
# with the wheel, and bash.scm ships as package data.
|
|
9
|
+
|
|
10
|
+
[project]
|
|
11
|
+
name = "rbtr-lang-bash"
|
|
12
|
+
version = "2026.9.0-dev1"
|
|
13
|
+
description = "rbtr — Bash language plugin"
|
|
14
|
+
readme = "README.md"
|
|
15
|
+
license = "MIT"
|
|
16
|
+
license-files = ["LICENSE"]
|
|
17
|
+
authors = [
|
|
18
|
+
{ name = "Alejandro Giacometti", email = "alejandro.giacometti@gmail.com" },
|
|
19
|
+
]
|
|
20
|
+
keywords = [
|
|
21
|
+
"code-search",
|
|
22
|
+
"code-index",
|
|
23
|
+
"tree-sitter",
|
|
24
|
+
"static-analysis",
|
|
25
|
+
"semantic-search",
|
|
26
|
+
"developer-tools",
|
|
27
|
+
"bash",
|
|
28
|
+
"shell",
|
|
29
|
+
]
|
|
30
|
+
classifiers = [
|
|
31
|
+
"Development Status :: 4 - Beta",
|
|
32
|
+
"Intended Audience :: Developers",
|
|
33
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
34
|
+
"Programming Language :: Python :: 3.13",
|
|
35
|
+
"Programming Language :: Unix Shell",
|
|
36
|
+
"Topic :: Software Development :: Libraries",
|
|
37
|
+
"Topic :: Text Processing :: Indexing",
|
|
38
|
+
"Typing :: Typed",
|
|
39
|
+
]
|
|
40
|
+
requires-python = ">=3.13"
|
|
41
|
+
dependencies = [
|
|
42
|
+
"rbtr==2026.9.0-dev1",
|
|
43
|
+
"tree-sitter-bash",
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
[project.urls]
|
|
47
|
+
Homepage = "https://github.com/janrito/rbtr"
|
|
48
|
+
Repository = "https://github.com/janrito/rbtr"
|
|
49
|
+
Documentation = "https://github.com/janrito/rbtr/tree/main/packages/rbtr-lang-bash#readme"
|
|
50
|
+
Issues = "https://github.com/janrito/rbtr/issues"
|
|
51
|
+
Changelog = "https://github.com/janrito/rbtr/releases"
|
|
52
|
+
|
|
53
|
+
[project.entry-points."rbtr.languages"]
|
|
54
|
+
# The value resolves to the language's `LanguageRegistration` (named by its
|
|
55
|
+
# id) — see the rbtr ARCHITECTURE "External plugins" note.
|
|
56
|
+
bash = "rbtr_lang_bash.plugin:bash"
|
|
57
|
+
|
|
58
|
+
[tool.uv.sources]
|
|
59
|
+
rbtr = { workspace = true }
|
|
60
|
+
|
|
61
|
+
[dependency-groups]
|
|
62
|
+
dev = ["rbtr[test]"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Bash language plugin package."""
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
; Top-level comments (Bash: single `comment` type).
|
|
2
|
+
(comment) @comment
|
|
3
|
+
|
|
4
|
+
(function_definition
|
|
5
|
+
name: (word) @_fn_name) @function
|
|
6
|
+
|
|
7
|
+
(command
|
|
8
|
+
name: (command_name
|
|
9
|
+
(word) @_cmd)
|
|
10
|
+
.
|
|
11
|
+
(word) @_import_module
|
|
12
|
+
(#eq? @_cmd "source")) @import
|
|
13
|
+
|
|
14
|
+
(command
|
|
15
|
+
name: (command_name
|
|
16
|
+
(word) @_cmd)
|
|
17
|
+
.
|
|
18
|
+
(word) @_import_module
|
|
19
|
+
(#eq? @_cmd ".")) @import
|
|
20
|
+
|
|
21
|
+
(program
|
|
22
|
+
(variable_assignment
|
|
23
|
+
name: (variable_name) @_var_name) @variable)
|
|
24
|
+
|
|
25
|
+
(program
|
|
26
|
+
(declaration_command
|
|
27
|
+
(variable_assignment
|
|
28
|
+
name: (variable_name) @_var_name)) @variable)
|
|
29
|
+
|
|
30
|
+
(command
|
|
31
|
+
name: (command_name (word) @_cmd)
|
|
32
|
+
argument: (concatenation (word) @_var_name)
|
|
33
|
+
(#eq? @_cmd "alias")
|
|
34
|
+
(#match? @_var_name "=")) @variable
|
|
35
|
+
|
|
36
|
+
; A script's top-level statements are what it does, and no name stands
|
|
37
|
+
; for them, so each is an anonymous section located by its lines. A
|
|
38
|
+
; script that defines nothing is still entirely searchable.
|
|
39
|
+
(program
|
|
40
|
+
(command
|
|
41
|
+
name: (command_name (word) @_statement)
|
|
42
|
+
; `source`, `.` and `alias` are already an import or a variable above.
|
|
43
|
+
; One `#not-match?` rather than several `#not-any-of?` arguments, which
|
|
44
|
+
; this binding applies only when given exactly one.
|
|
45
|
+
(#not-match? @_statement "^(source|[.]|alias)$")) @doc_section)
|
|
46
|
+
|
|
47
|
+
(program
|
|
48
|
+
[(if_statement) (for_statement) (while_statement) (case_statement)
|
|
49
|
+
(pipeline) (list) (subshell) (compound_statement) (unset_command)
|
|
50
|
+
(redirected_statement)] @doc_section)
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""Bash language plugin.
|
|
2
|
+
|
|
3
|
+
Provides function extraction only — Bash has no import system,
|
|
4
|
+
class system, or module structure.
|
|
5
|
+
|
|
6
|
+
Extracted chunks::
|
|
7
|
+
|
|
8
|
+
deploy() { echo deploying; } → function "deploy", scope ""
|
|
9
|
+
function setup { ... } → function "setup", scope ""
|
|
10
|
+
alias ll="ls -l" → variable "ll", scope ""
|
|
11
|
+
|
|
12
|
+
No classes or methods are extracted.
|
|
13
|
+
|
|
14
|
+
An `alias` name parses as one `word` fused with its `=` (`ll=`), which no
|
|
15
|
+
query can split. The `name_extractor` strips the trailing `=`; no other
|
|
16
|
+
bash name ends in one.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
from typing import TYPE_CHECKING
|
|
22
|
+
|
|
23
|
+
from rbtr.languages.registration import (
|
|
24
|
+
LanguageRegistration,
|
|
25
|
+
NameResolver,
|
|
26
|
+
QueryExtraction,
|
|
27
|
+
load_query,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
if TYPE_CHECKING:
|
|
31
|
+
from tree_sitter import Node
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# ── Query ────────────────────────────────────────────────────────────
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
# ── Plugin ───────────────────────────────────────────────────────────
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
bash = LanguageRegistration(
|
|
41
|
+
id="bash",
|
|
42
|
+
extensions=frozenset({".sh", ".bash", ".zsh"}),
|
|
43
|
+
filenames=frozenset(
|
|
44
|
+
{
|
|
45
|
+
"Bashrc",
|
|
46
|
+
".bashrc",
|
|
47
|
+
".bash_profile",
|
|
48
|
+
".zshrc",
|
|
49
|
+
}
|
|
50
|
+
),
|
|
51
|
+
grammar_module="tree_sitter_bash",
|
|
52
|
+
extraction=QueryExtraction(
|
|
53
|
+
query=load_query(__package__, "bash"),
|
|
54
|
+
),
|
|
55
|
+
extraction_serial=5,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@bash.name_extractor
|
|
60
|
+
def _strip_alias_eq(
|
|
61
|
+
resolver: NameResolver, capture_name: str, node: Node, captures: dict[str, list[Node]]
|
|
62
|
+
) -> str:
|
|
63
|
+
"""Default name, with the `=` the grammar fuses onto an alias removed."""
|
|
64
|
+
return resolver(capture_name, node, captures).rstrip("=")
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"blob_sha": "sha1",
|
|
4
|
+
"file_path": "bash.sh",
|
|
5
|
+
"kind": "comment",
|
|
6
|
+
"name": "",
|
|
7
|
+
"scope": "",
|
|
8
|
+
"language": "bash",
|
|
9
|
+
"file_language": "bash",
|
|
10
|
+
"content": "#!/usr/bin/env bash\n# Greeter — print greetings for named recipients.\n#\n# Bash has no classes or methods; the plugin extracts functions,\n# top-level variable assignments (including export/declare/readonly),\n# aliases, and source/. imports.",
|
|
11
|
+
"line_start": 1,
|
|
12
|
+
"line_end": 6,
|
|
13
|
+
"metadata": {
|
|
14
|
+
"module": "",
|
|
15
|
+
"names": "",
|
|
16
|
+
"dots": "",
|
|
17
|
+
"language_hint": ""
|
|
18
|
+
},
|
|
19
|
+
"id": "e4307a2c6ea35a81"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"blob_sha": "sha1",
|
|
23
|
+
"file_path": "bash.sh",
|
|
24
|
+
"kind": "import",
|
|
25
|
+
"name": "source ./lib/colours.sh",
|
|
26
|
+
"scope": "",
|
|
27
|
+
"language": "bash",
|
|
28
|
+
"file_language": "bash",
|
|
29
|
+
"content": "source ./lib/colours.sh",
|
|
30
|
+
"line_start": 8,
|
|
31
|
+
"line_end": 8,
|
|
32
|
+
"metadata": {
|
|
33
|
+
"module": "./lib/colours.sh",
|
|
34
|
+
"names": "",
|
|
35
|
+
"dots": "",
|
|
36
|
+
"language_hint": ""
|
|
37
|
+
},
|
|
38
|
+
"id": "9265bcd393cdbfc7"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"blob_sha": "sha1",
|
|
42
|
+
"file_path": "bash.sh",
|
|
43
|
+
"kind": "import",
|
|
44
|
+
"name": ". /etc/greeter.conf",
|
|
45
|
+
"scope": "",
|
|
46
|
+
"language": "bash",
|
|
47
|
+
"file_language": "bash",
|
|
48
|
+
"content": ". /etc/greeter.conf",
|
|
49
|
+
"line_start": 9,
|
|
50
|
+
"line_end": 9,
|
|
51
|
+
"metadata": {
|
|
52
|
+
"module": "/etc/greeter.conf",
|
|
53
|
+
"names": "",
|
|
54
|
+
"dots": "",
|
|
55
|
+
"language_hint": ""
|
|
56
|
+
},
|
|
57
|
+
"id": "9e439113ee561e27"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"blob_sha": "sha1",
|
|
61
|
+
"file_path": "bash.sh",
|
|
62
|
+
"kind": "variable",
|
|
63
|
+
"name": "DEFAULT_GREETING",
|
|
64
|
+
"scope": "",
|
|
65
|
+
"language": "bash",
|
|
66
|
+
"file_language": "bash",
|
|
67
|
+
"content": "DEFAULT_GREETING=\"Hello\"",
|
|
68
|
+
"line_start": 11,
|
|
69
|
+
"line_end": 11,
|
|
70
|
+
"metadata": {
|
|
71
|
+
"module": "",
|
|
72
|
+
"names": "",
|
|
73
|
+
"dots": "",
|
|
74
|
+
"language_hint": ""
|
|
75
|
+
},
|
|
76
|
+
"id": "38cfd35861b45035"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"blob_sha": "sha1",
|
|
80
|
+
"file_path": "bash.sh",
|
|
81
|
+
"kind": "comment",
|
|
82
|
+
"name": "",
|
|
83
|
+
"scope": "",
|
|
84
|
+
"language": "bash",
|
|
85
|
+
"file_language": "bash",
|
|
86
|
+
"content": "# trailing comment: its own chunk",
|
|
87
|
+
"line_start": 11,
|
|
88
|
+
"line_end": 11,
|
|
89
|
+
"metadata": {
|
|
90
|
+
"module": "",
|
|
91
|
+
"names": "",
|
|
92
|
+
"dots": "",
|
|
93
|
+
"language_hint": ""
|
|
94
|
+
},
|
|
95
|
+
"id": "c8b87f6c0550268b"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"blob_sha": "sha1",
|
|
99
|
+
"file_path": "bash.sh",
|
|
100
|
+
"kind": "variable",
|
|
101
|
+
"name": "LOCALE",
|
|
102
|
+
"scope": "",
|
|
103
|
+
"language": "bash",
|
|
104
|
+
"file_language": "bash",
|
|
105
|
+
"content": "# Standalone note, separated by blank lines from any definition.\n# Second line of the same block.\nLOCALE=\"${LANG:-en}\"",
|
|
106
|
+
"line_start": 13,
|
|
107
|
+
"line_end": 15,
|
|
108
|
+
"metadata": {
|
|
109
|
+
"module": "",
|
|
110
|
+
"names": "",
|
|
111
|
+
"dots": "",
|
|
112
|
+
"language_hint": ""
|
|
113
|
+
},
|
|
114
|
+
"id": "d74e7f5621a74641"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"blob_sha": "sha1",
|
|
118
|
+
"file_path": "bash.sh",
|
|
119
|
+
"kind": "variable",
|
|
120
|
+
"name": "API_URL",
|
|
121
|
+
"scope": "",
|
|
122
|
+
"language": "bash",
|
|
123
|
+
"file_language": "bash",
|
|
124
|
+
"content": "export API_URL=\"https://example.com\"",
|
|
125
|
+
"line_start": 16,
|
|
126
|
+
"line_end": 16,
|
|
127
|
+
"metadata": {
|
|
128
|
+
"module": "",
|
|
129
|
+
"names": "",
|
|
130
|
+
"dots": "",
|
|
131
|
+
"language_hint": ""
|
|
132
|
+
},
|
|
133
|
+
"id": "1139af1e903fa001"
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"blob_sha": "sha1",
|
|
137
|
+
"file_path": "bash.sh",
|
|
138
|
+
"kind": "variable",
|
|
139
|
+
"name": "MAX_RETRIES",
|
|
140
|
+
"scope": "",
|
|
141
|
+
"language": "bash",
|
|
142
|
+
"file_language": "bash",
|
|
143
|
+
"content": "readonly MAX_RETRIES=3",
|
|
144
|
+
"line_start": 17,
|
|
145
|
+
"line_end": 17,
|
|
146
|
+
"metadata": {
|
|
147
|
+
"module": "",
|
|
148
|
+
"names": "",
|
|
149
|
+
"dots": "",
|
|
150
|
+
"language_hint": ""
|
|
151
|
+
},
|
|
152
|
+
"id": "b892bc4e4a150620"
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
"blob_sha": "sha1",
|
|
156
|
+
"file_path": "bash.sh",
|
|
157
|
+
"kind": "variable",
|
|
158
|
+
"name": "COUNTER",
|
|
159
|
+
"scope": "",
|
|
160
|
+
"language": "bash",
|
|
161
|
+
"file_language": "bash",
|
|
162
|
+
"content": "declare -i COUNTER=0",
|
|
163
|
+
"line_start": 18,
|
|
164
|
+
"line_end": 18,
|
|
165
|
+
"metadata": {
|
|
166
|
+
"module": "",
|
|
167
|
+
"names": "",
|
|
168
|
+
"dots": "",
|
|
169
|
+
"language_hint": ""
|
|
170
|
+
},
|
|
171
|
+
"id": "2a9cfb0b1658749c"
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
"blob_sha": "sha1",
|
|
175
|
+
"file_path": "bash.sh",
|
|
176
|
+
"kind": "variable",
|
|
177
|
+
"name": "greet",
|
|
178
|
+
"scope": "",
|
|
179
|
+
"language": "bash",
|
|
180
|
+
"file_language": "bash",
|
|
181
|
+
"content": "alias greet=\"format_greeting\"",
|
|
182
|
+
"line_start": 19,
|
|
183
|
+
"line_end": 19,
|
|
184
|
+
"metadata": {
|
|
185
|
+
"module": "",
|
|
186
|
+
"names": "",
|
|
187
|
+
"dots": "",
|
|
188
|
+
"language_hint": ""
|
|
189
|
+
},
|
|
190
|
+
"id": "2b5409aa288fb92c"
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
"blob_sha": "sha1",
|
|
194
|
+
"file_path": "bash.sh",
|
|
195
|
+
"kind": "function",
|
|
196
|
+
"name": "format_greeting",
|
|
197
|
+
"scope": "",
|
|
198
|
+
"language": "bash",
|
|
199
|
+
"file_language": "bash",
|
|
200
|
+
"content": "# Format a greeting for a single recipient.\nformat_greeting() {\n local name=\"$1\"\n echo \"${DEFAULT_GREETING}, ${name} (${LOCALE})\"\n}",
|
|
201
|
+
"line_start": 21,
|
|
202
|
+
"line_end": 25,
|
|
203
|
+
"metadata": {
|
|
204
|
+
"module": "",
|
|
205
|
+
"names": "",
|
|
206
|
+
"dots": "",
|
|
207
|
+
"language_hint": ""
|
|
208
|
+
},
|
|
209
|
+
"id": "b57d1fd8270452eb"
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
"blob_sha": "sha1",
|
|
213
|
+
"file_path": "bash.sh",
|
|
214
|
+
"kind": "function",
|
|
215
|
+
"name": "greet_all",
|
|
216
|
+
"scope": "",
|
|
217
|
+
"language": "bash",
|
|
218
|
+
"file_language": "bash",
|
|
219
|
+
"content": "# Greet every argument in turn.\ngreet_all() {\n for name in \"$@\"; do\n format_greeting \"$name\"\n done\n}",
|
|
220
|
+
"line_start": 27,
|
|
221
|
+
"line_end": 32,
|
|
222
|
+
"metadata": {
|
|
223
|
+
"module": "",
|
|
224
|
+
"names": "",
|
|
225
|
+
"dots": "",
|
|
226
|
+
"language_hint": ""
|
|
227
|
+
},
|
|
228
|
+
"id": "938eaca775c955f0"
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
"blob_sha": "sha1",
|
|
232
|
+
"file_path": "bash.sh",
|
|
233
|
+
"kind": "doc_section",
|
|
234
|
+
"name": "",
|
|
235
|
+
"scope": "",
|
|
236
|
+
"language": "bash",
|
|
237
|
+
"file_language": "bash",
|
|
238
|
+
"content": "greet_all \"$@\"",
|
|
239
|
+
"line_start": 34,
|
|
240
|
+
"line_end": 34,
|
|
241
|
+
"metadata": {
|
|
242
|
+
"module": "",
|
|
243
|
+
"names": "",
|
|
244
|
+
"dots": "",
|
|
245
|
+
"language_hint": ""
|
|
246
|
+
},
|
|
247
|
+
"id": "28fef2e3cc81696c"
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
"blob_sha": "sha1",
|
|
251
|
+
"file_path": "bash.sh",
|
|
252
|
+
"kind": "doc_section",
|
|
253
|
+
"name": "",
|
|
254
|
+
"scope": "",
|
|
255
|
+
"language": "bash",
|
|
256
|
+
"file_language": "bash",
|
|
257
|
+
"content": "mkdir -p \"${HOME}/.greeter\"",
|
|
258
|
+
"line_start": 36,
|
|
259
|
+
"line_end": 36,
|
|
260
|
+
"metadata": {
|
|
261
|
+
"module": "",
|
|
262
|
+
"names": "",
|
|
263
|
+
"dots": "",
|
|
264
|
+
"language_hint": ""
|
|
265
|
+
},
|
|
266
|
+
"id": "3b9dadb425a9561b"
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
"blob_sha": "sha1",
|
|
270
|
+
"file_path": "bash.sh",
|
|
271
|
+
"kind": "doc_section",
|
|
272
|
+
"name": "",
|
|
273
|
+
"scope": "",
|
|
274
|
+
"language": "bash",
|
|
275
|
+
"file_language": "bash",
|
|
276
|
+
"content": "if [ -z \"${GREETER_QUIET:-}\" ]; then\n greet \"$DEFAULT_GREETING\"\nfi",
|
|
277
|
+
"line_start": 38,
|
|
278
|
+
"line_end": 40,
|
|
279
|
+
"metadata": {
|
|
280
|
+
"module": "",
|
|
281
|
+
"names": "",
|
|
282
|
+
"dots": "",
|
|
283
|
+
"language_hint": ""
|
|
284
|
+
},
|
|
285
|
+
"id": "1c837acadf784a90"
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
"blob_sha": "sha1",
|
|
289
|
+
"file_path": "lib/colours.sh",
|
|
290
|
+
"kind": "variable",
|
|
291
|
+
"name": "RED",
|
|
292
|
+
"scope": "",
|
|
293
|
+
"language": "bash",
|
|
294
|
+
"file_language": "bash",
|
|
295
|
+
"content": "#!/usr/bin/env bash\n# Terminal colour codes.\nRED='\\033[0;31m'",
|
|
296
|
+
"line_start": 1,
|
|
297
|
+
"line_end": 3,
|
|
298
|
+
"metadata": {
|
|
299
|
+
"module": "",
|
|
300
|
+
"names": "",
|
|
301
|
+
"dots": "",
|
|
302
|
+
"language_hint": ""
|
|
303
|
+
},
|
|
304
|
+
"id": "a0e8a338025ec509"
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
"blob_sha": "sha1",
|
|
308
|
+
"file_path": "lib/colours.sh",
|
|
309
|
+
"kind": "variable",
|
|
310
|
+
"name": "RESET",
|
|
311
|
+
"scope": "",
|
|
312
|
+
"language": "bash",
|
|
313
|
+
"file_language": "bash",
|
|
314
|
+
"content": "RESET='\\033[0m'",
|
|
315
|
+
"line_start": 4,
|
|
316
|
+
"line_end": 4,
|
|
317
|
+
"metadata": {
|
|
318
|
+
"module": "",
|
|
319
|
+
"names": "",
|
|
320
|
+
"dots": "",
|
|
321
|
+
"language_hint": ""
|
|
322
|
+
},
|
|
323
|
+
"id": "19e70f62367c0169"
|
|
324
|
+
}
|
|
325
|
+
]
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"""Bash docstring-extraction test cases.
|
|
2
|
+
|
|
3
|
+
tree-sitter-bash uses a single `comment` node for any `#` line. Function
|
|
4
|
+
docs are a `#` comment run directly above the definition; a shebang
|
|
5
|
+
(`#!/bin/bash`) attaches to the first function only when no blank line
|
|
6
|
+
separates them.
|
|
7
|
+
|
|
8
|
+
Each `@case` returns `(lang, source, symbol_name, snippet)`; see
|
|
9
|
+
`test_docstrings.py` for the assertion direction per tag.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from pytest_cases import case
|
|
15
|
+
|
|
16
|
+
type DocstringCase = tuple[str, str, str, str]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@case(tags=["documented", "canonical", "exterior_doc"])
|
|
20
|
+
def case_bash_hash_doc_on_function() -> DocstringCase:
|
|
21
|
+
"""Canonical `#` comment above a shell function."""
|
|
22
|
+
src = """\
|
|
23
|
+
# Greet the user.
|
|
24
|
+
greet() {
|
|
25
|
+
echo hello
|
|
26
|
+
}
|
|
27
|
+
"""
|
|
28
|
+
return "bash", src, "greet", "Greet the user"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@case(tags=["documented", "canonical", "exterior_doc"])
|
|
32
|
+
def case_bash_multi_line_hash_doc() -> DocstringCase:
|
|
33
|
+
"""Multi-line `#` comment run."""
|
|
34
|
+
src = """\
|
|
35
|
+
# Greet the user.
|
|
36
|
+
#
|
|
37
|
+
# Reads the name from $1.
|
|
38
|
+
greet() {
|
|
39
|
+
echo hi $1
|
|
40
|
+
}
|
|
41
|
+
"""
|
|
42
|
+
return "bash", src, "greet", "Reads the name from"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@case(tags=["documented", "edge_case", "exterior_doc"])
|
|
46
|
+
def case_bash_shebang_attached_to_first_function() -> DocstringCase:
|
|
47
|
+
"""When a function follows the shebang with no blank line,
|
|
48
|
+
the shebang attaches — an honest consequence of the
|
|
49
|
+
flexible attachment policy. Recording this as a case so
|
|
50
|
+
any future tightening does not regress silently.
|
|
51
|
+
"""
|
|
52
|
+
src = """\
|
|
53
|
+
#!/bin/bash
|
|
54
|
+
# Entry point.
|
|
55
|
+
main() {
|
|
56
|
+
echo hi
|
|
57
|
+
}
|
|
58
|
+
"""
|
|
59
|
+
return "bash", src, "main", "#!/bin/bash"
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@case(tags=["documented", "unconventional", "exterior_doc"])
|
|
63
|
+
def case_bash_comment_with_script_style_heading() -> DocstringCase:
|
|
64
|
+
"""Heading-like comment above a function attaches."""
|
|
65
|
+
src = """\
|
|
66
|
+
# ==== helpers ====
|
|
67
|
+
# Trim whitespace from $1.
|
|
68
|
+
trim() {
|
|
69
|
+
echo "$1"
|
|
70
|
+
}
|
|
71
|
+
"""
|
|
72
|
+
return "bash", src, "trim", "Trim whitespace"
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@case(tags=["undocumented", "no_docs"])
|
|
76
|
+
def case_bash_fn_without_doc() -> DocstringCase:
|
|
77
|
+
"""Undocumented shell function."""
|
|
78
|
+
src = """\
|
|
79
|
+
bare() {
|
|
80
|
+
echo hi
|
|
81
|
+
}
|
|
82
|
+
"""
|
|
83
|
+
return "bash", src, "bare", "PHANTOM_DOC_TEXT_SHOULD_NEVER_APPEAR"
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@case(tags=["undocumented", "boundary_not_attached"])
|
|
87
|
+
def case_bash_doc_detached_by_blank_line() -> DocstringCase:
|
|
88
|
+
"""Blank line breaks attachment."""
|
|
89
|
+
src = """\
|
|
90
|
+
# Orphan.
|
|
91
|
+
|
|
92
|
+
later() {
|
|
93
|
+
echo hi
|
|
94
|
+
}
|
|
95
|
+
"""
|
|
96
|
+
return "bash", src, "later", "Orphan"
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
@case(tags=["undocumented", "invalid"])
|
|
100
|
+
def case_bash_shebang_separated_by_blank_line() -> DocstringCase:
|
|
101
|
+
"""When a blank line separates the shebang from the first
|
|
102
|
+
function, the shebang stays detached — the same
|
|
103
|
+
blank-line rule applies uniformly to all comment kinds.
|
|
104
|
+
"""
|
|
105
|
+
src = """\
|
|
106
|
+
#!/bin/bash
|
|
107
|
+
|
|
108
|
+
main() {
|
|
109
|
+
echo hi
|
|
110
|
+
}
|
|
111
|
+
"""
|
|
112
|
+
return "bash", src, "main", "#!/bin/bash"
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""Bash extraction test cases.
|
|
2
|
+
|
|
3
|
+
Each `@case` returns test data consumed by `test_extraction.py` via
|
|
4
|
+
`pytest-cases`.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from pytest_cases import case
|
|
10
|
+
|
|
11
|
+
type SymbolCase = tuple[str, str, list[tuple[str, str, str]]]
|
|
12
|
+
type MixedCase = tuple[str, str, set[str], list[tuple[str, str]]]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@case(tags=["symbol"])
|
|
16
|
+
def case_bash_function_keyword() -> SymbolCase:
|
|
17
|
+
"""function deploy { ... }."""
|
|
18
|
+
src = """\
|
|
19
|
+
function deploy {
|
|
20
|
+
echo deploying
|
|
21
|
+
}
|
|
22
|
+
"""
|
|
23
|
+
return "bash", src, [("function", "deploy", "")]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@case(tags=["symbol"])
|
|
27
|
+
def case_bash_function_keyword_parens() -> SymbolCase:
|
|
28
|
+
"""function deploy() { ... }."""
|
|
29
|
+
src = """\
|
|
30
|
+
function deploy() {
|
|
31
|
+
echo deploying
|
|
32
|
+
}
|
|
33
|
+
"""
|
|
34
|
+
return "bash", src, [("function", "deploy", "")]
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@case(tags=["symbol"])
|
|
38
|
+
def case_bash_function_posix() -> SymbolCase:
|
|
39
|
+
"""deploy() { ... } — POSIX syntax."""
|
|
40
|
+
src = """\
|
|
41
|
+
deploy() {
|
|
42
|
+
echo deploying
|
|
43
|
+
}
|
|
44
|
+
"""
|
|
45
|
+
return "bash", src, [("function", "deploy", "")]
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@case(tags=["symbol"])
|
|
49
|
+
def case_bash_multiple_functions() -> SymbolCase:
|
|
50
|
+
"""Multiple shell functions."""
|
|
51
|
+
src = """\
|
|
52
|
+
function setup {
|
|
53
|
+
echo setup
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function teardown {
|
|
57
|
+
echo teardown
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
run() {
|
|
61
|
+
echo run
|
|
62
|
+
}
|
|
63
|
+
"""
|
|
64
|
+
return (
|
|
65
|
+
"bash",
|
|
66
|
+
src,
|
|
67
|
+
[
|
|
68
|
+
("function", "setup", ""),
|
|
69
|
+
("function", "teardown", ""),
|
|
70
|
+
("function", "run", ""),
|
|
71
|
+
],
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@case(tags=["symbol"])
|
|
76
|
+
def case_bash_alias() -> SymbolCase:
|
|
77
|
+
"""An alias is a variable, named without the `=` the grammar fuses on."""
|
|
78
|
+
src = """\
|
|
79
|
+
alias ll="ls -l"
|
|
80
|
+
"""
|
|
81
|
+
return "bash", src, [("variable", "ll", "")]
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
@case(tags=["symbol"])
|
|
85
|
+
def case_bash_function_local_vars() -> SymbolCase:
|
|
86
|
+
"""Function with local variables."""
|
|
87
|
+
src = """\
|
|
88
|
+
setup() {
|
|
89
|
+
local dir="/tmp"
|
|
90
|
+
mkdir -p "$dir"
|
|
91
|
+
}
|
|
92
|
+
"""
|
|
93
|
+
return "bash", src, [("function", "setup", "")]
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
@case(tags=["symbol"])
|
|
97
|
+
def case_bash_function_conditionals() -> SymbolCase:
|
|
98
|
+
"""Function with conditionals."""
|
|
99
|
+
src = """\
|
|
100
|
+
check() {
|
|
101
|
+
if [ -f /tmp/x ]; then
|
|
102
|
+
echo yes
|
|
103
|
+
fi
|
|
104
|
+
}
|
|
105
|
+
"""
|
|
106
|
+
return "bash", src, [("function", "check", "")]
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
# ── Mixed ───────────────────────────────────────────────────────────
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
@case(tags=["symbol"])
|
|
113
|
+
def case_bash_assignment() -> SymbolCase:
|
|
114
|
+
"""Top-level variable assignment."""
|
|
115
|
+
return "bash", "MAX=100\n", [("variable", "MAX", "")]
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@case(tags=["mixed"])
|
|
119
|
+
def case_bash_full_script() -> MixedCase:
|
|
120
|
+
"""Realistic shell script with doc comments on every
|
|
121
|
+
function. Expected-kinds tuple pins symbol extraction;
|
|
122
|
+
content invariants are in `test_docstrings.py`.
|
|
123
|
+
"""
|
|
124
|
+
src = """\
|
|
125
|
+
#!/bin/bash
|
|
126
|
+
|
|
127
|
+
# Deploy the current build to the given environment.
|
|
128
|
+
deploy() {
|
|
129
|
+
local env="$1"
|
|
130
|
+
echo "deploying to $env"
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
# Roll back the last deploy.
|
|
134
|
+
rollback() {
|
|
135
|
+
echo "rolling back"
|
|
136
|
+
}
|
|
137
|
+
"""
|
|
138
|
+
return "bash", src, {"function"}, []
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Greeter — print greetings for named recipients.
|
|
3
|
+
#
|
|
4
|
+
# Bash has no classes or methods; the plugin extracts functions,
|
|
5
|
+
# top-level variable assignments (including export/declare/readonly),
|
|
6
|
+
# aliases, and source/. imports.
|
|
7
|
+
|
|
8
|
+
source ./lib/colours.sh
|
|
9
|
+
. /etc/greeter.conf
|
|
10
|
+
|
|
11
|
+
DEFAULT_GREETING="Hello" # trailing comment: its own chunk
|
|
12
|
+
|
|
13
|
+
# Standalone note, separated by blank lines from any definition.
|
|
14
|
+
# Second line of the same block.
|
|
15
|
+
LOCALE="${LANG:-en}"
|
|
16
|
+
export API_URL="https://example.com"
|
|
17
|
+
readonly MAX_RETRIES=3
|
|
18
|
+
declare -i COUNTER=0
|
|
19
|
+
alias greet="format_greeting"
|
|
20
|
+
|
|
21
|
+
# Format a greeting for a single recipient.
|
|
22
|
+
format_greeting() {
|
|
23
|
+
local name="$1"
|
|
24
|
+
echo "${DEFAULT_GREETING}, ${name} (${LOCALE})"
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
# Greet every argument in turn.
|
|
28
|
+
greet_all() {
|
|
29
|
+
for name in "$@"; do
|
|
30
|
+
format_greeting "$name"
|
|
31
|
+
done
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
greet_all "$@"
|
|
35
|
+
|
|
36
|
+
mkdir -p "${HOME}/.greeter"
|
|
37
|
+
|
|
38
|
+
if [ -z "${GREETER_QUIET:-}" ]; then
|
|
39
|
+
greet "$DEFAULT_GREETING"
|
|
40
|
+
fi
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Bash docstring-extraction tests.
|
|
2
|
+
|
|
3
|
+
Bash docs are exterior (a leading `#` comment run); there are no
|
|
4
|
+
interior-doc cases, so only the documented / undocumented / exterior-doc
|
|
5
|
+
checks apply.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from pytest_cases import parametrize_with_cases
|
|
11
|
+
|
|
12
|
+
from rbtr.git import FileEntry
|
|
13
|
+
from rbtr.languages.extract import extract_file
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@parametrize_with_cases(
|
|
17
|
+
"lang, source, name, snippet", cases=".cases_docstrings", has_tag="documented"
|
|
18
|
+
)
|
|
19
|
+
def test_documented_chunk_includes_doc_text(
|
|
20
|
+
lang: str, source: str, name: str, snippet: str
|
|
21
|
+
) -> None:
|
|
22
|
+
"""By default the chunk content carries the symbol's docs."""
|
|
23
|
+
chunks = extract_file(FileEntry("input", "sha1", source.encode()), lang)
|
|
24
|
+
chunk = next(c for c in chunks if c.name == name)
|
|
25
|
+
assert snippet in chunk.content, (
|
|
26
|
+
f"expected {snippet!r} in {lang}.{name} content; got:\n{chunk.content!r}"
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@parametrize_with_cases(
|
|
31
|
+
"lang, source, name, snippet", cases=".cases_docstrings", has_tag="undocumented"
|
|
32
|
+
)
|
|
33
|
+
def test_no_phantom_documentation(lang: str, source: str, name: str, snippet: str) -> None:
|
|
34
|
+
"""Symbols without documentation do not gain any in content."""
|
|
35
|
+
chunks = extract_file(FileEntry("input", "sha1", source.encode()), lang)
|
|
36
|
+
chunk = next(c for c in chunks if c.name == name)
|
|
37
|
+
assert snippet not in chunk.content, (
|
|
38
|
+
f"unexpected {snippet!r} in {lang}.{name} content; got:\n{chunk.content!r}"
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@parametrize_with_cases(
|
|
43
|
+
"lang, source, name, snippet", cases=".cases_docstrings", has_tag="exterior_doc"
|
|
44
|
+
)
|
|
45
|
+
def test_leading_doc_folds_into_symbol(lang: str, source: str, name: str, snippet: str) -> None:
|
|
46
|
+
"""A leading comment block folds into its symbol's chunk content."""
|
|
47
|
+
chunk = next(
|
|
48
|
+
c for c in extract_file(FileEntry("input", "sha1", source.encode()), lang) if c.name == name
|
|
49
|
+
)
|
|
50
|
+
assert snippet in chunk.content
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""Bash extraction tests.
|
|
2
|
+
|
|
3
|
+
Construct/mixed cases (`cases_extraction.py`) drive the shared checks;
|
|
4
|
+
the function at the end pins bash's source/. import behaviour.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from pytest_cases import parametrize_with_cases
|
|
10
|
+
|
|
11
|
+
from rbtr.domain.models import ChunkKind
|
|
12
|
+
from rbtr.git import FileEntry
|
|
13
|
+
from rbtr.languages.extract import extract_file
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@parametrize_with_cases("lang, source, expected", cases=".cases_extraction", has_tag="symbol")
|
|
17
|
+
def test_extracts_expected_symbols(lang: str, source: str, expected: list) -> None:
|
|
18
|
+
"""Each expected (kind, name, scope) tuple appears in the output."""
|
|
19
|
+
chunks = extract_file(FileEntry("input", "sha1", source.encode()), lang)
|
|
20
|
+
symbols = [(c.kind, c.name, c.scope) for c in chunks]
|
|
21
|
+
for exp in expected:
|
|
22
|
+
assert exp in symbols, f"expected {exp} not found in {symbols}"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@parametrize_with_cases(
|
|
26
|
+
"lang, source, expected_kinds, expected_methods", cases=".cases_extraction", has_tag="mixed"
|
|
27
|
+
)
|
|
28
|
+
def test_extracts_all_expected_kinds(
|
|
29
|
+
lang: str,
|
|
30
|
+
source: str,
|
|
31
|
+
expected_kinds: set[str],
|
|
32
|
+
expected_methods: list[tuple[str, str]],
|
|
33
|
+
) -> None:
|
|
34
|
+
"""Realistic source produces all expected chunk kinds and method scoping."""
|
|
35
|
+
chunks = extract_file(FileEntry("input", "sha1", source.encode()), lang)
|
|
36
|
+
kinds = {c.kind for c in chunks}
|
|
37
|
+
for kind in expected_kinds:
|
|
38
|
+
assert kind in kinds, f"expected kind {kind!r} not in {kinds}"
|
|
39
|
+
methods = [(c.name, c.scope) for c in chunks if c.kind == ChunkKind.METHOD]
|
|
40
|
+
for name, scope in expected_methods:
|
|
41
|
+
assert (name, scope) in methods, f"expected method ({name}, {scope}) not in {methods}"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_bash_source_and_dot_extracted_as_imports() -> None:
|
|
45
|
+
"""source/. commands are captured as imports."""
|
|
46
|
+
src = """\
|
|
47
|
+
source ./env.sh
|
|
48
|
+
. /etc/profile
|
|
49
|
+
"""
|
|
50
|
+
chunks = extract_file(FileEntry("input", "sha1", src.encode()), "bash")
|
|
51
|
+
imports = [c for c in chunks if c.kind == ChunkKind.IMPORT]
|
|
52
|
+
assert len(imports) == 2
|
|
53
|
+
modules = {c.metadata.module for c in imports}
|
|
54
|
+
assert modules == {"./env.sh", "/etc/profile"}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_bash_top_level_commands_are_searchable() -> None:
|
|
58
|
+
"""A script's commands are what it does, so none is left out.
|
|
59
|
+
|
|
60
|
+
A deploy script may define nothing at all, and before this its every
|
|
61
|
+
command sat in no chunk.
|
|
62
|
+
"""
|
|
63
|
+
src = """\
|
|
64
|
+
set -euo pipefail
|
|
65
|
+
|
|
66
|
+
DEST=/srv/app
|
|
67
|
+
|
|
68
|
+
rsync -a ./build/ "$DEST"
|
|
69
|
+
|
|
70
|
+
if [ -d "$DEST" ]; then
|
|
71
|
+
systemctl restart app
|
|
72
|
+
fi
|
|
73
|
+
"""
|
|
74
|
+
chunks = list(extract_file(FileEntry("deploy.sh", "sha1", src.encode()), "bash"))
|
|
75
|
+
covered = {line for c in chunks for line in range(c.line_start, c.line_end + 1)}
|
|
76
|
+
lines = src.splitlines()
|
|
77
|
+
uncovered = [
|
|
78
|
+
lines[i - 1] for i in range(1, len(lines) + 1) if i not in covered and lines[i - 1].strip()
|
|
79
|
+
]
|
|
80
|
+
assert uncovered == []
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"""Bash sample extraction: the `samples/bash/` project through the real pipeline.
|
|
2
|
+
|
|
3
|
+
The snapshots are the golden record of what bash extraction produces;
|
|
4
|
+
regenerate with `pytest --snapshot-update` after an intended change.
|
|
5
|
+
Engine-wide invariants (determinism, line numbers, syntax-error recovery)
|
|
6
|
+
are covered once in core, not re-run per language.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import TYPE_CHECKING
|
|
13
|
+
|
|
14
|
+
import pytest
|
|
15
|
+
from tree_sitter import Parser
|
|
16
|
+
|
|
17
|
+
from rbtr.domain.models import Chunk, ChunkKind, Edge
|
|
18
|
+
from rbtr.git import FileEntry
|
|
19
|
+
from rbtr.languages.edges import build_resolution_map, infer_import_edges
|
|
20
|
+
from rbtr.languages.extract import extract_file
|
|
21
|
+
from rbtr.languages.manager import get_manager
|
|
22
|
+
from rbtr.testing import render_edges
|
|
23
|
+
|
|
24
|
+
if TYPE_CHECKING:
|
|
25
|
+
from syrupy.assertion import SnapshotAssertion
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@pytest.fixture
|
|
29
|
+
def project() -> list[tuple[str, str]]:
|
|
30
|
+
"""The `(relative path, text)` files of the `samples/bash/` project."""
|
|
31
|
+
root = Path(__file__).parent / "samples" / "bash"
|
|
32
|
+
return [
|
|
33
|
+
(str(p.relative_to(root)), p.read_text()) for p in sorted(root.rglob("*")) if p.is_file()
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@pytest.fixture
|
|
38
|
+
def chunks(project: list[tuple[str, str]]) -> list[Chunk]:
|
|
39
|
+
"""Chunks from every project file, each via the real `extract_file`."""
|
|
40
|
+
manager = get_manager()
|
|
41
|
+
out: list[Chunk] = []
|
|
42
|
+
for path, text in project:
|
|
43
|
+
lang = manager.detect_language(path) or "bash"
|
|
44
|
+
out.extend(extract_file(FileEntry(path, "sha1", text.encode()), lang))
|
|
45
|
+
return out
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@pytest.fixture
|
|
49
|
+
def edges(project: list[tuple[str, str]], chunks: list[Chunk]) -> list[Edge]:
|
|
50
|
+
"""Import edges inferred across the project's files."""
|
|
51
|
+
manager = get_manager()
|
|
52
|
+
return infer_import_edges(chunks, {p for p, _ in project}, build_resolution_map(manager))
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_emits_expected_kinds(chunks: list[Chunk]) -> None:
|
|
56
|
+
"""The sample exercises bash's function, variable, and import chunks."""
|
|
57
|
+
kinds = {c.kind for c in chunks}
|
|
58
|
+
assert {
|
|
59
|
+
ChunkKind.FUNCTION,
|
|
60
|
+
ChunkKind.VARIABLE,
|
|
61
|
+
ChunkKind.IMPORT,
|
|
62
|
+
ChunkKind.COMMENT,
|
|
63
|
+
} <= kinds
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def test_parses_cleanly(project: list[tuple[str, str]]) -> None:
|
|
67
|
+
"""Every project file is valid source — no tree-sitter ERROR/MISSING nodes."""
|
|
68
|
+
manager = get_manager()
|
|
69
|
+
for path, text in project:
|
|
70
|
+
grammar = manager.grammar(manager.detect_language(path) or "bash")
|
|
71
|
+
assert grammar is not None
|
|
72
|
+
assert not Parser(grammar).parse(text.encode()).root_node.has_error, path
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_extraction_matches_snapshot(chunks: list[Chunk], snapshot_json: SnapshotAssertion) -> None:
|
|
76
|
+
assert chunks == snapshot_json
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def test_edges_match_snapshot(
|
|
80
|
+
chunks: list[Chunk], edges: list[Edge], snapshot_json: SnapshotAssertion
|
|
81
|
+
) -> None:
|
|
82
|
+
assert render_edges(edges, chunks) == snapshot_json
|