Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

feat(cobol): resolve EXEC SQL INCLUDE to DB2 DCLGEN members (#4460)

Raghav Chamadiyaf88121428072
diff --git a/docs/architecture/language-support.md b/docs/architecture/language-support.md
index 529c8b050..812387e84 100644
--- a/docs/architecture/language-support.md
+++ b/docs/architecture/language-support.md
@@ -729,7 +729,7 @@ dependency surface their syntax supports.
| Good | **PHP** | `.php` | `use` declarations through PSR-4 from every `composer.json`, same-namespace and fully qualified class references |
| Good | **Dart** | `.dart` | `import` / `export` / `part`, `package:` via every `pubspec.yaml` |
| Good | **Object Pascal** | `.pas` `.pp` `.dpr` `.dpk` `.lpr` | `uses` clauses via unit-name to file-stem match; project files as entry points |
-| Good | **COBOL** | `.cbl` `.cob` `.cobol` `.cpy` | `COPY` members to copybooks; literal `CALL`, `PERFORM` and CICS `LINK`/`XCTL` targets, with constants followed; dynamic targets shown as such |
+| Good | **COBOL** | `.cbl` `.cob` `.cobol` `.cpy` `.dcl` (DCLGEN, by content) | `COPY` members to copybooks; literal `CALL`, `PERFORM` and CICS `LINK`/`XCTL` targets, with constants followed; dynamic targets shown as such |
| Good | **GDScript** | `.gd` | `preload` / `load` / `extends "res://..."` from the nearest `project.godot` |
| Good | **VB.NET** | `.vb` | `Imports` through the same MSBuild project index C# uses |
| Good | **Elixir** | `.ex` `.exs` | `alias` / `import` / `require` / `use` against a `defmodule` index, Mix path convention as fallback |
diff --git a/docs/layers/LANGUAGE_SUPPORT.md b/docs/layers/LANGUAGE_SUPPORT.md
index 6bbe8b2a3..e528867fe 100644
--- a/docs/layers/LANGUAGE_SUPPORT.md
+++ b/docs/layers/LANGUAGE_SUPPORT.md
@@ -82,6 +82,9 @@ COBOL is read in fixed reference format, with `EXEC SQL/CICS/DLI` blocks and
`COPY` statements masked before parsing; a copybook parses as a data or
procedure fragment. `COPY` and `EXEC SQL INCLUDE` members resolve to the
nearest copybook with that name; system copybooks such as `DFHAID` stay external.
+A DB2 DCLGEN member (`.dcl`) is a copybook when it holds an
+`EXEC SQL DECLARE ... TABLE` and level-numbered data entries. PL/I DCLGEN
+output and OpenVMS DCL procedures share the extension and are not indexed.
`EXEC CICS LINK` and `XCTL` link to their program when it is a literal or a
constant moved into the program variable; any other target shows as a
`cics-dynamic:` reference rather than a guess. A `PERFORM` binds only within
diff --git a/packages/core/src/repowise/core/ingestion/change_detector.py b/packages/core/src/repowise/core/ingestion/change_detector.py
index 0b10497ab..e016e6e0a 100644
--- a/packages/core/src/repowise/core/ingestion/change_detector.py
+++ b/packages/core/src/repowise/core/ingestion/change_detector.py
@@ -538,7 +538,7 @@ class ChangeDetector:
from .parser import parse_file
from .traverser import _detect_language
- lang = _detect_language(Path(path))
+ lang = _detect_language(Path(path), source)
file_info = FileInfo(
path=path,
abs_path=str(self.repo_path / path),
diff --git a/packages/core/src/repowise/core/ingestion/cobol/fragments.py b/packages/core/src/repowise/core/ingestion/cobol/fragments.py
index dd359db78..8c9ea53e7 100644
--- a/packages/core/src/repowise/core/ingestion/cobol/fragments.py
+++ b/packages/core/src/repowise/core/ingestion/cobol/fragments.py
@@ -10,6 +10,8 @@ from __future__ import annotations
import re
+from .statements import exec_blocks
+
FRAGMENT_PROGRAM = "REPOWISE-COPYBOOK"
_PROGRAM_HEADER = re.compile(r"\b(IDENTIFICATION|ID)\s+DIVISION\b|\bPROGRAM-ID\b", re.I)
@@ -25,9 +27,15 @@ def is_fragment(code: str) -> bool:
def is_procedure_fragment(code: str) -> bool:
- """Whether the first code line is procedure text rather than a data entry."""
+ """Whether the first code line is procedure text rather than a data entry.
+
+ EXEC blocks are skipped: a DCLGEN member opens with ``EXEC SQL DECLARE``
+ ahead of its record.
+ """
+ for block in reversed(exec_blocks(code)):
+ code = code[: block.start] + code[block.end :]
# A code view has no sequence area to skip; a ``>>`` directive is not code.
- lines = (line.strip() for line in code.split("\n"))
+ lines = (line.strip().strip(".").strip() for line in code.split("\n"))
first = next((line for line in lines if line and not line.startswith(">>")), "")
return _LEVEL_NUMBER.match(first) is None
diff --git a/packages/core/src/repowise/core/ingestion/cobol/source.py b/packages/core/src/repowise/core/ingestion/cobol/source.py
index 609106fa4..639268eed 100644
--- a/packages/core/src/repowise/core/ingestion/cobol/source.py
+++ b/packages/core/src/repowise/core/ingestion/cobol/source.py
@@ -23,6 +23,18 @@ def code_view(source: bytes) -> str:
return _INLINE_COMMENT.sub(lambda m: m.group(1) or " " * len(m.group(0)), code)
+# DCLGEN output for COBOL: the table declaration, then a level-numbered record.
+# A PL/I member declares ``DCL 1 NAME,`` and a VMS DCL procedure has neither.
+_SQL_DECLARE_TABLE = re.compile(r"\bEXEC\s+SQL\s+DECLARE\s+[\w.$#@-]+\s+TABLE\b", re.I)
+_DATA_ENTRY = re.compile(r"^[ \t]*\d{1,2}[ \t]+[A-Z0-9][A-Z0-9-]*[ \t]*\.", re.I | re.M)
+
+
+def is_cobol_dclgen(source: bytes) -> bool:
+ """Whether a ``.dcl`` member is a DCLGEN copybook written for COBOL."""
+ code = code_view(source)
+ return _SQL_DECLARE_TABLE.search(code) is not None and _DATA_ENTRY.search(code) is not None
+
+
def prepare_cobol_source(source: bytes) -> bytes:
"""The parse input: a code view with EXEC/COPY masked, copybooks wrapped."""
code = code_view(source)
diff --git a/packages/core/src/repowise/core/ingestion/cobol/statements.py b/packages/core/src/repowise/core/ingestion/cobol/statements.py
index 6bdc5e8bd..2b04c281d 100644
--- a/packages/core/src/repowise/core/ingestion/cobol/statements.py
+++ b/packages/core/src/repowise/core/ingestion/cobol/statements.py
@@ -28,6 +28,7 @@ _COPY = re.compile(
re.IGNORECASE | re.DOTALL,
)
_PROCEDURE_DIVISION = re.compile(r"\bPROCEDURE\s+DIVISION\b", re.IGNORECASE)
+_CLOSING_PERIOD = re.compile(r"[ \t]*\.")
_FILLER = "CONTINUE"
_DATA_PLACEHOLDER = "01 FILLER PIC X."
@@ -111,7 +112,14 @@ def mask_statements(code: str, procedure_from: int | None = None) -> str:
procedure_from = division.end() if division else len(code)
chars = list(code)
for block in exec_blocks(code):
- _blank(chars, block.start, block.end)
+ end = block.end
+ period = _CLOSING_PERIOD.match(code, end)
+ if period and block.start < procedure_from and _follows_period(chars, block.start):
+ # Between entries the period ends nothing, and one straight after a
+ # section header (a DCLGEN member) does not parse. Inside an open
+ # entry it is that entry's terminator and stays.
+ end = period.end()
+ _blank(chars, block.start, end)
if block.start >= procedure_from and not _SQL_INCLUDE.match(block.body):
chars[block.start : block.start + len(_FILLER)] = _FILLER
masked = "".join(chars)
@@ -124,6 +132,14 @@ def mask_statements(code: str, procedure_from: int | None = None) -> str:
return masked
+def _follows_period(chars: list[str], start: int) -> bool:
+ """Whether the code before *start* is empty or ends with a period."""
+ i = start - 1
+ while i >= 0 and chars[i].isspace():
+ i -= 1
+ return i < 0 or chars[i] == "."
+
+
def _blank(chars: list[str], start: int, end: int) -> None:
for i in range(start, end):
if chars[i] not in "\r\n":
diff --git a/packages/core/src/repowise/core/ingestion/resolvers/cobol.py b/packages/core/src/repowise/core/ingestion/resolvers/cobol.py
index e85dfb3cd..1f28d5a9a 100644
--- a/packages/core/src/repowise/core/ingestion/resolvers/cobol.py
+++ b/packages/core/src/repowise/core/ingestion/resolvers/cobol.py
@@ -18,7 +18,8 @@ from ..languages.registry import REGISTRY
if TYPE_CHECKING:
from .context import ResolverContext
-_COPYBOOK_SUFFIXES = frozenset({".cpy"})
+# A ``.dcl`` is indexed only when its content reads as a COBOL DCLGEN member.
+_COPYBOOK_SUFFIXES = frozenset({".cpy", ".dcl"})
def resolve_cobol_import(module_path: str, importer_path: str, ctx: ResolverContext) -> str | None:
@@ -27,7 +28,7 @@ def resolve_cobol_import(module_path: str, importer_path: str, ctx: ResolverCont
return ctx.add_external_node(f"cics-{module_path}")
library, _, member = module_path.rpartition("/")
spec = REGISTRY.get("cobol")
- extensions = spec.extensions if spec else _COPYBOOK_SUFFIXES
+ extensions = (spec.extensions if spec else frozenset()) | _COPYBOOK_SUFFIXES
candidates = [
path
for path in ctx.stem_map.get(member.lower(), ())
diff --git a/packages/core/src/repowise/core/ingestion/traverser.py b/packages/core/src/repowise/core/ingestion/traverser.py
index c63083b56..cb12a28cb 100644
--- a/packages/core/src/repowise/core/ingestion/traverser.py
+++ b/packages/core/src/repowise/core/ingestion/traverser.py
@@ -51,6 +51,7 @@ from ..pytest_roots import (
pytest_roots,
)
from ..test_paths import is_test_related_path
+from .cobol.source import is_cobol_dclgen
from .languages.registry import REGISTRY as _LANG_REGISTRY
from .languages.specs.aura import is_aura_markup_path
from .languages.specs.cpp import INCLUDE_FRAGMENT_EXTENSIONS
@@ -826,10 +827,7 @@ class FileTraverser:
"""The file's language, or None (counted) when it is binary or unparseable."""
# Name/extension lookup does no I/O; only an unrecognised extension
# pays for binary and shebang sniffing.
- language = _language_from_name_or_ext(abs_path)
- # A .h may be Objective-C by content.
- if language == "cpp":
- return _objc_header_language(abs_path) or language
+ language = _content_language(abs_path, _language_from_name_or_ext(abs_path))
if language is not None:
return language
if _is_binary(abs_path):
@@ -1083,7 +1081,18 @@ _C_COMMENT_RE = re.compile(rb"//[^\n]*|/\*.*?(?:\*/|\Z)", re.DOTALL)
_OBJC_HEADER_SNIFF_BYTES = 16384
-def _objc_header_language(abs_path: Path) -> LanguageTag | None:
+def _head(abs_path: Path, source: bytes | None, size: int) -> bytes | None:
+ """The first *size* bytes of *source* when given, else of the file; ``None`` if unreadable."""
+ if source is not None:
+ return source[:size]
+ try:
+ with open(abs_path, "rb") as f:
+ return f.read(size)
+ except OSError:
+ return None
+
+
+def _objc_header_language(abs_path: Path, source: bytes | None = None) -> LanguageTag | None:
"""``objectivec`` for a ``.h`` that reads as Objective-C, else ``None``.
One extension maps to one language for the whole repository, and ``.h``
@@ -1097,24 +1106,48 @@ def _objc_header_language(abs_path: Path) -> LanguageTag | None:
"""
if abs_path.suffix.lower() != ".h":
return None
- try:
- with open(abs_path, "rb") as f:
- head = f.read(_OBJC_HEADER_SNIFF_BYTES)
- except OSError:
+ head = _head(abs_path, source, _OBJC_HEADER_SNIFF_BYTES)
+ if head is None:
return None
# Blank the comments in place so line starts are preserved.
head = _C_COMMENT_RE.sub(lambda m: b" " * len(m.group(0)), head)
return "objectivec" if _OBJC_HEADER_DECLARATION_RE.search(head) else None
-def _detect_language(abs_path: Path) -> LanguageTag:
+# DCLGEN writes the table declaration, then the ``01`` record, at the top of a
+# member; a 750-column table (the DB2 maximum) declares in about 62 KB.
+_DCLGEN_SNIFF_BYTES = 131072
+
+
+def _dclgen_language(abs_path: Path, source: bytes | None = None) -> LanguageTag | None:
+ """``cobol`` for a ``.dcl`` DCLGEN member written for COBOL, else ``None``.
+
+ ``.dcl`` is also PL/I DCLGEN output and OpenVMS DCL, so the extension
+ alone claims nothing.
+ """
+ if abs_path.suffix.lower() != ".dcl":
+ return None
+ head = _head(abs_path, source, _DCLGEN_SNIFF_BYTES)
+ return "cobol" if head is not None and is_cobol_dclgen(head) else None
+
+
+def _content_language(
+ abs_path: Path, language: LanguageTag | None, source: bytes | None = None
+) -> LanguageTag | None:
+ """*language* from the name, or what content says for a shared extension.
+
+ *source* is the file's bytes when the caller already holds them (a blob),
+ so the working tree is not read in their place.
+ """
+ if language == "cpp":
+ return _objc_header_language(abs_path, source) or language
+ return language or _dclgen_language(abs_path, source)
+
+
+def _detect_language(abs_path: Path, source: bytes | None = None) -> LanguageTag:
"""Detect the language of a file from name, extension, content, or shebang."""
- lang = _language_from_name_or_ext(abs_path)
- if lang is not None:
- if lang == "cpp":
- return _objc_header_language(abs_path) or lang
- return lang
- return _detect_by_shebang(abs_path)
+ lang = _content_language(abs_path, _language_from_name_or_ext(abs_path), source)
+ return lang if lang is not None else _detect_by_shebang(abs_path)
def _detect_by_shebang(abs_path: Path) -> LanguageTag:
diff --git a/scripts/cobol_acceptance.py b/scripts/cobol_acceptance.py
index 516b03d46..67dd4cf79 100644
--- a/scripts/cobol_acceptance.py
+++ b/scripts/cobol_acceptance.py
@@ -20,7 +20,8 @@ import sqlite3
import sys
_PROGRAM_EXTS = {".cbl", ".cob", ".cobol"}
-_COPYBOOK_EXTS = {".cpy"}
+# A ``.dcl`` is taken as a COBOL DCLGEN member, which every CardDemo one is.
+_COPYBOOK_EXTS = {".cpy", ".dcl"}
_JCL_EXTS = {".jcl", ".prc", ".proc"}
_BMS_EXTS = {".bms"}
_NOT_A_PARAGRAPH = {"UNTIL", "VARYING", "WITH", "TEST", "FOREVER", "THRU", "THROUGH"}
@@ -99,6 +100,7 @@ def truth(root: str) -> dict:
pairs["copied"].add((rel, cpy))
for m in re.finditer(r"EXEC\s+SQL\s+INCLUDE\s+([A-Z0-9#@$-]+)", text, re.I):
for cpy in cpys.get(m.group(1).upper(), []):
+ pairs["include"].add((rel, cpy))
pairs["copied"].add((rel, cpy))
for m in re.finditer(r"\bCALL\s+'([A-Z0-9#@$-]+)'", text, re.I):
for dst in progs.get(m.group(1).upper(), []):
@@ -218,10 +220,10 @@ def metrics(root: str, db: str) -> dict:
touched = {f for pair in any_pairs for f in pair}
pair_hits = {
kind: ratio(
- len(t["pairs"][kind] & (imports if kind == "copy" else any_pairs)),
+ len(t["pairs"][kind] & (imports if kind in ("copy", "include") else any_pairs)),
len(t["pairs"][kind]),
)
- for kind in ("copy", "call", "cics", "jcl", "bms")
+ for kind in ("copy", "include", "call", "cics", "jcl", "bms")
}
return {
"cobol_symbols": ix["cobol_symbols"],
diff --git a/tests/unit/ingestion/parser/test_cobol_source.py b/tests/unit/ingestion/parser/test_cobol_source.py
index 61d38ddbc..1b10d947e 100644
--- a/tests/unit/ingestion/parser/test_cobol_source.py
+++ b/tests/unit/ingestion/parser/test_cobol_source.py
@@ -138,6 +138,74 @@ def test_a_procedure_copybook_yields_its_paragraphs() -> None:
assert _names(parsed) == {"YYYY-STORE-PFKEY": 3, "YYYY-STORE-PFKEY-EXIT": 5}
+def test_a_dclgen_member_yields_its_record_after_the_table_declaration() -> None:
+ source = (
+ b" * DCLGEN TABLE(CARDDEMO.TRANSACTION_TYPE)\n"
+ b" *\n"
+ b" EXEC SQL DECLARE CARDDEMO.TRANSACTION_TYPE TABLE\n"
+ b" ( TR_TYPE CHAR(2) NOT NULL\n"
+ b" ) END-EXEC.\n"
+ b" 01 DCLTRTYP.\n"
+ b" 10 TR-TYPE PIC X(2).\n"
+ )
+
+ parsed = _parse(source, "DCLTRTYP.dcl")
+
+ assert parsed.parse_errors == []
+ assert _names(parsed) == {"DCLTRTYP": 6, "TR-TYPE": 7}
+
+
+def _working_storage(*entries: bytes) -> bytes:
+ return (
+ b" IDENTIFICATION DIVISION.\n"
+ b" PROGRAM-ID. DEMO.\n"
+ b" DATA DIVISION.\n"
+ b" WORKING-STORAGE SECTION.\n"
+ + b"".join(entries)
+ + b" PROCEDURE DIVISION.\n"
+ b" STOP RUN.\n"
+ )
+
+
+def test_an_exec_block_inside_an_open_entry_keeps_its_terminating_period() -> None:
+ # The period after END-EXEC ends ``01 A``; blanking it would read B into A.
+ source = _working_storage(
+ b" 01 A PIC X\n",
+ b" EXEC SQL INCLUDE SQLCA END-EXEC.\n",
+ b" 01 B PIC X.\n",
+ )
+
+ parsed = _parse(source)
+
+ assert parsed.parse_errors == []
+ assert _names(parsed) == {"DEMO": 1, "A": 5, "B": 7}
+
+
+def test_an_exec_block_between_entries_parses() -> None:
+ source = _working_storage(
+ b" 01 A PIC X.\n",
+ b" EXEC SQL INCLUDE SQLCA END-EXEC.\n",
+ b" 01 B PIC X.\n",
+ )
+
+ parsed = _parse(source)
+
+ assert parsed.parse_errors == []
+ assert _names(parsed) == {"DEMO": 1, "A": 5, "B": 7}
+
+
+def test_a_data_copybook_opening_with_a_sql_include_is_data() -> None:
+ source = b" EXEC SQL INCLUDE SQLCA END-EXEC.\n 01 A PIC X.\n"
+
+ assert not is_procedure_fragment(code_view(source))
+
+
+def test_a_procedure_copybook_opening_with_exec_cics_stays_procedure() -> None:
+ source = b" EXEC CICS RETURN END-EXEC.\n PARA-A.\n EXIT.\n"
+
+ assert is_procedure_fragment(code_view(source))
+
+
def test_a_free_format_data_copybook_is_not_read_as_procedure_text() -> None:
source = b"\n\n>>SOURCE FORMAT FREE\n01 ACCOUNT-RECORD.\n 05 ACCT-ID PIC 9(11).\n"
diff --git a/tests/unit/ingestion/test_change_detector.py b/tests/unit/ingestion/test_change_detector.py
index 55b896c69..b747c81d5 100644
--- a/tests/unit/ingestion/test_change_detector.py
+++ b/tests/unit/ingestion/test_change_detector.py
@@ -447,3 +447,42 @@ class TestAffectedPagesStalenessPriority:
pagerank=pr,
)
assert result.regenerate[0] == "a.py"
+
+
+# ---------------------------------------------------------------------------
+# parse_bytes — language from the blob in hand
+# ---------------------------------------------------------------------------
+
+
+class TestParseBytesLanguage:
+ def test_a_dclgen_blob_is_cobol_from_any_working_directory(
+ self, tmp_path: Path, monkeypatch
+ ) -> None:
+ # The blob exists nowhere on disk and the cwd is not the repo, so only
+ # the bytes passed in can decide the language.
+ repo, elsewhere = tmp_path / "repo", tmp_path / "elsewhere"
+ repo.mkdir()
+ elsewhere.mkdir()
+ monkeypatch.chdir(elsewhere)
+ blob = (
+ b" EXEC SQL DECLARE CARDDEMO.TRANSACTION_TYPE TABLE\n"
+ b" ( TR_TYPE CHAR(2) NOT NULL ) END-EXEC.\n"
+ b" 01 DCLTRTYP.\n"
+ b" 10 TR-TYPE PIC X(2).\n"
+ )
+
+ parsed = ChangeDetector(repo).parse_bytes(blob, "app/dcl/DCLTRTYP.dcl")
+
+ assert parsed is not None
+ assert parsed.file_info.language == "cobol"
+
+ def test_an_objectivec_header_blob_is_routed_by_its_bytes(
+ self, tmp_path: Path, monkeypatch
+ ) -> None:
+ monkeypatch.chdir(tmp_path)
+ blob = b"#import <Foundation/Foundation.h>\n@interface Widget\n@end\n"
+
+ parsed = ChangeDetector(tmp_path / "repo").parse_bytes(blob, "Widget.h")
+
+ assert parsed is not None
+ assert parsed.file_info.language == "objectivec"
diff --git a/tests/unit/ingestion/test_cobol_resolver.py b/tests/unit/ingestion/test_cobol_resolver.py
index 74a97e070..e04b7348f 100644
--- a/tests/unit/ingestion/test_cobol_resolver.py
+++ b/tests/unit/ingestion/test_cobol_resolver.py
@@ -67,3 +67,9 @@ def test_copy_and_sql_include_become_one_import_per_member() -> None:
("OTHERLIB/MEMBER1", "COPY MEMBER1 OF OTHERLIB", ["*"]),
("DCLTRTYP", "EXEC SQL INCLUDE DCLTRTYP", ["*"]),
]
+
+
+def test_a_sql_include_resolves_to_a_dclgen_member() -> None:
+ ctx = _ctx("app/cbl/COTRTUPC.cbl", "app/dcl/DCLTRTYP.dcl")
+
+ assert resolve_cobol_import("DCLTRTYP", "app/cbl/COTRTUPC.cbl", ctx) == "app/dcl/DCLTRTYP.dcl"
diff --git a/tests/unit/ingestion/test_traverser.py b/tests/unit/ingestion/test_traverser.py
index b178f9ab0..d93e0c47b 100644
--- a/tests/unit/ingestion/test_traverser.py
+++ b/tests/unit/ingestion/test_traverser.py
@@ -19,6 +19,15 @@ from repowise.core.ingestion.traverser import (
in_blocked_dir,
)
+# A DCLGEN member for COBOL, with fixed-format sequence numbers in columns 1-6.
+_COBOL_DCLGEN = (
+ " * DCLGEN TABLE(CARDDEMO.TRANSACTION_TYPE)\n"
+ "000100 EXEC SQL DECLARE CARDDEMO.TRANSACTION_TYPE TABLE\n"
+ "000200 ( TR_TYPE CHAR(2) NOT NULL ) END-EXEC.\n"
+ "000300 01 DCLTRTYP.\n"
+ "000400 10 TR-TYPE PIC X(2).\n"
+)
+
class TestCompileGitignore:
def test_malformed_line_is_not_fatal_and_keeps_valid(self) -> None:
@@ -128,6 +137,36 @@ class TestLanguageDetection:
def test_a_dot_m_needs_no_sniff(self, tmp_path: Path) -> None:
assert _detect_language(tmp_path / "Widget.m") == "objectivec"
+ def test_a_cobol_dclgen_member_is_cobol(self, tmp_path: Path) -> None:
+ f = tmp_path / "DCLTRTYP.dcl"
+ f.write_text(_COBOL_DCLGEN)
+ assert _detect_language(f) == "cobol"
+
+ def test_a_pli_dclgen_member_is_not_cobol(self, tmp_path: Path) -> None:
+ f = tmp_path / "DCLEMP.dcl"
+ f.write_text(
+ " EXEC SQL DECLARE DSN8C10.EMP TABLE\n"
+ " ( EMPNO CHAR(6) NOT NULL ) ;\n"
+ " DCL 1 DCLEMP,\n"
+ " 5 EMPNO CHAR(6);\n"
+ )
+ assert _detect_language(f) == "unknown"
+
+ def test_an_uppercase_dcl_extension_is_sniffed_too(self, tmp_path: Path) -> None:
+ f = tmp_path / "DCLTRTYP.DCL"
+ f.write_text(_COBOL_DCLGEN)
+ assert _detect_language(f) == "cobol"
+
+ def test_a_table_declaration_without_a_record_is_not_cobol(self, tmp_path: Path) -> None:
+ f = tmp_path / "TABLE.dcl"
+ f.write_text(" EXEC SQL DECLARE CARDDEMO.T TABLE ( A CHAR(1) ) END-EXEC.\n")
+ assert _detect_language(f) == "unknown"
+
+ def test_a_vms_dcl_procedure_is_not_cobol(self, tmp_path: Path) -> None:
+ f = tmp_path / "build.dcl"
+ f.write_text("$ SET VERIFY\n$ CC/DEBUG MAIN.C\n$ LINK MAIN\n$ EXIT\n")
+ assert _detect_language(f) == "unknown"
+
def test_special_dockerfile(self, tmp_path: Path) -> None:
assert _detect_language(tmp_path / "Dockerfile") == "dockerfile"
@@ -179,6 +218,14 @@ class TestFileTraverser:
paths = [f.path for f in traverser.traverse()]
assert not any("__pycache__" in p for p in paths)
+ def test_only_a_cobol_dclgen_member_is_indexed(self, tmp_path: Path) -> None:
+ (tmp_path / "DCLTRTYP.dcl").write_text(_COBOL_DCLGEN)
+ (tmp_path / "build.dcl").write_text("$ SET VERIFY\n$ EXIT\n")
+ traverser = FileTraverser(tmp_path)
+ found = {f.path: f.language for f in traverser.traverse()}
+ assert found == {"DCLTRTYP.dcl": "cobol"}
+ assert traverser.stats.skipped_unknown_language == 1
+
def test_skips_unity_generated_dirs(self, tmp_path: Path) -> None:
(tmp_path / "ProjectSettings").mkdir()
(tmp_path / "ProjectSettings" / "ProjectVersion.txt").write_text(