diff --git a/.github/workflows/valgrind.yaml b/.github/workflows/valgrind.yaml new file mode 100644 index 0000000..249a3c8 --- /dev/null +++ b/.github/workflows/valgrind.yaml @@ -0,0 +1,42 @@ +name: Memcheck + +on: [push, pull_request] + +permissions: + contents: read + +jobs: + test: + name: ${{matrix.ruby}} on ${{matrix.os}} + runs-on: ${{matrix.os}}-latest + continue-on-error: ${{matrix.experimental}} + + strategy: + matrix: + os: + - ubuntu + + ruby: + - "3.2" + - "3.3" + - "3.4" + - "4.0" + + experimental: [false] + + include: + - os: ubuntu + ruby: head + experimental: true + + steps: + - uses: actions/checkout@v6 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{matrix.ruby}} + bundler-cache: true + - name: Install Valgrind + run: sudo apt-get install -y valgrind + - name: Run tests + timeout-minutes: 10 + run: bundle exec rake spec:valgrind diff --git a/Rakefile b/Rakefile index 4c2dcbc..3721dfe 100644 --- a/Rakefile +++ b/Rakefile @@ -48,24 +48,11 @@ namespace :build do end end -# adapted from http://flavoriffic.blogspot.com/2009/06/easily-valgrind-gdb-your-ruby-c.html -def specs_command - require "find" - files = [] - Find.find("spec") do |f| - files << f if File.basename(f) =~ /.*spec.*\.rb$/ - end - cmdline = "#{RUBY} -I.:lib:ext:spec \ - -e '%w[#{files.join(' ')}].each { |f| require f }'" -end - -namespace :spec do - desc "run specs with valgrind" - task :valgrind => :compile do - system "valgrind --num-callers=15 \ - --partial-loads-ok=yes --undef-value-errors=no \ - --tool=memcheck --leak-check=yes --track-fds=yes \ - --show-reachable=yes #{specs_command}" +if RUBY_PLATFORM.include?('linux') + require 'ruby_memcheck' + require 'ruby_memcheck/rspec/rake_task' + namespace :spec do + RubyMemcheck::RSpec::RakeTask.new(valgrind: :compile) end end diff --git a/gems.rb b/gems.rb index 48a8cd5..0c1e7ed 100644 --- a/gems.rb +++ b/gems.rb @@ -7,3 +7,7 @@ gem "bake-gem" gem "bake-modernize" end + +group :development, :test do + gem 'ruby_memcheck', '~> 3.0' if RUBY_PLATFORM.include?('linux') +end