Skip to content

Commit

Permalink
test: fix failing tests due to colliding file names (#569)
Browse files Browse the repository at this point in the history
### Summary of Changes

Clear files loaded into workspace by tests in additional places to
prevent colliding file names. This does not fully solve the issue yet,
but together with the upcoming update to `Langium` it should get rid of
it completely.

---------

Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com>
  • Loading branch information
lars-reimann and megalinter-bot authored Sep 20, 2023
1 parent 48b5f53 commit f6ffa4d
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 21 deletions.
File renamed without changes.
8 changes: 4 additions & 4 deletions src/language/safe-ds-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import {
PartialLangiumServices,
} from 'langium';
import { SafeDsGeneratedModule, SafeDsGeneratedSharedModule } from './generated/module.js';
import { SafeDsValidator, registerValidationChecks } from './validation/safe-ds-validator.js';
import { registerValidationChecks, SafeDsValidator } from './validation/safe-ds-validator.js';
import { SafeDsFormatter } from './formatting/safe-ds-formatter.js';
import { SafeDsWorkspaceManager } from './builtins/workspaceManager.js';
import {SafeDsScopeComputation} from "./scoping/safe-ds-scope-computation.js";
import {SafeDsScopeProvider} from "./scoping/safe-ds-scope-provider.js";
import { SafeDsWorkspaceManager } from './builtins/safe-ds-workspace-manager.js';
import { SafeDsScopeComputation } from './scoping/safe-ds-scope-computation.js';
import { SafeDsScopeProvider } from './scoping/safe-ds-scope-provider.js';

/**
* Declaration of custom services - add your own service classes here.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { beforeAll, describe, expect, it } from 'vitest';
import { listBuiltinsFiles } from '../../../src/language/builtins/workspaceManager.js';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { listBuiltinsFiles } from '../../../src/language/builtins/safe-ds-workspace-manager.js';
import { createSafeDsServices } from '../../../src/language/safe-ds-module.js';
import { getLinkingErrors } from '../../helpers/diagnostics.js';
import { NodeFileSystem } from 'langium/node';
import { clearDocuments } from 'langium/test';

const services = createSafeDsServices(NodeFileSystem).SafeDs;

Expand All @@ -11,6 +12,10 @@ describe('SafeDsWorkspaceManager', () => {
await services.shared.workspace.WorkspaceManager.initializeWorkspace([]);
});

afterAll(async () => {
await clearDocuments(services);
});

describe('loadAdditionalDocuments', () => {
it.each(['Any', 'Boolean', 'Float', 'Int', 'Nothing', 'Number', 'String'])(
'should be possible to refer to %s',
Expand Down
12 changes: 5 additions & 7 deletions tests/language/formatting/testFormatting.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { createSafeDsServices } from '../../../src/language/safe-ds-module.js';
import { clearDocuments, expectFormatting } from 'langium/test';
import { describe, it } from 'vitest';
import { afterEach, describe, it } from 'vitest';
import { EmptyFileSystem } from 'langium';
import { createFormattingTests } from './creator.js';

const services = createSafeDsServices(EmptyFileSystem).SafeDs;
const formatterTests = createFormattingTests();

describe('formatter', async () => {
afterEach(async () => {
await clearDocuments(services);
});

// Test that the original code is formatted correctly
it.each(await formatterTests)('$testName', async (test) => {
// Test is invalid
Expand All @@ -20,9 +24,6 @@ describe('formatter', async () => {
before: test.originalCode,
after: test.expectedFormattedCode,
});

// Clear loaded documents to avoid colliding URIs (https://github.com/langium/langium/issues/1146)
await clearDocuments(services);
});

// Test that the expected formatted code stays the same when formatted again
Expand All @@ -37,8 +38,5 @@ describe('formatter', async () => {
before: test.expectedFormattedCode,
after: test.expectedFormattedCode,
});

// Clear loaded documents to avoid colliding URIs (https://github.com/langium/langium/issues/1146)
await clearDocuments(services);
});
});
9 changes: 5 additions & 4 deletions tests/language/grammar/testGrammar.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it } from 'vitest';
import { afterEach, describe, it } from 'vitest';
import { createSafeDsServices } from '../../../src/language/safe-ds-module.js';
import { AssertionError } from 'assert';
import { NodeFileSystem } from 'langium/node';
Expand All @@ -9,6 +9,10 @@ import { getSyntaxErrors } from '../../helpers/diagnostics.js';
const services = createSafeDsServices(NodeFileSystem).SafeDs;

describe('grammar', () => {
afterEach(async () => {
await clearDocuments(services);
});

it.each(createGrammarTests())('$testName', async (test) => {
// Test is invalid
if (test.error) {
Expand Down Expand Up @@ -39,8 +43,5 @@ describe('grammar', () => {
});
}
}

// Clear loaded documents to avoid colliding URIs (https://github.com/langium/langium/issues/1146)
await clearDocuments(services);
});
});
8 changes: 6 additions & 2 deletions tests/language/scoping/testScoping.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, it } from 'vitest';
import { afterEach, describe, it } from 'vitest';
import { createSafeDsServices } from '../../../src/language/safe-ds-module.js';
import { URI } from 'vscode-uri';
import { NodeFileSystem } from 'langium/node';
import { isRangeEqual } from 'langium/test';
import { isRangeEqual, clearDocuments } from 'langium/test';
import { AssertionError } from 'assert';
import { isLocationEqual, locationToString } from '../../helpers/location.js';
import { createScopingTests, ExpectedReference } from './creator.js';
Expand All @@ -12,6 +12,10 @@ import { Location } from 'vscode-languageserver';
const services = createSafeDsServices(NodeFileSystem).SafeDs;

describe('scoping', async () => {
afterEach(async () => {
await clearDocuments(services);
});

it.each(await createScopingTests())('$testName', async (test) => {
// Test is invalid
if (test.error) {
Expand Down
8 changes: 6 additions & 2 deletions tests/language/validation/testValidation.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { describe, it } from 'vitest';
import { afterEach, describe, it } from 'vitest';
import { createSafeDsServices } from '../../../src/language/safe-ds-module.js';
import { URI } from 'vscode-uri';
import { NodeFileSystem } from 'langium/node';
import { createValidationTests, ExpectedIssue } from './creator.js';
import { Diagnostic, DiagnosticSeverity } from 'vscode-languageserver-types';
import { AssertionError } from 'assert';
import { isRangeEqual } from 'langium/test';
import { clearDocuments, isRangeEqual } from 'langium/test';
import { locationToString } from '../../helpers/location.js';

const services = createSafeDsServices(NodeFileSystem).SafeDs;

describe('validation', async () => {
afterEach(async () => {
await clearDocuments(services);
});

it.each(await createValidationTests())('$testName', async (test) => {
// Test is invalid
if (test.error) {
Expand Down

0 comments on commit f6ffa4d

Please sign in to comment.