File size: 1,929 Bytes
82ceab0
ae07b89
 
 
 
82ceab0
ae07b89
 
 
 
8aaba9a
ae07b89
 
 
 
 
 
 
 
 
7953154
ae07b89
7953154
 
ae07b89
 
8d0a50d
72cecc9
 
 
 
 
 
6468892
72cecc9
 
 
6468892
72cecc9
 
 
 
8d0a50d
 
 
 
 
 
 
 
ae07b89
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require_relative "helper"
require 'tempfile'
require 'tmpdir'
require 'shellwords'

class TestPackage < TestBase
  def test_build
    Tempfile.create do |file|
      assert system("gem", "build", "whispercpp.gemspec", "--output", file.to_path.shellescape, exception: true)
      assert file.size > 0
      assert_path_exist file.to_path
    end
  end

  sub_test_case "Building binary on installation" do
    def setup
      system "rake", "build", exception: true
    end

    def test_install
      gemspec = Gem::Specification.load("whispercpp.gemspec")
      Dir.mktmpdir do |dir|
        system "gem", "install", "--install-dir", dir.shellescape, "--no-document", "pkg/#{gemspec.file_name.shellescape}", exception: true
        assert_installed dir, gemspec.version
      end
    end

    def test_install_with_coreml
      omit_unless RUBY_PLATFORM.match?(/darwin/) do
        gemspec = Gem::Specification.load("whispercpp.gemspec")
        Dir.mktmpdir do |dir|
          system "gem", "install", "--install-dir", dir.shellescape, "--no-document", "pkg/#{gemspec.file_name.shellescape}", "--", "--enable-whisper-coreml", exception: true
          assert_installed dir, gemspec.version
          libdir = File.join(dir, "gems", "#{gemspec.name}-#{gemspec.version}", "lib")
          assert_nothing_raised do
            system "ruby", "-I", libdir, "-r", "whisper", "-e", "Whisper::Context.new('tiny')", exception: true
          end
          assert_match(/COREML = 1/, `ruby -I #{libdir.shellescape} -r whisper -e 'puts Whisper.system_info_str'`)
        end
      end
    end

    private

    def assert_installed(dir, version)
      assert_path_exist File.join(dir, "gems/whispercpp-#{version}/lib", "whisper.#{RbConfig::CONFIG["DLEXT"]}")
      assert_path_exist File.join(dir, "gems/whispercpp-#{version}/LICENSE")
      assert_path_not_exist File.join(dir, "gems/whispercpp-#{version}/ext/build")
    end
  end
end