forked from rust-embedded/rust-raspberrypi-OS-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.rb
82 lines (65 loc) · 1.71 KB
/
test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# frozen_string_literal: true
# SPDX-License-Identifier: MIT OR Apache-2.0
#
# Copyright (c) 2019-2023 Andre Richter <andre.o.richter@gmail.com>
# Test base class.
class Test
INDENT = ' '
def initialize
# Template instance variables.
# @test_name
# @test_description
# @test_output
# @test_error
end
private
def print_border(content)
puts "#{INDENT}-------------------------------------------------------------------"
puts content
puts "#{INDENT}-------------------------------------------------------------------"
end
def print_header
print_border("#{INDENT}🦀 #{@test_description}")
puts
end
def print_footer_error(error)
puts
print_border("#{INDENT}❌ Failure: #{@test_name}: #{error}")
puts
puts
end
def print_footer_success
puts
print_border("#{INDENT}✅ Success: #{@test_name}")
puts
puts
end
# Expects @test_output the be an array of lines, without '\n'
def print_output
@test_output.each { |x| print "#{INDENT}#{x}\n" }
end
# Template method.
def setup; end
# Template method.
def finish; end
# Template method.
def run_concrete_test
raise('Not implemented')
end
public
def run
setup
run_concrete_test
finish
print_header
print_output
exit_code = if @test_error
print_footer_error(@test_error)
false
else
print_footer_success
true
end
exit(exit_code)
end
end