test: add VS Code integration test suite for RustMetricsAnalyzer#328
Open
github-actions[bot] wants to merge 2 commits into
Open
test: add VS Code integration test suite for RustMetricsAnalyzer#328github-actions[bot] wants to merge 2 commits into
github-actions[bot] wants to merge 2 commits into
Conversation
Add rustAnalyzer.test.ts to src/test/metricsAnalyzer/languages/ covering: - Basic function analysis (simple fn, if expression, multiple fns, empty/no-fn) - Control flow: for, while, loop, match, nested, else-if - Boolean operators: &&, ||, chained - Impl methods: qualified names, complexity, multiple methods - Closures: top-level (no increment), nested - Position information: startLine accuracy - Static factory method: analyzeFile() All other language analyzers already have an equivalent test file; this completes the set. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a VS Code integration test file for the existing RustMetricsAnalyzer, aligning Rust with the other language analyzers’ integration test coverage under src/test/metricsAnalyzer/languages/.
Changes:
- Added
rustAnalyzer.test.tsintegration tests for Rust function detection, complexity increments, qualifiedimplmethod names, and position reporting. - Included scenarios for control-flow constructs (if/else, loops, match), boolean operators, and closures.
- Added a static factory method test for
RustMetricsAnalyzer.analyzeFile().
Comments suppressed due to low confidence (3)
src/test/metricsAnalyzer/languages/rustAnalyzer.test.ts:57
subtractuses anif … else …expression, and the Rust analyzer counts theelse_clauseas +1 as well. The expected complexity of this function should be 2 (if + else), not 1.
assert.strictEqual(results.length, 2);
assert.strictEqual(results[0].name, "add");
assert.strictEqual(results[0].complexity, 0);
assert.strictEqual(results[1].name, "subtract");
assert.strictEqual(results[1].complexity, 1);
});
src/test/metricsAnalyzer/languages/rustAnalyzer.test.ts:161
- This
if / else if / elsechain should include anelse clauseincrement as well. The Rust analyzer reports reasons["if expression", "else if clause", "else clause"]with total complexity 3 for this pattern, so expecting 2 here will fail.
// if(1) + else if(1) = 2
const results = analyzer.analyzeFunctions(sourceCode);
assert.strictEqual(results[0].complexity, 2);
const reasons = results[0].details.map((d) => d.reason);
assert.ok(reasons.includes("if expression"));
assert.ok(reasons.includes("else if clause"));
});
src/test/metricsAnalyzer/languages/rustAnalyzer.test.ts:288
- This test claims to verify nested-closure counting, but the closure (
|x| x * 2) is after theifblock, so it’s at nesting level 0 and should not add complexity. As written, the assertion can pass even if nested closures are never counted; restructure the sample so the closure is actually inside a nested context (e.g., within theifbody) and assert aclosure (nested)detail/increment.
test("should count nested closure", () => {
const sourceCode = `
fn process(items: &[i32]) -> i32 {
if items.is_empty() {
return 0;
}
items.iter().map(|x| x * 2).sum()
}
`;
// if(1) + closure nested inside if context → complexity >= 1
const results = analyzer.analyzeFunctions(sourceCode);
assert.ok(results[0].complexity >= 1);
});
Agent-Logs-Url: https://github.com/askpt/code-metrics/sessions/9b985942-1e63-4963-9610-b194f5f6fc06 Co-authored-by: askpt <2493377+askpt@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #328 +/- ##
=======================================
Coverage 76.23% 76.23%
=======================================
Files 13 13
Lines 3981 3981
Branches 428 428
=======================================
Hits 3035 3035
Misses 944 944
Partials 2 2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
Adds
src/test/metricsAnalyzer/languages/rustAnalyzer.test.ts— the VS Code integration test suite forRustMetricsAnalyzer.Every other language analyzer already has a corresponding test file in this directory (C#, Go, Java, JavaScript, jsLike, Python, TSX, TypeScript). This PR completes the set by adding the missing Rust counterpart.
Test Coverage
The new test suite covers:
&&,||, chained operatorsStruct::method), complexity, multiple methodsstartLineaccuracyRustMetricsAnalyzer.analyzeFile()Test Status
npm run compile— passed, no TypeScript errorsnpm run lint— passed, no ESLint issuesnpm run test:unit— 100/100 passing (Rust unit tests already inunit.test.ts)npm test) require VS Code download — not runnable in sandboxed CI environment; infrastructure-only limitationWarning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
releaseassets.githubusercontent.comSee Network Configuration for more information.