Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Untested files are counted taking into account filters include/exclude #115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion spec/cli_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ local function register_cli_tests(enable_cluacov)
assert_cli("includeuntestedfiles", enable_cluacov)
assert_cli("includeuntestedfiles", enable_cluacov, "expected2.out", "-c 2.luacov")
assert_cli("includeuntestedfiles", enable_cluacov, "expected3.out", "-c 3.luacov")
assert_cli("includeuntestedfiles/subdir", enable_cluacov)
end)

end
Expand Down
10 changes: 5 additions & 5 deletions spec/includeuntestedfiles/2.luacov
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
return {
include = {
"example%-src%/moduleA%/*"
},
-- All files implicitly included
includeuntestedfiles = true,

includeuntestedfiles = {
"example-src/moduleA"
-- In this case, only files from the `dir` directory are included in the calculation.
include = {
"dir%/*"
}
}
11 changes: 6 additions & 5 deletions spec/includeuntestedfiles/3.luacov
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
return {
modules = {
["libB"] = "example-src/moduleA/libB.lua"
},
includeuntestedfiles = {
"example-src/moduleA/libB.lua"
-- All files implicitly included
includeuntestedfiles = true,

-- In this case, files from the `dir` directory are not included in the calculation.
exclude = {
"dir"
}
}
1 change: 1 addition & 0 deletions spec/includeuntestedfiles/bar.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
return "This is file Bar"
77 changes: 77 additions & 0 deletions spec/includeuntestedfiles/dir/foo.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
-- Samurai Name and Wisdom Generator

-- Function to generate a random samurai name
function generateSamuraiName()
local firstNames = {"Takeda", "Oda", "Tokugawa", "Uesugi", "Shimazu", "Mori", "Date", "Sanada", "Hattori", "Honda"}
local lastNames = {"Nobunaga", "Ieyasu", "Kenshin", "Yoshihiro", "Yoshimoto", "Masamune", "Yukimura", "Hanzo", "Tadakatsu", "Shingen"}

local firstName = firstNames[math.random(#firstNames)]
local lastName = lastNames[math.random(#lastNames)]

return firstName .. " " .. lastName
end

-- Function to generate a random samurai wisdom
function generateSamuraiWisdom()
local wisdoms = {
"The bamboo that bends is stronger than the oak that resists.",
"Victory comes to those who make the last move.",
"Patience is the warrior's greatest weapon.",
"A samurai's mind is as sharp as his blade.",
"In the midst of chaos, there is also opportunity.",
"The journey of a thousand miles begins with a single step.",
"To know oneself is to study oneself in action with another person.",
"The ultimate aim of martial arts is not having to use them.",
"A warrior is worthless unless he rises above others and stands strong in the midst of a storm.",
"The way of the warrior is resolute acceptance of death."
}

return wisdoms[math.random(#wisdoms)]
end

-- Function to display ASCII art of a samurai
function displaySamuraiArt()
print(" O")
print(" /|\\")
print(" / | \\")
print(" / | \\")
print(" / | \\")
print(" / | \\")
print(" / | \\")
print(" / | \\")
print("/_______|_______\\")
print(" / \\")
print(" / \\")
print(" / \\")
print(" / \\")
print(" / \\")
print(" / \\")
print(" / \\")
print("/_______________\\")
end

-- Main function to generate and display samurai name and wisdom
function main()
math.randomseed(os.time())

print("Welcome to the Samurai Name and Wisdom Generator!")
print("-----------------------------------------------")

local samuraiName = generateSamuraiName()
local samuraiWisdom = generateSamuraiWisdom()

print("\nYour Samurai Name:")
print("------------------")
print(samuraiName)

print("\nSamurai Wisdom:")
print("---------------")
print(samuraiWisdom)

print("\nSamurai Art:")
print("------------")
displaySamuraiArt()
end

-- Run the main function
main()
42 changes: 42 additions & 0 deletions spec/includeuntestedfiles/dir/moduleA/too.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
local max_iterations = 100
local width = 80
local height = 40
local x_min, x_max = -2.0, 1.0
local y_min, y_max = -1.0, 1.0

local function mandelbrot(cx, cy)
local x, y = 0, 0
local iteration = 0

while x*x + y*y <= 4 and iteration < max_iterations do
local x_new = x*x - y*y + cx
y = 2*x*y + cy
x = x_new
iteration = iteration + 1
end

return iteration
end

local function draw_mandelbrot()
for py = 0, height - 1 do
local y = y_min + (y_max - y_min) * py / (height - 1)
local line = ""

for px = 0, width - 1 do
local x = x_min + (x_max - x_min) * px / (width - 1)
local iteration = mandelbrot(x, y)

if iteration == max_iterations then
line = line .. "#"
else
local shade = math.floor((iteration / max_iterations) * 10)
line = line .. string.sub(" .:-=+*#%@", shade + 1, shade + 1)
end
end

print(line)
end
end

draw_mandelbrot()
1 change: 0 additions & 1 deletion spec/includeuntestedfiles/example-src/moduleA/libA.lua

This file was deleted.

1 change: 0 additions & 1 deletion spec/includeuntestedfiles/example-src/moduleA/libB.lua

This file was deleted.

1 change: 0 additions & 1 deletion spec/includeuntestedfiles/example-src/moduleB/aLib.lua

This file was deleted.

1 change: 0 additions & 1 deletion spec/includeuntestedfiles/example-src/moduleB/bLib.lua

This file was deleted.

This file was deleted.

This file was deleted.

169 changes: 126 additions & 43 deletions spec/includeuntestedfiles/expected.out
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,66 +1,149 @@
==============================================================================
example-src/moduleA/libA.lua
bar.lua
==============================================================================
1 local a = 1 + 1
1 return "This is file Bar"

==============================================================================
example-src/moduleA/libB.lua
dir/foo.lua
==============================================================================
*0 local b = 1 - math.huge
-- Samurai Name and Wisdom Generator

==============================================================================
example-src/moduleB/aLib.lua
==============================================================================
*0 local val = "ue"
-- Function to generate a random samurai name
*0 function generateSamuraiName()
*0 local firstNames = {"Takeda", "Oda", "Tokugawa", "Uesugi", "Shimazu", "Mori", "Date", "Sanada", "Hattori", "Honda"}
*0 local lastNames = {"Nobunaga", "Ieyasu", "Kenshin", "Yoshihiro", "Yoshimoto", "Masamune", "Yukimura", "Hanzo", "Tadakatsu", "Shingen"}

==============================================================================
example-src/moduleB/bLib.lua
==============================================================================
*0 local test = 123
*0 local firstName = firstNames[math.random(#firstNames)]
*0 local lastName = lastNames[math.random(#lastNames)]

==============================================================================
example-src/third-module/lib-1.lua
==============================================================================
1 return 5
*0 return firstName .. " " .. lastName
end

==============================================================================
example-src/third-module/lib-2.lua
==============================================================================
1 return 0
-- Function to generate a random samurai wisdom
*0 function generateSamuraiWisdom()
*0 local wisdoms = {
"The bamboo that bends is stronger than the oak that resists.",
"Victory comes to those who make the last move.",
"Patience is the warrior's greatest weapon.",
"A samurai's mind is as sharp as his blade.",
"In the midst of chaos, there is also opportunity.",
"The journey of a thousand miles begins with a single step.",
"To know oneself is to study oneself in action with another person.",
"The ultimate aim of martial arts is not having to use them.",
"A warrior is worthless unless he rises above others and stands strong in the midst of a storm.",
"The way of the warrior is resolute acceptance of death."
}

*0 return wisdoms[math.random(#wisdoms)]
end

-- Function to display ASCII art of a samurai
*0 function displaySamuraiArt()
*0 print(" O")
*0 print(" /|\\")
*0 print(" / | \\")
*0 print(" / | \\")
*0 print(" / | \\")
*0 print(" / | \\")
*0 print(" / | \\")
*0 print(" / | \\")
*0 print("/_______|_______\\")
*0 print(" / \\")
*0 print(" / \\")
*0 print(" / \\")
*0 print(" / \\")
*0 print(" / \\")
*0 print(" / \\")
*0 print(" / \\")
*0 print("/_______________\\")
end

-- Main function to generate and display samurai name and wisdom
*0 function main()
*0 math.randomseed(os.time())

*0 print("Welcome to the Samurai Name and Wisdom Generator!")
*0 print("-----------------------------------------------")

*0 local samuraiName = generateSamuraiName()
*0 local samuraiWisdom = generateSamuraiWisdom()

*0 print("\nYour Samurai Name:")
*0 print("------------------")
*0 print(samuraiName)

*0 print("\nSamurai Wisdom:")
*0 print("---------------")
*0 print(samuraiWisdom)

*0 print("\nSamurai Art:")
*0 print("------------")
*0 displaySamuraiArt()
end

-- Run the main function
*0 main()

==============================================================================
subdir/test.lua
dir/moduleA/too.lua
==============================================================================
*0 local max_iterations = 100
*0 local width = 80
*0 local height = 40
*0 local x_min, x_max = -2.0, 1.0
*0 local y_min, y_max = -1.0, 1.0

local function mandelbrot(cx, cy)
*0 local x, y = 0, 0
*0 local iteration = 0

*0 package.path = package.path .. ";../?.lua"
*0 while x*x + y*y <= 4 and iteration < max_iterations do
*0 local x_new = x*x - y*y + cx
*0 y = 2*x*y + cy
*0 x = x_new
*0 iteration = iteration + 1
end

-- Don't load some of the modules to prevent them from getting tested/executed
require "example-src.moduleA.libA"
require "example-src.third-module.lib-1"
require "example-src.third-module.lib-2"
*0 return iteration
end

local function draw_mandelbrot()
*0 for py = 0, height - 1 do
*0 local y = y_min + (y_max - y_min) * py / (height - 1)
*0 local line = ""

*0 for px = 0, width - 1 do
*0 local x = x_min + (x_max - x_min) * px / (width - 1)
*0 local iteration = mandelbrot(x, y)

*0 if iteration == max_iterations then
*0 line = line .. "#"
else
*0 local shade = math.floor((iteration / max_iterations) * 10)
*0 line = line .. string.sub(" .:-=+*#%@", shade + 1, shade + 1)
end
end

*0 print(line)
end
end

*0 draw_mandelbrot()

==============================================================================
test.lua
==============================================================================

-- Don't load some of the modules to prevent them from getting tested/executed
1 require "example-src.moduleA.libA"
1 require "example-src.third-module.lib-1"
1 require "example-src.third-module.lib-2"
1 require('bar')

==============================================================================
Summary
==============================================================================

File Hits Missed Coverage
-------------------------------------------------------
example-src/moduleA/libA.lua 1 0 100.00%
example-src/moduleA/libB.lua 0 1 0.00%
example-src/moduleB/aLib.lua 0 1 0.00%
example-src/moduleB/bLib.lua 0 1 0.00%
example-src/third-module/lib-1.lua 1 0 100.00%
example-src/third-module/lib-2.lua 1 0 100.00%
subdir/test.lua 0 1 0.00%
test.lua 3 0 100.00%
-------------------------------------------------------
Total 6 4 60.00%
File Hits Missed Coverage
----------------------------------------
bar.lua 1 0 100.00%
dir/foo.lua 0 43 0.00%
dir/moduleA/too.lua 0 25 0.00%
test.lua 1 0 100.00%
----------------------------------------
Total 2 68 2.86%
Loading