elapsed 0.0.1 → 0.2.0
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.
- checksums.yaml +4 -4
- data/.0pdd.yml +2 -19
- data/.github/workflows/actionlint.yml +5 -21
- data/.github/workflows/codecov.yml +9 -23
- data/.github/workflows/copyrights.yml +19 -0
- data/.github/workflows/markdown-lint.yml +6 -21
- data/.github/workflows/pdd.yml +6 -21
- data/.github/workflows/rake.yml +8 -24
- data/.github/workflows/reuse.yml +19 -0
- data/.github/workflows/typos.yml +19 -0
- data/.github/workflows/xcop.yml +6 -21
- data/.github/workflows/yamllint.yml +5 -20
- data/.gitignore +8 -5
- data/.rubocop.yml +8 -20
- data/.rultor.yml +4 -20
- data/.simplecov +2 -19
- data/Gemfile +12 -27
- data/Gemfile.lock +62 -151
- data/LICENSE.txt +1 -1
- data/LICENSES/MIT.txt +21 -0
- data/README.md +15 -6
- data/REUSE.toml +34 -0
- data/Rakefile +3 -30
- data/elapsed.gemspec +6 -23
- data/lib/elapsed.rb +25 -41
- data/test/test__helper.rb +22 -22
- data/test/test_elapsed.rb +71 -25
- metadata +18 -17
- data/.github/workflows/license.yml +0 -57
data/test/test_elapsed.rb
CHANGED
@@ -1,42 +1,34 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2024 Yegor Bugayenko
|
4
|
-
#
|
5
|
-
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
13
|
-
# copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
# SOFTWARE.
|
22
|
-
|
23
|
-
require 'minitest/autorun'
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
5
|
+
|
24
6
|
require 'loog'
|
7
|
+
require_relative 'test__helper'
|
25
8
|
require_relative '../lib/elapsed'
|
26
9
|
|
27
10
|
# Test.
|
28
11
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
29
|
-
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
12
|
+
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
30
13
|
# License:: MIT
|
31
14
|
class TestElapsed < Minitest::Test
|
32
15
|
def test_simple
|
33
16
|
loog = Loog::Buffer.new
|
34
17
|
r =
|
35
|
-
elapsed(loog,
|
18
|
+
elapsed(loog, good: 'Everything was good') do
|
36
19
|
4 + 5
|
37
20
|
end
|
38
21
|
assert_equal(9, r)
|
39
|
-
|
22
|
+
assert_includes(loog.to_s, 'was good')
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_with_failure
|
26
|
+
loog = Loog::Buffer.new
|
27
|
+
assert_raises(StandardError) do
|
28
|
+
elapsed(loog, bad: 'Failed miserably') do
|
29
|
+
raise 'oops'
|
30
|
+
end
|
31
|
+
end
|
40
32
|
end
|
41
33
|
|
42
34
|
def test_with_throw
|
@@ -44,7 +36,7 @@ class TestElapsed < Minitest::Test
|
|
44
36
|
elapsed(loog) do
|
45
37
|
throw :'Perfectly works'
|
46
38
|
end
|
47
|
-
|
39
|
+
assert_includes(loog.to_s, 'works')
|
48
40
|
end
|
49
41
|
|
50
42
|
def test_to_stdout
|
@@ -52,4 +44,58 @@ class TestElapsed < Minitest::Test
|
|
52
44
|
4 + 5
|
53
45
|
end
|
54
46
|
end
|
47
|
+
|
48
|
+
def test_with_over_threshold_reports
|
49
|
+
loog = Loog::Buffer.new
|
50
|
+
elapsed(loog, over: 0.001) do
|
51
|
+
sleep(0.01)
|
52
|
+
end
|
53
|
+
assert_includes(loog.to_s, 'Finished')
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_with_over_threshold_does_not_report
|
57
|
+
loog = Loog::Buffer.new
|
58
|
+
elapsed(loog, over: 1.0) do
|
59
|
+
4 + 5
|
60
|
+
end
|
61
|
+
assert_equal('', loog.to_s)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_with_over_threshold_on_error_reports
|
65
|
+
loog = Loog::Buffer.new
|
66
|
+
assert_raises(StandardError) do
|
67
|
+
elapsed(loog, over: 0.001, bad: 'Error occurred') do
|
68
|
+
sleep(0.01)
|
69
|
+
raise 'error'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
assert_includes(loog.to_s, 'Error occurred')
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_with_over_threshold_on_error_does_not_report
|
76
|
+
loog = Loog::Buffer.new
|
77
|
+
assert_raises(StandardError) do
|
78
|
+
elapsed(loog, over: 1.0, bad: 'Error occurred') do
|
79
|
+
raise 'error'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
assert_equal('', loog.to_s)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_with_over_threshold_on_throw_reports
|
86
|
+
loog = Loog::Buffer.new
|
87
|
+
elapsed(loog, over: 0.001) do
|
88
|
+
sleep(0.01)
|
89
|
+
throw :done
|
90
|
+
end
|
91
|
+
assert_includes(loog.to_s, 'done')
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_with_over_threshold_on_throw_does_not_report
|
95
|
+
loog = Loog::Buffer.new
|
96
|
+
elapsed(loog, over: 1.0) do
|
97
|
+
throw :done
|
98
|
+
end
|
99
|
+
assert_equal('', loog.to_s)
|
100
|
+
end
|
55
101
|
end
|
metadata
CHANGED
@@ -1,60 +1,61 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elapsed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: loog
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
|
-
- - "
|
16
|
+
- - "~>"
|
18
17
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
18
|
+
version: '0.6'
|
20
19
|
type: :runtime
|
21
20
|
prerelease: false
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
23
22
|
requirements:
|
24
|
-
- - "
|
23
|
+
- - "~>"
|
25
24
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
25
|
+
version: '0.6'
|
27
26
|
- !ruby/object:Gem::Dependency
|
28
27
|
name: tago
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
30
29
|
requirements:
|
31
|
-
- - "
|
30
|
+
- - "~>"
|
32
31
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
32
|
+
version: '0.1'
|
34
33
|
type: :runtime
|
35
34
|
prerelease: false
|
36
35
|
version_requirements: !ruby/object:Gem::Requirement
|
37
36
|
requirements:
|
38
|
-
- - "
|
37
|
+
- - "~>"
|
39
38
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
39
|
+
version: '0.1'
|
41
40
|
description: You simply pass a code block to the elapsed() function and it will print
|
42
41
|
the summary of execution to the log with the time it took
|
43
42
|
email: yegor256@gmail.com
|
44
43
|
executables: []
|
45
44
|
extensions: []
|
46
45
|
extra_rdoc_files:
|
47
|
-
- README.md
|
48
46
|
- LICENSE.txt
|
47
|
+
- README.md
|
49
48
|
files:
|
50
49
|
- ".0pdd.yml"
|
51
50
|
- ".gitattributes"
|
52
51
|
- ".github/workflows/actionlint.yml"
|
53
52
|
- ".github/workflows/codecov.yml"
|
54
|
-
- ".github/workflows/
|
53
|
+
- ".github/workflows/copyrights.yml"
|
55
54
|
- ".github/workflows/markdown-lint.yml"
|
56
55
|
- ".github/workflows/pdd.yml"
|
57
56
|
- ".github/workflows/rake.yml"
|
57
|
+
- ".github/workflows/reuse.yml"
|
58
|
+
- ".github/workflows/typos.yml"
|
58
59
|
- ".github/workflows/xcop.yml"
|
59
60
|
- ".github/workflows/yamllint.yml"
|
60
61
|
- ".gitignore"
|
@@ -65,19 +66,20 @@ files:
|
|
65
66
|
- Gemfile
|
66
67
|
- Gemfile.lock
|
67
68
|
- LICENSE.txt
|
69
|
+
- LICENSES/MIT.txt
|
68
70
|
- README.md
|
71
|
+
- REUSE.toml
|
69
72
|
- Rakefile
|
70
73
|
- elapsed.gemspec
|
71
74
|
- lib/elapsed.rb
|
72
75
|
- renovate.json
|
73
76
|
- test/test__helper.rb
|
74
77
|
- test/test_elapsed.rb
|
75
|
-
homepage:
|
78
|
+
homepage: https://github.com/yegor256/elapsed
|
76
79
|
licenses:
|
77
80
|
- MIT
|
78
81
|
metadata:
|
79
82
|
rubygems_mfa_required: 'true'
|
80
|
-
post_install_message:
|
81
83
|
rdoc_options:
|
82
84
|
- "--charset=UTF-8"
|
83
85
|
require_paths:
|
@@ -93,8 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
95
|
- !ruby/object:Gem::Version
|
94
96
|
version: '0'
|
95
97
|
requirements: []
|
96
|
-
rubygems_version: 3.
|
97
|
-
signing_key:
|
98
|
+
rubygems_version: 3.6.7
|
98
99
|
specification_version: 4
|
99
100
|
summary: A simple Ruby function to measure the time elapsed by the execution of a
|
100
101
|
block
|
@@ -1,57 +0,0 @@
|
|
1
|
-
# Copyright (c) 2024 Yegor Bugayenko
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in all
|
11
|
-
# copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
-
# SOFTWARE.
|
20
|
-
---
|
21
|
-
name: license
|
22
|
-
'on':
|
23
|
-
push:
|
24
|
-
branches:
|
25
|
-
- master
|
26
|
-
pull_request:
|
27
|
-
branches:
|
28
|
-
- master
|
29
|
-
jobs:
|
30
|
-
license:
|
31
|
-
runs-on: ubuntu-22.04
|
32
|
-
steps:
|
33
|
-
- uses: actions/checkout@v4
|
34
|
-
- shell: bash
|
35
|
-
run: |
|
36
|
-
header="Copyright (c) $(date +%Y) Yegor Bugayenko"
|
37
|
-
failed="false"
|
38
|
-
while IFS= read -r file; do
|
39
|
-
if ! grep -q "${header}" "${file}"; then
|
40
|
-
failed="true"
|
41
|
-
echo "⚠️ Copyright header is not found in: ${file}"
|
42
|
-
else
|
43
|
-
echo "File looks good: ${file}"
|
44
|
-
fi
|
45
|
-
done < <(find . -type f \( \
|
46
|
-
-name "Dockerfile" -o \
|
47
|
-
-name "LICENSE.txt" -o \
|
48
|
-
-name "Makefile" -o \
|
49
|
-
-name "Rakefile" -o \
|
50
|
-
-name "*.sh" -o \
|
51
|
-
-name "*.rb" -o \
|
52
|
-
-name "*.fe" -o \
|
53
|
-
-name "*.yml" \
|
54
|
-
\) -print)
|
55
|
-
if [ "${failed}" = "true" ]; then
|
56
|
-
exit 1
|
57
|
-
fi
|