@stdlib/random-streams-levy-cli 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +1 -1
- package/README.md +6 -3
- package/package.json +16 -27
- package/.github/workflows/publish_cli.yml +0 -165
- package/CONTRIBUTORS +0 -39
- package/test/fixtures/bad_state.txt +0 -0
- package/test/fixtures/state.txt +0 -0
- package/test/fixtures/write_error.js.txt +0 -41
- package/test/test.cli.js +0 -517
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2024 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -160,7 +160,7 @@ See [LICENSE][stdlib-license].
|
|
|
160
160
|
|
|
161
161
|
## Copyright
|
|
162
162
|
|
|
163
|
-
Copyright © 2016-
|
|
163
|
+
Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
164
164
|
|
|
165
165
|
</section>
|
|
166
166
|
|
|
@@ -173,8 +173,8 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors].
|
|
|
173
173
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/random-streams-levy-cli.svg
|
|
174
174
|
[npm-url]: https://npmjs.org/package/@stdlib/random-streams-levy-cli
|
|
175
175
|
|
|
176
|
-
[test-image]: https://github.com/stdlib-js/random-streams-levy/actions/workflows/test.yml/badge.svg?branch=v0.1
|
|
177
|
-
[test-url]: https://github.com/stdlib-js/random-streams-levy/actions/workflows/test.yml?query=branch:v0.1
|
|
176
|
+
[test-image]: https://github.com/stdlib-js/random-streams-levy/actions/workflows/test.yml/badge.svg?branch=v0.2.1
|
|
177
|
+
[test-url]: https://github.com/stdlib-js/random-streams-levy/actions/workflows/test.yml?query=branch:v0.2.1
|
|
178
178
|
|
|
179
179
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/random-streams-levy/main.svg
|
|
180
180
|
[coverage-url]: https://codecov.io/github/stdlib-js/random-streams-levy?branch=main
|
|
@@ -201,8 +201,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors].
|
|
|
201
201
|
[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
|
|
202
202
|
|
|
203
203
|
[deno-url]: https://github.com/stdlib-js/random-streams-levy/tree/deno
|
|
204
|
+
[deno-readme]: https://github.com/stdlib-js/random-streams-levy/blob/deno/README.md
|
|
204
205
|
[umd-url]: https://github.com/stdlib-js/random-streams-levy/tree/umd
|
|
206
|
+
[umd-readme]: https://github.com/stdlib-js/random-streams-levy/blob/umd/README.md
|
|
205
207
|
[esm-url]: https://github.com/stdlib-js/random-streams-levy/tree/esm
|
|
208
|
+
[esm-readme]: https://github.com/stdlib-js/random-streams-levy/blob/esm/README.md
|
|
206
209
|
[branches-url]: https://github.com/stdlib-js/random-streams-levy/blob/main/branches.md
|
|
207
210
|
|
|
208
211
|
[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-streams-levy/main/LICENSE
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/random-streams-levy-cli",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Create a readable stream for generating pseudorandom numbers drawn from a Lévy distribution.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -25,33 +25,22 @@
|
|
|
25
25
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@stdlib/array-uint32": "^0.1
|
|
29
|
-
"@stdlib/array-uint8": "^0.1
|
|
30
|
-
"@stdlib/assert-is-integer": "^0.1
|
|
31
|
-
"@stdlib/assert-is-uint8array": "^0.1
|
|
32
|
-
"@stdlib/blas-base-gcopy": "^0.
|
|
33
|
-
"@stdlib/buffer-from-array": "^0.1
|
|
34
|
-
"@stdlib/cli-ctor": "^0.1
|
|
35
|
-
"@stdlib/fs-read-file": "^0.1
|
|
36
|
-
"@stdlib/fs-write-file": "^0.1
|
|
37
|
-
"@stdlib/math-base-assert-is-nan": "^0.1
|
|
38
|
-
"@stdlib/process-cwd": "^0.1
|
|
39
|
-
"@stdlib/random-base-levy": "^0.1
|
|
40
|
-
"@stdlib/streams-node-stdout": "^0.1
|
|
41
|
-
"@stdlib/random-streams-levy": "0.1
|
|
42
|
-
},
|
|
43
|
-
"devDependencies": {
|
|
44
|
-
"@stdlib/assert-is-browser": "^0.1.0",
|
|
45
|
-
"@stdlib/assert-is-windows": "^0.1.0",
|
|
46
|
-
"@stdlib/fs-exists": "^0.1.0",
|
|
47
|
-
"@stdlib/fs-unlink": "^0.1.0",
|
|
48
|
-
"@stdlib/process-exec-path": "^0.1.0",
|
|
49
|
-
"@stdlib/string-replace": "^0.1.0",
|
|
50
|
-
"tape": "git+https://github.com/kgryte/tape.git#fix/globby",
|
|
51
|
-
"proxyquire": "^2.0.0",
|
|
52
|
-
"istanbul": "^0.4.1",
|
|
53
|
-
"tap-min": "git+https://github.com/Planeshifter/tap-min.git"
|
|
28
|
+
"@stdlib/array-uint32": "^0.2.1",
|
|
29
|
+
"@stdlib/array-uint8": "^0.2.1",
|
|
30
|
+
"@stdlib/assert-is-integer": "^0.2.1",
|
|
31
|
+
"@stdlib/assert-is-uint8array": "^0.2.1",
|
|
32
|
+
"@stdlib/blas-base-gcopy": "^0.2.0",
|
|
33
|
+
"@stdlib/buffer-from-array": "^0.2.1",
|
|
34
|
+
"@stdlib/cli-ctor": "^0.2.1",
|
|
35
|
+
"@stdlib/fs-read-file": "^0.2.1",
|
|
36
|
+
"@stdlib/fs-write-file": "^0.2.1",
|
|
37
|
+
"@stdlib/math-base-assert-is-nan": "^0.2.1",
|
|
38
|
+
"@stdlib/process-cwd": "^0.2.1",
|
|
39
|
+
"@stdlib/random-base-levy": "^0.2.1",
|
|
40
|
+
"@stdlib/streams-node-stdout": "^0.2.1",
|
|
41
|
+
"@stdlib/random-streams-levy": "0.2.1"
|
|
54
42
|
},
|
|
43
|
+
"devDependencies": {},
|
|
55
44
|
"keywords": [
|
|
56
45
|
"stdlib",
|
|
57
46
|
"stdmath",
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
#/
|
|
2
|
-
# @license Apache-2.0
|
|
3
|
-
#
|
|
4
|
-
# Copyright (c) 2023 The Stdlib Authors.
|
|
5
|
-
#
|
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
# you may not use this file except in compliance with the License.
|
|
8
|
-
# You may obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
# See the License for the specific language governing permissions and
|
|
16
|
-
# limitations under the License.
|
|
17
|
-
#/
|
|
18
|
-
|
|
19
|
-
# Workflow name:
|
|
20
|
-
name: publish_cli
|
|
21
|
-
|
|
22
|
-
# Workflow triggers:
|
|
23
|
-
on:
|
|
24
|
-
# Allow the workflow to be manually run:
|
|
25
|
-
workflow_dispatch:
|
|
26
|
-
# Workflow inputs:
|
|
27
|
-
inputs:
|
|
28
|
-
version:
|
|
29
|
-
description: 'Version Increment'
|
|
30
|
-
type: choice
|
|
31
|
-
default: 'none'
|
|
32
|
-
options:
|
|
33
|
-
- 'none'
|
|
34
|
-
- 'major'
|
|
35
|
-
- 'minor'
|
|
36
|
-
- 'patch'
|
|
37
|
-
- 'premajor'
|
|
38
|
-
- 'preminor'
|
|
39
|
-
- 'prepatch'
|
|
40
|
-
- 'prerelease'
|
|
41
|
-
|
|
42
|
-
# Workflow jobs:
|
|
43
|
-
jobs:
|
|
44
|
-
|
|
45
|
-
# Define job to publish package to npm:
|
|
46
|
-
publish:
|
|
47
|
-
|
|
48
|
-
# Define display name:
|
|
49
|
-
name: 'Publish CLI package to npm'
|
|
50
|
-
|
|
51
|
-
# Define the type of virtual host machine on which to run the job:
|
|
52
|
-
runs-on: ubuntu-latest
|
|
53
|
-
|
|
54
|
-
# Define environment variables:
|
|
55
|
-
env:
|
|
56
|
-
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
|
|
57
|
-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
58
|
-
|
|
59
|
-
# Define the sequence of job steps...
|
|
60
|
-
steps:
|
|
61
|
-
|
|
62
|
-
# Checkout cli branch:
|
|
63
|
-
- name: 'Checkout cli branch'
|
|
64
|
-
uses: actions/checkout@v3
|
|
65
|
-
with:
|
|
66
|
-
ref: cli
|
|
67
|
-
|
|
68
|
-
# Install Node.js:
|
|
69
|
-
- name: 'Install Node.js'
|
|
70
|
-
uses: actions/setup-node@v3
|
|
71
|
-
with:
|
|
72
|
-
node-version: 16
|
|
73
|
-
timeout-minutes: 5
|
|
74
|
-
|
|
75
|
-
# Configure git:
|
|
76
|
-
- name: 'Configure git'
|
|
77
|
-
run: |
|
|
78
|
-
git config --local user.email "noreply@stdlib.io"
|
|
79
|
-
git config --local user.name "stdlib-bot"
|
|
80
|
-
|
|
81
|
-
# Increment package version (if requested):
|
|
82
|
-
- name: 'Increment package version (if requested)'
|
|
83
|
-
if: ${{ github.event.inputs.version != 'none' }}
|
|
84
|
-
run: |
|
|
85
|
-
# Save NPM_TOKEN to user's .npmrc:
|
|
86
|
-
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
|
|
87
|
-
|
|
88
|
-
# Increment package version:
|
|
89
|
-
npm version ${{ github.event.inputs.version }} --no-git-tag-version
|
|
90
|
-
|
|
91
|
-
# Define variable for new version:
|
|
92
|
-
NEW_VERSION=$(node -p "require('./package.json').version")
|
|
93
|
-
|
|
94
|
-
# Replace branch in README.md link definitions for badges with the new version:
|
|
95
|
-
find . -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/branch([=:])[^ ]+/branch\1v${NEW_VERSION}/g"
|
|
96
|
-
|
|
97
|
-
# Create a new commit and tag:
|
|
98
|
-
git add package.json README.md
|
|
99
|
-
git commit -m "Release v${NEW_VERSION}"
|
|
100
|
-
git tag -a "v${NEW_VERSION}-cli" -m "Release v${NEW_VERSION}"
|
|
101
|
-
|
|
102
|
-
# Push changes to GitHub:
|
|
103
|
-
SLUG=${{ github.repository }}
|
|
104
|
-
git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" --follow-tags
|
|
105
|
-
|
|
106
|
-
# Replace GitHub MathJax equations with SVGs:
|
|
107
|
-
- name: 'Replace GitHub MathJax equations with SVGs'
|
|
108
|
-
run: |
|
|
109
|
-
find . -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe 's/```math\n([\s\S]+?)\n```\n\n//g'
|
|
110
|
-
find . -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe 's/<!-- <div class="equation"(.*)(<\/div>\s*-->)/<div class="equation"$1<\/div>/sg'
|
|
111
|
-
|
|
112
|
-
# Replace GitHub links to individual packages with npm links:
|
|
113
|
-
- name: 'Replace all GitHub links to individual packages with npm links'
|
|
114
|
-
run: |
|
|
115
|
-
find . -type f -name '*.md' -print0 | xargs -0 sed -Ei '/tree\/main/b; s/@stdlib\/([^:]*)\]: https:\/\/github.com\/stdlib-js/@stdlib\/\1\]: https:\/\/www.npmjs.com\/package\/@stdlib/g'
|
|
116
|
-
SLUG=${{ github.repository }}
|
|
117
|
-
ESCAPED_SLUG=${SLUG//\//\\\/}
|
|
118
|
-
REPO=${SLUG#*/}
|
|
119
|
-
find . -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/https:\/\/github.com\/${ESCAPED_SLUG}\/tree\/main/https:\/\/www.npmjs.com\/package\/@stdlib\/${REPO}/g"
|
|
120
|
-
|
|
121
|
-
# Publish package to npm:
|
|
122
|
-
- name: 'Publish package to npm'
|
|
123
|
-
uses: JS-DevTools/npm-publish@v2
|
|
124
|
-
with:
|
|
125
|
-
token: ${{ secrets.NPM_TOKEN }}
|
|
126
|
-
access: public
|
|
127
|
-
|
|
128
|
-
# Discard any uncommitted changes:
|
|
129
|
-
- name: 'Discard any uncommitted changes'
|
|
130
|
-
run: |
|
|
131
|
-
git reset --hard
|
|
132
|
-
|
|
133
|
-
# Send status to Slack channel if job fails:
|
|
134
|
-
- name: 'Send status to Slack channel in case of failure'
|
|
135
|
-
uses: act10ns/slack@v2
|
|
136
|
-
with:
|
|
137
|
-
status: ${{ job.status }}
|
|
138
|
-
steps: ${{ toJson(steps) }}
|
|
139
|
-
channel: '#npm-ci'
|
|
140
|
-
if: failure()
|
|
141
|
-
|
|
142
|
-
# Define job to cancel any running or queued workflow runs...
|
|
143
|
-
cancel:
|
|
144
|
-
|
|
145
|
-
# Define the type of virtual host machine on which to run the job:
|
|
146
|
-
runs-on: ubuntu-latest
|
|
147
|
-
|
|
148
|
-
# Time out the job after 3 minutes:
|
|
149
|
-
timeout-minutes: 3
|
|
150
|
-
|
|
151
|
-
# Define the sequence of job steps...
|
|
152
|
-
steps:
|
|
153
|
-
|
|
154
|
-
# Cancel any running or queued workflow runs:
|
|
155
|
-
- name: 'Cancel running or queued workflow runs'
|
|
156
|
-
uses: styfle/cancel-workflow-action@0.11.0
|
|
157
|
-
with:
|
|
158
|
-
workflow_id: >-
|
|
159
|
-
benchmark.yml,
|
|
160
|
-
examples.yml,
|
|
161
|
-
test.yml,
|
|
162
|
-
test_coverage.yml,
|
|
163
|
-
test_install.yml,
|
|
164
|
-
publish.yml
|
|
165
|
-
access_token: ${{ github.token }}
|
package/CONTRIBUTORS
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
# This file is generated by tools/scripts/update_contributors.
|
|
2
|
-
#
|
|
3
|
-
# Contributors listed in alphabetical order.
|
|
4
|
-
|
|
5
|
-
Ali Salesi <ali_sal1381@yahoo.com>
|
|
6
|
-
Amit Jimiwal <amitjimiwal45@gmail.com>
|
|
7
|
-
Athan Reines <kgryte@gmail.com>
|
|
8
|
-
Brendan Graetz <bguiz@users.noreply.github.com>
|
|
9
|
-
Bruno Fenzl <brunofenzl@gmail.com>
|
|
10
|
-
Christopher Dambamuromo <chridam@gmail.com>
|
|
11
|
-
Dan Rose <danoftheroses@gmail.com>
|
|
12
|
-
Dominik Moritz <domoritz@gmail.com>
|
|
13
|
-
Dorrin Sotoudeh <dorrinsotoudeh123@gmail.com>
|
|
14
|
-
Frank Kovacs <fran70kk@gmail.com>
|
|
15
|
-
Harshita Kalani <harshitakalani02@gmail.com>
|
|
16
|
-
James Gelok <jdgelok@gmail.com>
|
|
17
|
-
Jithin KS <jithinks112@gmail.com>
|
|
18
|
-
Joey Reed <joeyrreed@gmail.com>
|
|
19
|
-
Jordan Gallivan <115050475+Jordan-Gallivan@users.noreply.github.com>
|
|
20
|
-
Joris Labie <joris.labie1@gmail.com>
|
|
21
|
-
Justin Dennison <justin1dennison@gmail.com>
|
|
22
|
-
Marcus Fantham <mfantham@users.noreply.github.com>
|
|
23
|
-
Matt Cochrane <matthew.cochrane.eng@gmail.com>
|
|
24
|
-
Milan Raj <rajsite@users.noreply.github.com>
|
|
25
|
-
Momtchil Momtchev <momtchil@momtchev.com>
|
|
26
|
-
Naresh Jagadeesan <naresh.naresh000@gmail.com>
|
|
27
|
-
Nithin Katta <88046362+nithinkatta@users.noreply.github.com>
|
|
28
|
-
Ognjen Jevremović <ognjenjevremovic@users.noreply.github.com>
|
|
29
|
-
Philipp Burckhardt <pburckhardt@outlook.com>
|
|
30
|
-
Pranav Goswami <goswami.4@iitj.ac.in>
|
|
31
|
-
Ricky Reusser <rsreusser@gmail.com>
|
|
32
|
-
Roman Stetsyk <25715951+romanstetsyk@users.noreply.github.com>
|
|
33
|
-
Ryan Seal <splrk@users.noreply.github.com>
|
|
34
|
-
Seyyed Parsa Neshaei <spneshaei@users.noreply.github.com>
|
|
35
|
-
Shraddheya Shendre <shendreshraddheya@gmail.com>
|
|
36
|
-
Stephannie Jiménez Gacha <steff456@hotmail.com>
|
|
37
|
-
Yernar Yergaziyev <yernar.yergaziyev@erg.kz>
|
|
38
|
-
orimiles5 <97595296+orimiles5@users.noreply.github.com>
|
|
39
|
-
rei2hu <reimu@reimu.ws>
|
|
Binary file
|
package/test/fixtures/state.txt
DELETED
|
Binary file
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Apache-2.0
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2018 The Stdlib Authors.
|
|
5
|
-
*
|
|
6
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
* you may not use this file except in compliance with the License.
|
|
8
|
-
* You may obtain a copy of the License at
|
|
9
|
-
*
|
|
10
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
*
|
|
12
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
* See the License for the specific language governing permissions and
|
|
16
|
-
* limitations under the License.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
var proc = require( 'process' );
|
|
20
|
-
var resolve = require( 'path' ).resolve;
|
|
21
|
-
var proxyquire = require( 'proxyquire' );
|
|
22
|
-
|
|
23
|
-
var fpath = resolve( __dirname, '..', 'bin', 'cli' );
|
|
24
|
-
|
|
25
|
-
proc.stdin.isTTY = true;
|
|
26
|
-
proc.argv[ 2 ] = 2.0;
|
|
27
|
-
proc.argv[ 3 ] = 5.0;
|
|
28
|
-
proc.argv[ 4 ] = '--iter';
|
|
29
|
-
proc.argv[ 5 ] = '10';
|
|
30
|
-
proc.argv[ 6 ] = '--snapshot';
|
|
31
|
-
proc.argv[ 7 ] = resolve( __dirname, 'fixtures', 'tmp_state.txt' );
|
|
32
|
-
|
|
33
|
-
proxyquire( fpath, {
|
|
34
|
-
'@stdlib/fs-write-file': {
|
|
35
|
-
'sync': writeFile
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
function writeFile() {
|
|
40
|
-
return new Error( 'beep' );
|
|
41
|
-
}
|
package/test/test.cli.js
DELETED
|
@@ -1,517 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Apache-2.0
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2018 The Stdlib Authors.
|
|
5
|
-
*
|
|
6
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
* you may not use this file except in compliance with the License.
|
|
8
|
-
* You may obtain a copy of the License at
|
|
9
|
-
*
|
|
10
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
*
|
|
12
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
* See the License for the specific language governing permissions and
|
|
16
|
-
* limitations under the License.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
'use strict';
|
|
20
|
-
|
|
21
|
-
// MODULES //
|
|
22
|
-
|
|
23
|
-
var resolve = require( 'path' ).resolve;
|
|
24
|
-
var exec = require( 'child_process' ).exec;
|
|
25
|
-
var tape = require( 'tape' );
|
|
26
|
-
var IS_BROWSER = require( '@stdlib/assert-is-browser' );
|
|
27
|
-
var IS_WINDOWS = require( '@stdlib/assert-is-windows' );
|
|
28
|
-
var EXEC_PATH = require( '@stdlib/process-exec-path' );
|
|
29
|
-
var isnan = require( '@stdlib/math-base-assert-is-nan' );
|
|
30
|
-
var levy = require( '@stdlib/random-base-levy' ).factory;
|
|
31
|
-
var readFileSync = require( '@stdlib/fs-read-file' ).sync;
|
|
32
|
-
var existsSync = require( '@stdlib/fs-exists' ).sync;
|
|
33
|
-
var unlinkSync = require( '@stdlib/fs-unlink' ).sync;
|
|
34
|
-
var Uint32Array = require( '@stdlib/array-uint32' );
|
|
35
|
-
var Uint8Array = require( '@stdlib/array-uint8' );
|
|
36
|
-
var gcopy = require( '@stdlib/blas-base-gcopy' );
|
|
37
|
-
var replace = require( '@stdlib/string-replace' );
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
// VARIABLES //
|
|
41
|
-
|
|
42
|
-
var fpath = resolve( __dirname, '..', 'bin', 'cli' );
|
|
43
|
-
var opts = {
|
|
44
|
-
'skip': IS_BROWSER || IS_WINDOWS
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// FIXTURES //
|
|
49
|
-
|
|
50
|
-
var PKG_VERSION = require( './../package.json' ).version;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
// TESTS //
|
|
54
|
-
|
|
55
|
-
tape( 'command-line interface', function test( t ) {
|
|
56
|
-
t.ok( true, __filename );
|
|
57
|
-
t.end();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
tape( 'when invoked with a `--help` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) {
|
|
61
|
-
var expected;
|
|
62
|
-
var cmd;
|
|
63
|
-
|
|
64
|
-
expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), {
|
|
65
|
-
'encoding': 'utf8'
|
|
66
|
-
});
|
|
67
|
-
cmd = [
|
|
68
|
-
EXEC_PATH,
|
|
69
|
-
fpath,
|
|
70
|
-
'--help'
|
|
71
|
-
];
|
|
72
|
-
|
|
73
|
-
exec( cmd.join( ' ' ), done );
|
|
74
|
-
|
|
75
|
-
function done( error, stdout, stderr ) {
|
|
76
|
-
if ( error ) {
|
|
77
|
-
t.fail( error.message );
|
|
78
|
-
} else {
|
|
79
|
-
t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' );
|
|
80
|
-
t.strictEqual( stderr.toString(), expected+'\n', 'expected value' );
|
|
81
|
-
}
|
|
82
|
-
t.end();
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
tape( 'when invoked with a `-h` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) {
|
|
87
|
-
var expected;
|
|
88
|
-
var cmd;
|
|
89
|
-
|
|
90
|
-
expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), {
|
|
91
|
-
'encoding': 'utf8'
|
|
92
|
-
});
|
|
93
|
-
cmd = [
|
|
94
|
-
EXEC_PATH,
|
|
95
|
-
fpath,
|
|
96
|
-
'-h'
|
|
97
|
-
];
|
|
98
|
-
|
|
99
|
-
exec( cmd.join( ' ' ), done );
|
|
100
|
-
|
|
101
|
-
function done( error, stdout, stderr ) {
|
|
102
|
-
if ( error ) {
|
|
103
|
-
t.fail( error.message );
|
|
104
|
-
} else {
|
|
105
|
-
t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' );
|
|
106
|
-
t.strictEqual( stderr.toString(), expected+'\n', 'expected value' );
|
|
107
|
-
}
|
|
108
|
-
t.end();
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
tape( 'when invoked with a `--version` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) {
|
|
113
|
-
var cmd = [
|
|
114
|
-
EXEC_PATH,
|
|
115
|
-
fpath,
|
|
116
|
-
'--version'
|
|
117
|
-
];
|
|
118
|
-
|
|
119
|
-
exec( cmd.join( ' ' ), done );
|
|
120
|
-
|
|
121
|
-
function done( error, stdout, stderr ) {
|
|
122
|
-
if ( error ) {
|
|
123
|
-
t.fail( error.message );
|
|
124
|
-
} else {
|
|
125
|
-
t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' );
|
|
126
|
-
t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' );
|
|
127
|
-
}
|
|
128
|
-
t.end();
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
tape( 'when invoked with a `-V` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) {
|
|
133
|
-
var cmd = [
|
|
134
|
-
EXEC_PATH,
|
|
135
|
-
fpath,
|
|
136
|
-
'-V'
|
|
137
|
-
];
|
|
138
|
-
|
|
139
|
-
exec( cmd.join( ' ' ), done );
|
|
140
|
-
|
|
141
|
-
function done( error, stdout, stderr ) {
|
|
142
|
-
if ( error ) {
|
|
143
|
-
t.fail( error.message );
|
|
144
|
-
} else {
|
|
145
|
-
t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' );
|
|
146
|
-
t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' );
|
|
147
|
-
}
|
|
148
|
-
t.end();
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
tape( 'if provided insufficient arguments, the command-line interface prints an error and sets a non-zero exit code (none)', opts, function test( t ) {
|
|
153
|
-
var cmd = [
|
|
154
|
-
EXEC_PATH,
|
|
155
|
-
fpath
|
|
156
|
-
];
|
|
157
|
-
|
|
158
|
-
exec( cmd.join( ' ' ), done );
|
|
159
|
-
|
|
160
|
-
function done( error, stdout, stderr ) {
|
|
161
|
-
if ( error ) {
|
|
162
|
-
t.pass( error.message );
|
|
163
|
-
t.strictEqual( error.code, 1, 'expected exit code' );
|
|
164
|
-
} else {
|
|
165
|
-
t.fail( 'should error' );
|
|
166
|
-
}
|
|
167
|
-
t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' );
|
|
168
|
-
t.strictEqual( stderr.toString().length > 0, true, 'prints to `stderr`' );
|
|
169
|
-
t.end();
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
tape( 'if provided insufficient arguments, the command-line interface prints an error and sets a non-zero exit code (one)', opts, function test( t ) {
|
|
174
|
-
var cmd = [
|
|
175
|
-
EXEC_PATH,
|
|
176
|
-
fpath,
|
|
177
|
-
'2.0'
|
|
178
|
-
];
|
|
179
|
-
|
|
180
|
-
exec( cmd.join( ' ' ), done );
|
|
181
|
-
|
|
182
|
-
function done( error, stdout, stderr ) {
|
|
183
|
-
if ( error ) {
|
|
184
|
-
t.pass( error.message );
|
|
185
|
-
t.strictEqual( error.code, 1, 'expected exit code' );
|
|
186
|
-
} else {
|
|
187
|
-
t.fail( 'should error' );
|
|
188
|
-
}
|
|
189
|
-
t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' );
|
|
190
|
-
t.strictEqual( stderr.toString().length > 0, true, 'prints to `stderr`' );
|
|
191
|
-
t.end();
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
tape( 'the command-line interface supports specifying the number of generated pseudorandom numbers', opts, function test( t ) {
|
|
196
|
-
var cmd = [
|
|
197
|
-
EXEC_PATH,
|
|
198
|
-
fpath,
|
|
199
|
-
'2.0',
|
|
200
|
-
'5.0',
|
|
201
|
-
'--iter 10'
|
|
202
|
-
];
|
|
203
|
-
|
|
204
|
-
exec( cmd.join( ' ' ), done );
|
|
205
|
-
|
|
206
|
-
function done( error, stdout, stderr ) {
|
|
207
|
-
var results;
|
|
208
|
-
var v;
|
|
209
|
-
var i;
|
|
210
|
-
if ( error ) {
|
|
211
|
-
t.fail( error.message );
|
|
212
|
-
} else {
|
|
213
|
-
t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' );
|
|
214
|
-
|
|
215
|
-
results = stdout.toString();
|
|
216
|
-
results = results.split( '\n' );
|
|
217
|
-
|
|
218
|
-
// 10 numbers + trailing newline:
|
|
219
|
-
t.strictEqual( results.length, 11, 'has expected length' );
|
|
220
|
-
for ( i = 0; i < results.length-1; i++ ) {
|
|
221
|
-
v = parseFloat( results[ i ] );
|
|
222
|
-
t.strictEqual( typeof v, 'number', 'has expected type' );
|
|
223
|
-
t.strictEqual( isnan( v ), false, 'is not NaN' );
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
t.end();
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
tape( 'the command-line interface supports specifying the pseudorandom number generator seed', opts, function test( t ) {
|
|
231
|
-
var rand;
|
|
232
|
-
var cmd;
|
|
233
|
-
|
|
234
|
-
cmd = [
|
|
235
|
-
EXEC_PATH,
|
|
236
|
-
fpath,
|
|
237
|
-
'2.0',
|
|
238
|
-
'5.0',
|
|
239
|
-
'--iter 10',
|
|
240
|
-
'--seed 12345'
|
|
241
|
-
];
|
|
242
|
-
|
|
243
|
-
// Note: we assume that the underlying generator is the following PRNG...
|
|
244
|
-
rand = levy( 2.0, 5.0, {
|
|
245
|
-
'seed': 12345
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
exec( cmd.join( ' ' ), done );
|
|
249
|
-
|
|
250
|
-
function done( error, stdout, stderr ) {
|
|
251
|
-
var results;
|
|
252
|
-
var v;
|
|
253
|
-
var i;
|
|
254
|
-
if ( error ) {
|
|
255
|
-
t.fail( error.message );
|
|
256
|
-
} else {
|
|
257
|
-
t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' );
|
|
258
|
-
|
|
259
|
-
results = stdout.toString();
|
|
260
|
-
results = results.split( '\n' );
|
|
261
|
-
|
|
262
|
-
// 10 numbers + trailing newline:
|
|
263
|
-
t.strictEqual( results.length, 11, 'has expected length' );
|
|
264
|
-
for ( i = 0; i < results.length-1; i++ ) {
|
|
265
|
-
v = parseFloat( results[ i ] );
|
|
266
|
-
t.strictEqual( v, rand(), 'prints expected value' );
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
t.end();
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
tape( 'the command-line interface supports specifying a custom delimiter', opts, function test( t ) {
|
|
274
|
-
var cmd = [
|
|
275
|
-
EXEC_PATH,
|
|
276
|
-
fpath,
|
|
277
|
-
'2.0',
|
|
278
|
-
'5.0',
|
|
279
|
-
'--iter 10',
|
|
280
|
-
'--sep aba'
|
|
281
|
-
];
|
|
282
|
-
|
|
283
|
-
exec( cmd.join( ' ' ), done );
|
|
284
|
-
|
|
285
|
-
function done( error, stdout, stderr ) {
|
|
286
|
-
var results;
|
|
287
|
-
var v;
|
|
288
|
-
var i;
|
|
289
|
-
if ( error ) {
|
|
290
|
-
t.fail( error.message );
|
|
291
|
-
} else {
|
|
292
|
-
t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' );
|
|
293
|
-
|
|
294
|
-
results = stdout.toString();
|
|
295
|
-
results = results.split( '\n' );
|
|
296
|
-
|
|
297
|
-
// Only trailing newline:
|
|
298
|
-
t.strictEqual( results.length, 2, 'has expected length' );
|
|
299
|
-
|
|
300
|
-
results = results[ 0 ].split( 'aba' );
|
|
301
|
-
t.strictEqual( results.length, 10, 'has expected length' );
|
|
302
|
-
for ( i = 0; i < results.length-1; i++ ) {
|
|
303
|
-
v = parseFloat( results[ i ] );
|
|
304
|
-
t.strictEqual( typeof v, 'number', 'has expected type' );
|
|
305
|
-
t.strictEqual( isnan( v ), false, 'is not NaN' );
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
t.end();
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
tape( 'the command-line interface supports specifying a pseudorandom number generator state', opts, function test( t ) {
|
|
313
|
-
var state;
|
|
314
|
-
var spath;
|
|
315
|
-
var rand;
|
|
316
|
-
var cmd;
|
|
317
|
-
var len;
|
|
318
|
-
|
|
319
|
-
spath = resolve( __dirname, 'fixtures', 'state.txt' );
|
|
320
|
-
state = readFileSync( spath );
|
|
321
|
-
|
|
322
|
-
cmd = [
|
|
323
|
-
EXEC_PATH,
|
|
324
|
-
fpath,
|
|
325
|
-
'2.0',
|
|
326
|
-
'5.0',
|
|
327
|
-
'--iter 10',
|
|
328
|
-
'--state "'+spath+'"'
|
|
329
|
-
];
|
|
330
|
-
|
|
331
|
-
// Explicitly copy the `Buffer`, as, in older Node.js versions, `Buffer` is not a typed array:
|
|
332
|
-
len = state.length;
|
|
333
|
-
state = gcopy( len, state, 1, new Uint8Array( len ), 1 );
|
|
334
|
-
state = new Uint32Array( state.buffer, state.byteOffset, len/Uint32Array.BYTES_PER_ELEMENT ); // eslint-disable-line max-len
|
|
335
|
-
|
|
336
|
-
// Note: we assume that the underlying generator is the following PRNG...
|
|
337
|
-
rand = levy( 2.0, 5.0, {
|
|
338
|
-
'state': state
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
exec( cmd.join( ' ' ), done );
|
|
342
|
-
|
|
343
|
-
function done( error, stdout, stderr ) {
|
|
344
|
-
var results;
|
|
345
|
-
var v;
|
|
346
|
-
var i;
|
|
347
|
-
if ( error ) {
|
|
348
|
-
t.fail( error.message );
|
|
349
|
-
} else {
|
|
350
|
-
t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' );
|
|
351
|
-
|
|
352
|
-
results = stdout.toString();
|
|
353
|
-
results = results.split( '\n' );
|
|
354
|
-
|
|
355
|
-
// 10 numbers + trailing newline:
|
|
356
|
-
t.strictEqual( results.length, 11, 'has expected length' );
|
|
357
|
-
for ( i = 0; i < results.length-1; i++ ) {
|
|
358
|
-
v = parseFloat( results[ i ] );
|
|
359
|
-
t.strictEqual( v, rand(), 'prints expected value' );
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
t.end();
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
tape( 'the command-line interface supports specifying an output file path for saving the pseudorandom number generator state upon exit', opts, function test( t ) {
|
|
367
|
-
var state;
|
|
368
|
-
var spath;
|
|
369
|
-
var rand;
|
|
370
|
-
var cmd;
|
|
371
|
-
var arr;
|
|
372
|
-
var i;
|
|
373
|
-
|
|
374
|
-
// Define an output path for a temporary file:
|
|
375
|
-
spath = resolve( __dirname, 'fixtures', 'tmp_state_snapshot.txt' );
|
|
376
|
-
|
|
377
|
-
// Ensure that the temporary file does not already exist:
|
|
378
|
-
if ( existsSync( spath ) ) {
|
|
379
|
-
t.fail( 'temporary file should not exist: '+spath );
|
|
380
|
-
return t.end();
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
cmd = [
|
|
384
|
-
EXEC_PATH,
|
|
385
|
-
fpath,
|
|
386
|
-
'2.0',
|
|
387
|
-
'5.0',
|
|
388
|
-
'--seed 12345',
|
|
389
|
-
'--iter 10',
|
|
390
|
-
'--snapshot "'+spath+'"'
|
|
391
|
-
];
|
|
392
|
-
|
|
393
|
-
// Note: we assume that the underlying generator is the following PRNG...
|
|
394
|
-
rand = levy( 2.0, 5.0, {
|
|
395
|
-
'seed': 12345
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
// Advance the PRNG state:
|
|
399
|
-
arr = [];
|
|
400
|
-
for ( i = 0; i < 10; i++ ) {
|
|
401
|
-
arr.push( rand() );
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
// Get the current PRNG state:
|
|
405
|
-
state = rand.state;
|
|
406
|
-
|
|
407
|
-
exec( cmd.join( ' ' ), done );
|
|
408
|
-
|
|
409
|
-
function done( error, stdout, stderr ) {
|
|
410
|
-
var snapshot;
|
|
411
|
-
var results;
|
|
412
|
-
var len;
|
|
413
|
-
var err;
|
|
414
|
-
var v;
|
|
415
|
-
var i;
|
|
416
|
-
if ( error ) {
|
|
417
|
-
t.fail( error.message );
|
|
418
|
-
} else {
|
|
419
|
-
t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' );
|
|
420
|
-
|
|
421
|
-
results = stdout.toString();
|
|
422
|
-
results = results.split( '\n' );
|
|
423
|
-
|
|
424
|
-
// 10 numbers + trailing newline:
|
|
425
|
-
t.strictEqual( results.length, 11, 'has expected length' );
|
|
426
|
-
for ( i = 0; i < results.length-1; i++ ) {
|
|
427
|
-
v = parseFloat( results[ i ] );
|
|
428
|
-
t.strictEqual( v, arr[ i ], 'prints expected value' );
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
// Check that the PRNG state was written to a file:
|
|
432
|
-
t.strictEqual( existsSync( spath ), true, 'temporary snapshot file exists' );
|
|
433
|
-
|
|
434
|
-
// Verify the file contents (note: we need to explicitly copy the `Buffer`, as, in older Node.js versions, `Buffer` is not a typed array):
|
|
435
|
-
snapshot = readFileSync( spath );
|
|
436
|
-
len = snapshot.length;
|
|
437
|
-
snapshot = gcopy( len, snapshot, 1, new Uint8Array( len ), 1 );
|
|
438
|
-
snapshot = new Uint32Array( snapshot.buffer, snapshot.byteOffset, len/Uint32Array.BYTES_PER_ELEMENT ); // eslint-disable-line max-len
|
|
439
|
-
|
|
440
|
-
t.deepEqual( snapshot, state, 'file contains expected contents' );
|
|
441
|
-
|
|
442
|
-
// Remove the temporary file:
|
|
443
|
-
err = unlinkSync( spath );
|
|
444
|
-
if ( err ) {
|
|
445
|
-
t.fail( err.message );
|
|
446
|
-
}
|
|
447
|
-
t.strictEqual( existsSync( spath ), false, 'temporary snapshot file does not exist' );
|
|
448
|
-
}
|
|
449
|
-
t.end();
|
|
450
|
-
}
|
|
451
|
-
});
|
|
452
|
-
|
|
453
|
-
tape( 'if provided an invalid pseudorandom number generator state, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) {
|
|
454
|
-
var spath;
|
|
455
|
-
var cmd;
|
|
456
|
-
|
|
457
|
-
spath = resolve( __dirname, 'fixtures', 'bad_state.txt' );
|
|
458
|
-
|
|
459
|
-
cmd = [
|
|
460
|
-
EXEC_PATH,
|
|
461
|
-
fpath,
|
|
462
|
-
'2.0',
|
|
463
|
-
'5.0',
|
|
464
|
-
'--iter 10',
|
|
465
|
-
'--state "'+spath+'"'
|
|
466
|
-
];
|
|
467
|
-
|
|
468
|
-
exec( cmd.join( ' ' ), done );
|
|
469
|
-
|
|
470
|
-
function done( error, stdout, stderr ) {
|
|
471
|
-
if ( error ) {
|
|
472
|
-
t.pass( error.message );
|
|
473
|
-
t.strictEqual( error.code, 1, 'expected exit code' );
|
|
474
|
-
} else {
|
|
475
|
-
t.fail( 'should error' );
|
|
476
|
-
}
|
|
477
|
-
t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' );
|
|
478
|
-
t.strictEqual( stderr.toString().length > 0, true, 'prints to `stderr`' );
|
|
479
|
-
t.end();
|
|
480
|
-
}
|
|
481
|
-
});
|
|
482
|
-
|
|
483
|
-
tape( 'if an error is encountered when writing pseudorandom number generator state to file, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) {
|
|
484
|
-
var script;
|
|
485
|
-
var opts;
|
|
486
|
-
var cmd;
|
|
487
|
-
|
|
488
|
-
script = readFileSync( resolve( __dirname, 'fixtures', 'write_error.js.txt' ), {
|
|
489
|
-
'encoding': 'utf8'
|
|
490
|
-
});
|
|
491
|
-
|
|
492
|
-
// Replace single quotes with double quotes:
|
|
493
|
-
script = replace( script, '\'', '"' );
|
|
494
|
-
|
|
495
|
-
cmd = [
|
|
496
|
-
EXEC_PATH,
|
|
497
|
-
'-e',
|
|
498
|
-
'\''+script+'\''
|
|
499
|
-
];
|
|
500
|
-
|
|
501
|
-
opts = {
|
|
502
|
-
'cwd': __dirname
|
|
503
|
-
};
|
|
504
|
-
|
|
505
|
-
exec( cmd.join( ' ' ), opts, done );
|
|
506
|
-
|
|
507
|
-
function done( error, stdout, stderr ) {
|
|
508
|
-
if ( error ) {
|
|
509
|
-
t.pass( error.message );
|
|
510
|
-
t.strictEqual( error.code, 1, 'expected exit code' );
|
|
511
|
-
}
|
|
512
|
-
// Pseudorandom numbers have already been written to `stdout` by the time the error is encountered...
|
|
513
|
-
t.strictEqual( stdout.toString().length > 0, true, 'prints to `stdout`' );
|
|
514
|
-
t.strictEqual( stderr.toString(), 'Error: beep\n', 'expected value' );
|
|
515
|
-
t.end();
|
|
516
|
-
}
|
|
517
|
-
});
|