Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
U
updater
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Michal Čihař
updater
Commits
178fda03
Verified
Commit
178fda03
authored
Feb 29, 2016
by
Michal 'vorner' Vaner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pkg: Formatting of package status
Functions to format the status block for a single package.
parent
27168a64
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
154 additions
and
0 deletions
+154
-0
src/lib/autoload/a_05_backend.lua
src/lib/autoload/a_05_backend.lua
+63
-0
tests/backend.lua
tests/backend.lua
+91
-0
No files found.
src/lib/autoload/a_05_backend.lua
View file @
178fda03
...
...
@@ -95,6 +95,69 @@ function block_parse(block)
return
result
end
--[[
Format single block of data.
The block shall be passed as an array, each item an object with header and value strings.
The object may be an empty table. In that case, no output is generated for the given
object.
]]
function
block_dump_ordered
(
block
)
return
table.concat
(
utils
.
map
(
block
,
function
(
i
,
line
)
if
line
.
header
then
local
space
=
' '
if
line
.
value
:
match
(
"^%s"
)
then
space
=
''
end
return
i
,
line
.
header
..
":"
..
space
..
line
.
value
..
"
\n
"
else
return
i
,
''
end
end
))
end
--[[
Dump status of a single package.
]]
function
pkg_status_dump
(
status
)
local
function
line
(
name
,
conversion
)
if
status
[
name
]
then
return
{
header
=
name
,
value
=
conversion
(
status
[
name
])}
else
return
{}
end
end
local
function
raw
(
name
)
return
line
(
name
,
function
(
v
)
return
v
end
)
end
return
block_dump_ordered
({
raw
"Package"
,
raw
"Version"
,
line
(
"Depends"
,
function
(
deps
)
-- Join the dependencies together, separated by commas
return
table.concat
(
deps
,
', '
)
end
),
raw
"Conflicts"
,
line
(
"Status"
,
function
(
status
)
-- Join status flags together, separated by spaces
return
table.concat
(
utils
.
set2arr
(
status
),
' '
)
end
),
raw
"Architecture"
,
line
(
"Conffiles"
,
function
(
confs
)
local
i
=
0
--[[
For each dep, place it into an array instead of map and format the line.
Then connect these lines together with newlines.
]]
return
"
\n
"
..
table.concat
(
utils
.
map
(
confs
,
function
(
filename
,
hash
)
i
=
i
+
1
return
i
,
" "
..
filename
..
" "
..
hash
end
),
"
\n
"
)
end
),
raw
"Installed-Time"
,
raw
"Auto-Installed"
})
end
--[[
Split text into blocks separated by at least one empty line.
Returns an iterator.
...
...
tests/backend.lua
View file @
178fda03
...
...
@@ -423,6 +423,97 @@ function test_collisions()
},
rem
)
end
function
test_block_dump_ordered
()
-- Empty block should produce empty output
assert_equal
(
''
,
B
.
block_dump_ordered
({}))
-- An ordinary block, nothing special
assert_equal
(
[[
Header: value
Header2: value2
]]
,
B
.
block_dump_ordered
({
{
header
=
"Header"
,
value
=
"value"
},
{
header
=
"Header2"
,
value
=
"value2"
}
}))
-- Repeated headers. Not that we would actually need that in practice.
assert_equal
(
[[
Header: value
Header: value
]]
,
B
.
block_dump_ordered
({
{
header
=
"Header"
,
value
=
"value"
},
{
header
=
"Header"
,
value
=
"value"
}
}))
-- An empty object generates nothing
assert_equal
(
[[
Header: value
Header: value
]]
,
B
.
block_dump_ordered
({
{
header
=
"Header"
,
value
=
"value"
},
{},
{
header
=
"Header"
,
value
=
"value"
}
}))
-- A multi-line value
assert_equal
(
[[
Header:
value
another line
]]
,
B
.
block_dump_ordered
({
{
header
=
"Header"
,
value
=
-- Since lua eats the first newline directly after [[, we need to provide two.
[[
value
another line]]
}}))
end
function
test_pkg_status_dump
()
-- Simple package with just one-line headers
assert_equal
(
[[
Package: pkg-name
Version: 1
Installed-Time: 1
]]
,
B
.
pkg_status_dump
({
Package
=
"pkg-name"
,
Version
=
"1"
,
[
"Installed-Time"
]
=
"1"
}))
-- Package with some extra (unused) headers
assert_equal
(
[[
Package: pkg-name
Version: 1
Installed-Time: 1
]]
,
B
.
pkg_status_dump
({
Package
=
"pkg-name"
,
Version
=
"1"
,
[
"Installed-Time"
]
=
"1"
,
Extra
=
"xxxx"
}))
-- Package with more complex headers
assert_equal
(
[[
Package: pkg-name
Version: 1
Depends: dep1, dep2
Status: flag
Conffiles:
file 1234567890123456
Installed-Time: 1
]]
,
B
.
pkg_status_dump
({
Package
=
"pkg-name"
,
Version
=
"1"
,
[
"Installed-Time"
]
=
"1"
,
Extra
=
"xxxx"
,
Depends
=
{
"dep1"
,
"dep2"
},
Status
=
{
flag
=
true
},
Conffiles
=
{
[
"file"
]
=
"1234567890123456"
}
}))
end
function
setup
()
local
sdir
=
os.getenv
(
"S"
)
or
"."
-- Use a shortened version of a real status file for tests
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment