Skip to content

Commit

Permalink
test: backfill coverage for the #activate method
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed Sep 9, 2023
1 parent ee637e0 commit fee7cde
Showing 1 changed file with 127 additions and 0 deletions.
127 changes: 127 additions & 0 deletions test/test_activate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
require File.expand_path('../helper', __FILE__)

class TestActivate < TestCase
attr_reader :recipe

def setup
super

@save_env = %w[PATH CPATH LIBRARY_PATH].inject({}) do |env, var|
env.update(var => ENV[var])
end

FileUtils.rm_rf(["tmp", "ports"]) # remove any previous test files

@recipe = MiniPortile.new("foo", "1.0.0").tap do |recipe|
recipe.logger = StringIO.new
end
end

def teardown
FileUtils.rm_rf(["tmp", "ports"]) # remove any previous test files

@save_env.each do |var, val|
ENV[var] = val
end

super
end

def test_PATH_env_var_when_bin_does_not_exist
refute(Dir.exist?(bin_path))
refute(path_elements('PATH').include?(bin_path))

recipe.activate

refute(path_elements('PATH').include?(bin_path))
end

def test_PATH_env_var_when_bin_exists
FileUtils.mkdir_p(bin_path)
refute(path_elements('PATH').include?(bin_path))

recipe.activate

assert(path_elements('PATH').include?(bin_path))
end

def test_CPATH_env_var_when_include_does_not_exist
refute(Dir.exist?(include_path))
refute(path_elements('CPATH').include?(include_path))

recipe.activate

refute(path_elements('CPATH').include?(include_path))
end

def test_CPATH_env_var_when_include_exists
FileUtils.mkdir_p(include_path)
refute(path_elements('CPATH').include?(include_path))

recipe.activate

assert(path_elements('CPATH').include?(include_path))
end

def test_LIBRARY_PATH_env_var_when_lib_does_not_exist
refute(Dir.exist?(lib_path))
refute(path_elements('LIBRARY_PATH').include?(lib_path))

recipe.activate

refute(path_elements('LIBRARY_PATH').include?(lib_path))
end

def test_LIBRARY_PATH_env_var_when_lib_exists
FileUtils.mkdir_p(lib_path)
refute(path_elements('LIBRARY_PATH').include?(lib_path))

recipe.activate

assert(path_elements('LIBRARY_PATH').include?(lib_path))
end

def test_LDFLAGS_env_var_when_not_cross_compiling
FileUtils.mkdir_p(lib_path)
assert_equal(recipe.host, recipe.original_host) # assert on setup)

refute(flag_elements('LDFLAGS').include?("-L#{lib_path}"))

recipe.activate

refute(flag_elements('LDFLAGS').include?("-L#{lib_path}"))
end

def test_LDFLAGS_env_var_when_cross_compiling
recipe.host = recipe.original_host + "-x" # make them not-equal
FileUtils.mkdir_p(lib_path)

refute(flag_elements('LDFLAGS').include?("-L#{lib_path}"))

recipe.activate

assert(flag_elements('LDFLAGS').include?("-L#{lib_path}"))
end

private

def path_elements(varname)
ENV.fetch(varname, "").split(File::PATH_SEPARATOR)
end

def flag_elements(varname)
ENV.fetch(varname, "").split
end

def bin_path
File.join(recipe.path, "bin")
end

def include_path
File.join(recipe.path, "include")
end

def lib_path
File.join(recipe.path, "lib")
end
end

0 comments on commit fee7cde

Please sign in to comment.