-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest.sh
More file actions
74 lines (63 loc) · 2.43 KB
/
test.sh
File metadata and controls
74 lines (63 loc) · 2.43 KB
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
#!/bin/bash
local file="$Ash__ACTIVE_MODULE_DIRECTORY/extra/example.yaml"
local prefix="YamlParse_output_"
eval $(YamlParse__parse "$file" "$prefix")
#################################################
# Test that basic keys work
#################################################
Yamlparse__test_keys(){
Yamlparse_test_expected "$YamlParse_output_one" "kittens"
if [[ $? -ne 0 ]]; then return 1; fi
Yamlparse_test_expected "$YamlParse_output_two" "puppies"
if [[ $? -ne 0 ]]; then return 1; fi
}
#################################################
# Test that nested keys are working
#################################################
Yamlparse__test_nested(){
Yamlparse_test_expected "$YamlParse_output_trees_evergreen" "so green"
if [[ $? -ne 0 ]]; then return 1; fi
Yamlparse_test_expected "$YamlParse_output_trees_maple" "so red"
if [[ $? -ne 0 ]]; then return 1; fi
}
#################################################
# Testing that doubly nested keys work. We're
# not going to test any further than this.
#################################################
Yamlparse__test_doubly_nested(){
Yamlparse_test_expected "$YamlParse_output_trees_maple_canadian" "canada"
if [[ $? -ne 0 ]]; then return 1; fi
Yamlparse_test_expected "$YamlParse_output_trees_maple_american" "america"
if [[ $? -ne 0 ]]; then return 1; fi
}
#################################################
# Tests that keys still are working, after putting
# them in a line after nested values
#################################################
Yamlparse__test_keys_after_nested(){
Yamlparse_test_expected "$YamlParse_output_three" "rats"
if [[ $? -ne 0 ]]; then return 1; fi
Yamlparse_test_expected "$YamlParse_output_four" "bats"
if [[ $? -ne 0 ]]; then return 1; fi
}
#################################################
# This is a helper function, and is not run
# directly by our test suite (note the single
# underscore).
#
# @param $1: The actual result
# @param $2: The expected result
# @returns $?: 1 if this test has failed,
# 0 if this test was successful. Also returns
# the error message to be returned in our tests.
#################################################
Yamlparse_test_expected(){
local actual_result="$1"
local expected_result="$2"
if [[ "$actual_result" != "$expected_result" ]]; then
echo "Expected '$expected_result', but got '$actual_result'"
return 1
else
return 0
fi
}