Skip to content

Commit

Permalink
Merge pull request #152 from snyk/fix/enhance-cycles-detection
Browse files Browse the repository at this point in the history
fix: enhance cycles detection
  • Loading branch information
anthogez authored Oct 25, 2020
2 parents f75b635 + d147c16 commit 7c13518
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
5 changes: 4 additions & 1 deletion lib/find-cycles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export function findCycles(
return true;
}
for (const ancestor of currentAncestors) {
if (!alreadyVisited.has(ancestor) && ancestor !== currentNode) {
if (
!alreadyVisited.has(ancestor) ||
(!alreadyVisited.has(currentNode) && ancestor !== currentNode)
) {
alreadyVisited.add(ancestor);
return findCycles(
ancestorsChain,
Expand Down
2 changes: 1 addition & 1 deletion test/system/kotlin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ if (kotlinSupported) {
const graphObject: any = JSON.parse(
JSON.stringify(result.dependencyGraph),
);
t.ok(graphObject.graph.nodes[0].deps.length === 7, 'top level deps');
t.ok(graphObject.graph.nodes[0].deps.length === 8, 'top level deps');
},
);
}
17 changes: 9 additions & 8 deletions test/system/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import * as javaCallGraphBuilder from '@snyk/java-call-graph-builder';
import { CallGraph } from '@snyk/cli-interface/legacy/common';

const rootNoWrapper = fixtureDir('no wrapper');
const GRADLE_VERSION = process.env.GRADLE_VERSION;

test('run inspect()', async (t) => {
const result = await inspect('.', path.join(rootNoWrapper, 'build.gradle'));
Expand Down Expand Up @@ -94,13 +93,15 @@ test('multi-config: both compile and runtime deps picked up by default', async (
// double parsing to have access to internal depGraph data, no methods available to properly
// return the deps nodeIds list that belongs to a node
const graphObject: any = JSON.parse(JSON.stringify(result.dependencyGraph));
if (GRADLE_VERSION) {
const major = parseInt(GRADLE_VERSION.split('.')[0]);
if (major < 4) {
t.ok(graphObject.graph.nodes[0].deps.length === 11, 'top level deps');
} else {
t.ok(graphObject.graph.nodes[0].deps.length === 9, 'top level deps');
}
const gradleVersionOutput = await subProcess.execute('gradle', ['-v'], {});
const isGradleVersionLessThan4 =
parseInt(gradleVersionOutput.match(/Gradle (\d+)\.\d+(\.\d+)?/)![1], 10) <
4;

if (isGradleVersionLessThan4) {
t.ok(graphObject.graph.nodes[0].deps.length === 16, 'top level deps');
} else {
t.ok(graphObject.graph.nodes[0].deps.length === 14, 'top level deps');
}
t.ok(result.dependencyGraph.getPkgs().length === 42, 'same dependencies');
});
Expand Down

0 comments on commit 7c13518

Please sign in to comment.