Remove obsolete TODO.
[tails.git] / features / support / env.rb
blobe3f039b421f3d8bc217892e560e834059da0bdaa
1 require 'rubygems'
2 require "#{Dir.pwd}/features/support/extra_hooks.rb"
3 require 'time'
4 require 'rspec'
6 # Force UTF-8. Ruby will default to the system locale, and if it is
7 # non-UTF-8, String-methods will fail when operating on non-ASCII
8 # strings.
9 Encoding.default_external = Encoding::UTF_8
10 Encoding.default_internal = Encoding::UTF_8
12 def fatal_system(str)
13   unless system(str)
14     raise StandardError.new("Command exited with #{$?}")
15   end
16 end
18 def git_exists?
19   File.exists? '.git'
20 end
22 def create_git
23   Dir.mkdir 'config'
24   FileUtils.touch('config/base_branch')
25   Dir.mkdir('config/APT_overlays.d')
26   Dir.mkdir('config/APT_snapshots.d')
27   ['debian', 'debian-security', 'torproject'].map do |origin|
28     Dir.mkdir("config/APT_snapshots.d/#{origin}")
29   end
30   Dir.mkdir 'debian'
31   File.open('debian/changelog', 'w') do |changelog|
32     changelog.write(<<END_OF_CHANGELOG)
33 tails (0) stable; urgency=low
35   * First release.
37  -- Tails developers <tails@boum.org>  Mon, 30 Jan 2012 01:00:00 +0000
38 END_OF_CHANGELOG
39   end
41   fatal_system "git init --quiet"
42   fatal_system "git config user.email 'tails@boum.org'"
43   fatal_system "git config user.name 'Tails developers'"
44   fatal_system "git add debian/changelog"
45   fatal_system "git commit --quiet debian/changelog -m 'First release'"
46   fatal_system "git branch -M stable"
47   fatal_system "git branch testing stable"
48   fatal_system "git branch devel stable"
49   fatal_system "git branch feature/jessie devel"
50 end
52 def current_branch
53   cmd = 'git rev-parse --symbolic-full-name --abbrev-ref HEAD'.split
54   branch = cmd_helper(cmd).strip
55   assert_not_equal("HEAD", branch, "We are in 'detached HEAD' state")
56   return branch
57 end
59 # In order: if git HEAD is tagged, return its name; if a branch is
60 # checked out, return its name; otherwise we are in 'detached HEAD'
61 # state, and we return the empty string.
62 def describe_git_head
63   cmd_helper("git describe --tags --exact-match #{current_commit}".split).strip
64 rescue Test::Unit::AssertionFailedError
65   begin
66     current_branch
67   rescue Test::Unit::AssertionFailedError
68     ""
69   end
70 end
72 def current_commit
73   cmd_helper('git rev-parse HEAD'.split).strip
74 end
76 def current_short_commit
77   current_commit[0, 7]
78 end
80 RSpec::Matchers.define :have_suite do |suite|
81   match do |string|
82     # e.g.: `deb http://deb.tails.boum.org/ 0.10 main contrib non-free`
83     %r{^deb +http://deb\.tails\.boum\.org/ +#{Regexp.escape(suite)} main}.match(string)
84   end
85   failure_message_for_should do |string|
86     "expected the sources to include #{suite}\nCurrent sources : #{string}"
87   end
88   failure_message_for_should_not do |string|
89     "expected the sources to exclude #{suite}\nCurrent sources : #{string}"
90   end
91   description do
92     "expected an output with #{suite}"
93   end
94 end
96 RSpec::Matchers.define :have_tagged_snapshot do |tag|
97   match do |string|
98     # e.g.: `http://tagged.snapshots.deb.tails.boum.org/0.10`
99     %r{^http://tagged\.snapshots\.deb\.tails\.boum\.org/#{Regexp.escape(tag)}/[a-z-]+$}.match(string)
100   end
101   failure_message_for_should do |string|
102     "expected the mirror to be #{tag}\nCurrent mirror: #{string}"
103   end
104   failure_message_for_should_not do |string|
105     "expected the mirror not to be #{tag}\nCurrent mirror: #{string}"
106   end
107   description do
108     "expected an output with #{tag}"
109   end
112 RSpec::Matchers.define :have_time_based_snapshot do |tag|
113   match do |string|
114     # e.g.: `http://time-based.snapshots.deb.tails.boum.org/debian/2016060602`
115     %r{^http://time\-based\.snapshots\.deb\.tails\.boum\.org/[^/]+/\d+}.match(string)
116   end
117   failure_message_for_should do |string|
118     "expected the mirror to be a time-based snapshot\nCurrent mirror: #{string}"
119   end
120   failure_message_for_should_not do |string|
121     "expected the mirror not to be a time-based snapshot\nCurrent mirror: #{string}"
122   end
123   description do
124     "expected a time-based snapshot"
125   end