8000 test: Allow different package names and versions for subfolders (#106) · codemuse-app/scip-python@db414af · GitHub
[go: up one dir, main page]

Skip to content

Commit db414af

Browse files
test: Allow different package names and versions for subfolders (sourcegraph#106)
We add a separate JSON file which tracks the project names and versions. This makes it easy to add tests with unusual project names and versions, to make sure we're handling those correctly end-to-end.
1 parent 281524f commit db414af

File tree

4 files changed

+65
-16
lines changed

4 files changed

+65
-16
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def main():
2+
pass
3+
4+
main()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# < definition scip-python python package with space 0.1 main/__init__:
2+
#documentation (module) main
3+
4+
def main():
5+
# ^^^^ definition package with space 0.1 main/main().
6+
# documentation ```python
7+
# > def main(): # -> None:
8+
# > ```
9+
pass
10+
11+
main()
12+
#^^^ reference package with space 0.1 main/main().
13+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"default": {
3+
"name": "snapshot-util",
4+
"version": "0.1"
5+
},
6+
"special": {
7+
"odd_pkg_name_1": {
8+
"name": "package with space",
9+
"version": "0.1"
10+
}
11+
}
12+
}

packages/pyright-scip/test/test-main.ts

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,45 @@
11
import { main } from '../src/main-impl';
22
import * as path from 'path';
3+
import * as fs from 'fs';
34

45
function testMain(mode: 'check' | 'update'): void {
56
const nodePath = process.argv[0];
6-
const argv = [
7-
nodePath,
8-
path.resolve('./index.js'),
9-
'snapshot-dir',
10-
'./snapshots',
11-
'--environment',
12-
'snapshots/testEnv.json',
13-
'--quiet',
14-
'--project-name',
15-
'snapshot-util',
16-
'--project-version',
17-
'0.1',
18-
];
19-
if (mode === 'check') {
20-
argv.push('--check');
7+
const startCwd = process.cwd();
8+
// Returns list of subdir names, not absolute paths.
9+
const inputDir = path.join('.', 'snapshots', 'input');
10+
const subdirNames = fs.readdirSync(inputDir);
11+
const packageInfoPath = path.join('.', 'snapshots', 'packageInfo.json');
12+
const packageInfo = JSON.parse(fs.readFileSync(packageInfoPath, 'utf8'));
13+
for (const subdirName of subdirNames) {
14+
console.assert(!subdirName.includes(path.sep));
15+
let projectName = packageInfo['default']['name'];
16+
let projectVersion = packageInfo['default']['version'];
17+
if (subdirName in packageInfo['special']) {
18+
projectName = packageInfo['special'][subdirName]['name'];
19+
projectVersion = packageInfo['special'][subdirName]['version'];
20+
}
21+
const argv = [
22+
nodePath,
23+
path.resolve('./index.js'),
24+
'snapshot-dir',
25+
'./snapshots',
26+
'--environment',
27+
'snapshots/testEnv.json',
28+
'--quiet',
29+
'--project-name',
30+
projectName,
31+
'--project-version',
32+
projectVersion,
33+
'--only',
34+
subdirName,
35+
];
36+
if (mode === 'check') {
37+
argv.push('--check');
38+
}
39+
main(argv);
40+
// main changes the working directory; reset it.
41+
process.chdir(startCwd);
2142
}
22-
main(argv);
2343
}
2444

2545
if (process.argv.indexOf('--check') !== -1) {

0 commit comments

Comments
 (0)
0