Skip to content

Commit

Permalink
test: use assert_includes for better failure messages
Browse files Browse the repository at this point in the history
and fix up the paths on windows
  • Loading branch information
flavorjones committed Sep 9, 2023
1 parent aa982b2 commit 7f2a847
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/mini_portile2/mini_portile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def activate
end

if set_ldflags && File.exist?(lib_path)
full_lib_path = File.expand_path(lib_path)
full_lib_path = native_path(lib_path)
flag = "-L#{full_lib_path}"

# rely on LDFLAGS when cross-compiling
Expand Down
51 changes: 30 additions & 21 deletions test/test_activate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,78 +31,78 @@ def teardown

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

recipe.activate

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

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

recipe.activate

assert(path_elements('PATH').include?(bin_path))
assert_includes(path_elements('PATH'), 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))
refute_includes(path_elements('CPATH'), include_path)

recipe.activate

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

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

recipe.activate

assert(path_elements('CPATH').include?(include_path))
assert_includes(path_elements('CPATH'), 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))
refute_includes(path_elements('LIBRARY_PATH'), lib_path)

recipe.activate

refute(path_elements('LIBRARY_PATH').include?(lib_path))
refute_includes(path_elements('LIBRARY_PATH'), 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))
refute_includes(path_elements('LIBRARY_PATH'), lib_path)

recipe.activate

assert(path_elements('LIBRARY_PATH').include?(lib_path))
assert_includes(path_elements('LIBRARY_PATH'), 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}"))
refute_includes(flag_elements('LDFLAGS'), "-L#{lib_path}")

recipe.activate

refute(flag_elements('LDFLAGS').include?("-L#{lib_path}"))
refute_includes(flag_elements('LDFLAGS'), "-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}"))
refute_includes(flag_elements('LDFLAGS'), "-L#{lib_path}")

recipe.activate

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

def test_LDFLAGS_global_when_not_set
Expand All @@ -120,7 +120,7 @@ def test_LDFLAGS_global_when_set

recipe.activate

assert($LDFLAGS.split.include?("-L#{lib_path}"))
assert_includes($LDFLAGS.split, "-L#{lib_path}")
end

def test_LDFLAGS_global_when_set_but_option_is_turned_off
Expand All @@ -130,7 +130,7 @@ def test_LDFLAGS_global_when_set_but_option_is_turned_off
recipe.set_ldflags = false
recipe.activate

refute($LDFLAGS.split.include?("-L#{lib_path}"))
refute_includes($LDFLAGS.split, "-L#{lib_path}")
end

private
Expand All @@ -143,15 +143,24 @@ def flag_elements(varname)
ENV.fetch(varname, "").split
end

def native_path(path)
path = File.expand_path(path)
if File::ALT_SEPARATOR
path.tr(File::SEPARATOR, File::ALT_SEPARATOR)
else
path
end
end

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

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

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

0 comments on commit 7f2a847

Please sign in to comment.