always 0.0.5 → 0.1.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.
data/test/test_always.rb CHANGED
@@ -1,31 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2024 Yegor Bugayenko
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
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.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
22
5
 
23
- require 'minitest/autorun'
6
+ require 'concurrent/set'
24
7
  require_relative '../lib/always'
8
+ require_relative 'test__helper'
25
9
 
26
10
  # Test.
27
11
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
28
- # Copyright:: Copyright (c) 2024 Yegor Bugayenko
12
+ # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
29
13
  # License:: MIT
30
14
  class TestAlways < Minitest::Test
31
15
  def test_simple
@@ -36,6 +20,21 @@ class TestAlways < Minitest::Test
36
20
  a.stop
37
21
  end
38
22
 
23
+ def test_threads_have_names
24
+ names = Concurrent::Set.new
25
+ total = 3
26
+ a = Always.new(total, name: 'foo').on_error { |e| puts e }
27
+ a.start do
28
+ names.add(Thread.current.name)
29
+ end
30
+ sleep(0.1)
31
+ a.stop
32
+ assert_equal(total, names.size)
33
+ total.times do |i|
34
+ assert_includes(names, "foo-#{i + 1}")
35
+ end
36
+ end
37
+
39
38
  def test_with_error
40
39
  a = Always.new(5)
41
40
  failures = 0
@@ -44,7 +43,7 @@ class TestAlways < Minitest::Test
44
43
  end
45
44
  sleep(0.1)
46
45
  a.stop
47
- assert(failures.positive?)
46
+ assert_predicate(failures, :positive?)
48
47
  end
49
48
 
50
49
  def test_read_backtraces
@@ -56,7 +55,7 @@ class TestAlways < Minitest::Test
56
55
  end
57
56
  sleep(0.1)
58
57
  a.stop
59
- assert(failures.positive?)
58
+ assert_predicate(failures, :positive?)
60
59
  assert_equal(max, a.backtraces.size)
61
60
  end
62
61
 
@@ -67,8 +66,8 @@ class TestAlways < Minitest::Test
67
66
  sleep(0.1)
68
67
  threads, cycles, errors = a.to_s.split('/')
69
68
  assert_equal(n, threads.to_i)
70
- assert(cycles.to_i.positive?)
71
- assert(errors.to_i.zero?)
69
+ assert_predicate(cycles.to_i, :positive?)
70
+ assert_predicate(errors.to_i, :zero?)
72
71
  a.stop
73
72
  end
74
73
 
@@ -88,7 +87,7 @@ class TestAlways < Minitest::Test
88
87
  end
89
88
  sleep(0.1)
90
89
  a.stop
91
- assert(done.positive?)
90
+ assert_predicate(done, :positive?)
92
91
  end
93
92
 
94
93
  def test_with_broken_syntax
@@ -99,8 +98,8 @@ class TestAlways < Minitest::Test
99
98
  end
100
99
  sleep(0.1)
101
100
  _, _, errors = a.to_s.split('/')
102
- assert(!errors.to_i.zero?)
103
- assert(!failures.zero?)
101
+ refute_predicate(errors.to_i, :zero?)
102
+ refute_predicate(failures, :zero?)
104
103
  a.stop
105
104
  end
106
105
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: always
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-07-04 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: concurrent-ruby
@@ -31,17 +30,19 @@ email: yegor256@gmail.com
31
30
  executables: []
32
31
  extensions: []
33
32
  extra_rdoc_files:
34
- - README.md
35
33
  - LICENSE.txt
34
+ - README.md
36
35
  files:
37
36
  - ".0pdd.yml"
38
37
  - ".gitattributes"
39
38
  - ".github/workflows/actionlint.yml"
40
39
  - ".github/workflows/codecov.yml"
41
- - ".github/workflows/license.yml"
40
+ - ".github/workflows/copyrights.yml"
42
41
  - ".github/workflows/markdown-lint.yml"
43
42
  - ".github/workflows/pdd.yml"
44
43
  - ".github/workflows/rake.yml"
44
+ - ".github/workflows/reuse.yml"
45
+ - ".github/workflows/typos.yml"
45
46
  - ".github/workflows/xcop.yml"
46
47
  - ".github/workflows/yamllint.yml"
47
48
  - ".gitignore"
@@ -52,7 +53,9 @@ files:
52
53
  - Gemfile
53
54
  - Gemfile.lock
54
55
  - LICENSE.txt
56
+ - LICENSES/MIT.txt
55
57
  - README.md
58
+ - REUSE.toml
56
59
  - Rakefile
57
60
  - always.gemspec
58
61
  - lib/always.rb
@@ -64,7 +67,6 @@ licenses:
64
67
  - MIT
65
68
  metadata:
66
69
  rubygems_mfa_required: 'true'
67
- post_install_message:
68
70
  rdoc_options:
69
71
  - "--charset=UTF-8"
70
72
  require_paths:
@@ -80,8 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
82
  - !ruby/object:Gem::Version
81
83
  version: '0'
82
84
  requirements: []
83
- rubygems_version: 3.4.10
84
- signing_key:
85
+ rubygems_version: 3.6.7
85
86
  specification_version: 4
86
87
  summary: A simple Ruby framework that spins a loop forever, in a background thread
87
88
  test_files: []
@@ -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