6 include Test
::Unit::Assertions
8 # Force UTF-8. Ruby will default to the system locale, and if it is
9 # non-UTF-8, String-methods will fail when operating on non-ASCII
11 Encoding
.default_external
= Encoding
::UTF_8
12 Encoding
.default_internal
= Encoding
::UTF_8
14 GIT_DIR
=`git rev-parse --show-toplevel`
17 "Failed to find Tails' Git root; this command must be run " +
18 "inside Tails Git repo"
21 def rfc2822_date
?(date
)
22 !!DateTime
.rfc2822(date
)
27 def page_meta_date_is_ok
?(path
)
28 meta_date_post_re
= /^\[\[!meta\s+date="(?<date>.*)"\]\]$/
30 content_lines
= File
.new(path
).read
.split("\n")
31 matches
= content_lines
.grep(meta_date_post_re
)
33 STDERR.puts
"#{path}: has #{matches.size} well-formed 'meta date' " +
34 "directives (must be 1)"
37 meta_date_line
= matches
.first
38 m
= meta_date_post_re
.match(meta_date_line
)
40 if not(rfc2822_date
?(meta_date
))
41 STDERR.puts
"#{path}: 'meta date' directive contains non-rfc2822 " +
49 def po_file_meta_date_is_ok
?(path
)
50 meta_date_po_re_str
= '\[\[!meta\s+date=\\\"(?<date>.*)\\\"\]\]\\\n'
52 content_lines
= File
.new(path
).read
.split("\n")
53 matches
= content_lines
.grep(Regexp
.new("^msgid \"#{meta_date_po_re_str}\"$"))
55 STDERR.puts
"#{path}: has #{matches.size} 'meta date' msgid:s (must be 1)"
59 msgid_index
= content_lines
.find_index(msgid
)
60 msgstr_index
= msgid_index
+ 1
61 msgstr_line
= content_lines
[msgstr_index
]
62 m
= Regexp
.new("^msgstr \"(?:#{meta_date_po_re_str})?\"$").match(msgstr_line
)
64 STDERR.puts
"#{path}: the 'meta date' msgid is not followed by a msgstr"
68 if not(rfc2822_date
?(meta_date
))
69 STDERR.puts
"#{path}: 'meta date' msgstr contains non-rfc2822 " +
82 meta_date_sorted_pages
=
83 Dir
.glob('wiki/src/{news,security,security/audits}/*.{mdwn,html}') - [
84 'wiki/src/security/audits.mdwn',
87 meta_date_sorted_pages
.each
do |post_path
|
88 success
= false unless page_meta_date_is_ok
?(post_path
)
89 Dir
.glob(post_path
.sub(/.(html|mdwn)$/, '') + '.*.po').each
do |po_path
|
90 success
= false unless po_file_meta_date_is_ok
?(po_path
)