@@ -8,21 +8,22 @@ const path = require('path')
8
8
9
9
require ( 'npmlog' ) . level = 'warn'
10
10
11
- //* can use name as short descriptions
11
+ //* name can be used as short descriptions
12
12
13
13
/**
14
14
* @typedef Check
15
- * @property {string } path - path to execurtable or command
15
+ * @property {string } path - path to executable or command
16
16
* @property {string } name - very little description
17
17
*/
18
18
19
+ // TODO: add symlinks to python which will contain utf-8 chars
19
20
/**
20
21
* @type {Check[] }
21
22
*/
22
23
const checks = [
23
24
{ path : process . env . PYTHON , name : 'env var PYTHON' } ,
24
- { path : process . env . python2 , name : 'env var python2 ' } ,
25
- { path : 'python3 ' , name : 'env var python3 ' }
25
+ { path : 'python3' , name : 'python3 in PATH ' } ,
26
+ { path : 'python ' , name : 'python in PATH ' }
26
27
]
27
28
const args = [ path . resolve ( './lib/find-python-script.py' ) ]
28
29
const options = {
@@ -32,37 +33,37 @@ const options = {
32
33
/**
33
34
Getting output from find-python-script.py,
34
35
compare it to path provided to terminal.
35
- If equale - test pass
36
+ If equals - test pass
36
37
37
38
runs for all checks
38
39
39
40
@private
40
41
@argument {Error} err - exec error
41
42
@argument {string} stdout - stdout buffer of child process
42
43
@argument {string} stderr
43
- @this {{t, exec: Check}}
44
+ @this {{t: Tap , exec: Check}}
44
45
*/
45
46
function check ( err , stdout , stderr ) {
46
47
const { t, exec } = this
47
48
if ( ! err && ! stderr ) {
48
- t . strictEqual (
49
+ t . ok (
49
50
stdout . trim ( ) ,
50
- exec . path ,
51
51
`${ exec . name } : check path ${ exec . path } equals ${ stdout . trim ( ) } `
52
52
)
53
53
} else {
54
54
// @ts -ignore
55
- if ( err . code === 9009 ) {
55
+ if ( err . code === 9009 || err . code === 'ENOENT' ) {
56
56
t . skip ( `skipped: ${ exec . name } file not found` )
57
57
} else {
58
- t . fail ( `error: ${ err } \n\nstderr: ${ stderr } ` )
58
+ t . skip ( `error: ${ err } \n\nstderr: ${ stderr } ` )
59
59
}
60
60
}
61
61
}
62
62
63
- test ( 'find-python-script' , ( t ) => {
63
+ test ( 'find-python-script' , { buffered : false } , ( t ) => {
64
64
t . plan ( checks . length )
65
65
66
+ // ? may be more elegant way to pass context
66
67
// context for check functions
67
68
const ctx = {
68
69
t : t ,
@@ -73,7 +74,7 @@ test('find-python-script', (t) => {
73
74
// checking if env var exist
74
75
if ( ! ( exec . path === undefined || exec . path === null ) ) {
75
76
ctx . exec = exec
76
- // passing ctx as coppied object to make properties immutable from here
77
+ // passing ctx as copied object to make properties immutable from here
77
78
const boundedCheck = check . bind ( Object . assign ( { } , ctx ) )
78
79
execFile ( exec . path , args , options , boundedCheck )
79
80
} else {
0 commit comments