Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve and Document Test Structure #507

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 141 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/util/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { createStream, type Options } from 'rotating-file-stream'

export class FlowrLogger extends Logger<ILogObj> {
/** by keeping track of all children we can propagate updates of the settings (e.g., in tests) */

private readonly childLoggers: Logger<ILogObj>[] = []

public getSubLogger(
Expand Down
18 changes: 18 additions & 0 deletions test/functionality/_helper/collect-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import fs from 'node:fs'
import path from 'path'

/**
* Require all files in a folder that end with a suffix, will never recurse into subfolders
* @param folder - the folder to require all files from
* @param suffix - the suffix which the files of interest must have
*/
export function requireAllTestsInFolder(folder: string, suffix = '-tests.ts'): void {
for(const fileBuff of fs.readdirSync(folder, { recursive: false })) {
const file = fileBuff.toString()
if(file.endsWith(suffix)) {
require(path.join(folder,file))
} else if(!file.endsWith('.spec.ts')) {
throw new Error(`Unexpected file ${file} in ${folder}, neither matches the import suffix '${suffix}', nor the test suffix '.spec.ts'. This is a sanity check so no files are lost. Please restructure your folders if this is intended.`)
}
}
}
7 changes: 7 additions & 0 deletions test/functionality/_helper/environment-builder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { NodeId } from '../../../src/r-bridge'
import { IdentifierDefinition } from '../../../src/dataflow'
import { LocalScope } from '../../../src/dataflow/environments/scopes'

export function variable(name: string, definedAt: NodeId): IdentifierDefinition {
return { name, kind: 'variable', scope: LocalScope, used: 'always', nodeId: '_0', definedAt }
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function retrieveStatsSafe(slicer: BenchmarkSlicer, request: { request: st
return { stats, statInfo }
}

describe('The Benchmark Slicer', () => {
describe('Benchmark Slicer', () => {
describe('Stats by parsing text-based inputs', function() {
this.timeout('15min')
it('Simple slice for simple line', async() => {
Expand Down
23 changes: 11 additions & 12 deletions test/functionality/dataflow/dataflow.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { requireAllTestsInFolder } from '../_helper/collect-tests'
import path from 'path'

describe('Dataflow', () => {
require('./environments/environments')
describe('Environments', () =>
requireAllTestsInFolder(path.join(__dirname, 'environments'))
)

describe('Graph', () =>
requireAllTestsInFolder(path.join(__dirname, 'graph'))
)

describe('Graph', () => {
require('./graph/equal')
})

describe('Extraction', () => {
require('./elements/atomic')
require('./elements/expression-lists')
describe('Functions', () => {
require('./elements/functions/function-definition')
require('./elements/functions/function-call')
})
})
require('./processing-of-elements/processing-of-elements')
})
9 changes: 0 additions & 9 deletions test/functionality/dataflow/elements/expression-lists.ts

This file was deleted.

3 changes: 0 additions & 3 deletions test/functionality/dataflow/elements/loops/loops.ts

This file was deleted.

14 changes: 0 additions & 14 deletions test/functionality/dataflow/environments/environments.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { DefaultEnvironmentMemory, IEnvironment, initializeCleanEnvironments } f
import { guard } from '../../../../src/util/assert'
import { expect } from 'chai'
import { appendEnvironments, define, overwriteEnvironments } from '../../../../src/dataflow/environments'
import { variable } from './environments'
import { GlobalScope, LocalScope } from '../../../../src/dataflow/environments/scopes'
import { variable } from '../../_helper/environment-builder'

/** if you pass multiple `definedAt`, this will expect the node to have multiple definitions */
function existsDefinedAt(name: string, definedAt: NodeId[], result: IEnvironment | undefined, message?: string) {
Expand All @@ -17,7 +17,7 @@ function existsDefinedAt(name: string, definedAt: NodeId[], result: IEnvironment
expect(got.map(d => d.definedAt), `${name} should be defined at ${JSON.stringify(definedAt)}. ${message ?? ''}`).to.deep.equal(definedAt)
}

describe('Overwrite', () => {
describe('Modification', () => {
describe('Global', () => {
it('Different variables', () => {
let clean = initializeCleanEnvironments()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { define, initializeCleanEnvironments, resolveByName } from '../../../../src/dataflow/environments'
import { variable } from './environments'
import { expect } from 'chai'
import { guard } from '../../../../src/util/assert'
import { GlobalScope, LocalScope } from '../../../../src/dataflow/environments/scopes'
import { variable } from '../../_helper/environment-builder'

describe('Resolve', () => {
describe('ByName', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function test(cmp: (x: boolean) => void, a: DataflowGraph, b: DataflowGraph, tex
}
}

describe('Graph Equality', () => {
describe('Equal', () => {
const raw = (name: string, a: DataflowGraph, b: DataflowGraph, text: string, cmp: (x: boolean) => void) => {
return it(name, () => {
// as the comparison is relatively quick, we allow explicit checks for commutativity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
* Yet, some constructs (like for-loops) require the combination of statements, they are included as well.
* This will not include functions!
*/
import { assertDataflow, withShell } from '../../helper/shell'
import { DataflowGraph, EdgeType, initializeCleanEnvironments } from '../../../../src/dataflow'
import { RAssignmentOpPool, RNonAssignmentBinaryOpPool, RUnaryOpPool } from '../../helper/provider'
import { appendEnvironments, define } from '../../../../src/dataflow/environments'
import { UnnamedArgumentPrefix } from '../../../../src/dataflow/internal/process/functions/argument'
import { GlobalScope, LocalScope } from '../../../../src/dataflow/environments/scopes'
import { MIN_VERSION_PIPE } from '../../../../src/r-bridge/lang-4.x/ast/model/versions'
import { assertDataflow, withShell } from '../../../_helper/shell'
import { DataflowGraph, EdgeType, initializeCleanEnvironments } from '../../../../../src/dataflow'
import { RAssignmentOpPool, RNonAssignmentBinaryOpPool, RUnaryOpPool } from '../../../_helper/provider'
import { appendEnvironments, define } from '../../../../../src/dataflow/environments'
import { UnnamedArgumentPrefix } from '../../../../../src/dataflow/internal/process/functions/argument'
import { GlobalScope, LocalScope } from '../../../../../src/dataflow/environments/scopes'
import { MIN_VERSION_PIPE } from '../../../../../src/r-bridge/lang-4.x/ast/model/versions'

describe('Atomic dataflow information', withShell((shell) => {
describe('Atomic (dataflow information)', withShell((shell) => {
describe('uninteresting leafs', () => {
for(const input of ['42', '"test"', 'TRUE', 'NA', 'NULL']) {
assertDataflow(input, shell, input, new DataflowGraph())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
DataflowGraph, EdgeType,
initializeCleanEnvironments
} from '../../../../../src/dataflow'
import { assertDataflow, withShell } from '../../../helper/shell'
import { assertDataflow, withShell } from '../../../_helper/shell'
import { appendEnvironments, define } from '../../../../../src/dataflow/environments'
import { GlobalScope, LocalScope } from '../../../../../src/dataflow/environments/scopes'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NodeId } from '../../../../../src/r-bridge'
import { DataflowGraph, EdgeType, initializeCleanEnvironments } from '../../../../../src/dataflow'
import { assertDataflow, withShell } from '../../../helper/shell'
import { assertDataflow, withShell } from '../../../_helper/shell'
import { define } from '../../../../../src/dataflow/environments'
import { LocalScope } from '../../../../../src/dataflow/environments/scopes'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertDataflow, withShell } from '../../../helper/shell'
import { assertDataflow, withShell } from '../../../_helper/shell'
import { DataflowGraph } from '../../../../../src/dataflow'

describe('Lists without variable references ', withShell(shell => {
Expand Down
Loading