|
1
|
# |
|
2
|
# Copyright (c) 2016 D. Richard Hipp |
|
3
|
# |
|
4
|
# This program is free software; you can redistribute it and/or |
|
5
|
# modify it under the terms of the Simplified BSD License (also |
|
6
|
# known as the "2-Clause License" or "FreeBSD License".) |
|
7
|
# |
|
8
|
# This program is distributed in the hope that it will be useful, |
|
9
|
# but without any warranty; without even the implied warranty of |
|
10
|
# merchantability or fitness for a particular purpose. |
|
11
|
# |
|
12
|
# Author contact information: |
|
13
|
# [email protected] |
|
14
|
# http://www.hwaci.com/drh/ |
|
15
|
# |
|
16
|
############################################################################ |
|
17
|
# |
|
18
|
# The "settings" and "unset" commands. |
|
19
|
# |
|
20
|
|
|
21
|
set path [file dirname [info script]]; test_setup |
|
22
|
|
|
23
|
############################################################################### |
|
24
|
# |
|
25
|
# Complete syntax as tested: |
|
26
|
# |
|
27
|
# fossil settings ?PROPERTY? ?VALUE? ?OPTIONS? |
|
28
|
# fossil unset PROPERTY ?OPTIONS? |
|
29
|
# |
|
30
|
# Where the only supported options are "--global" and "--exact". |
|
31
|
# |
|
32
|
############################################################################### |
|
33
|
# |
|
34
|
# NOTE: The [get_all_settings] procedure from test/tester.tcl returns the list |
|
35
|
# of settings to test and needs to be manually updated when new settings |
|
36
|
# are added. |
|
37
|
# |
|
38
|
############################################################################### |
|
39
|
# |
|
40
|
# NOTE: The [extract_setting_names] procedure extracts the list of setting |
|
41
|
# names from the line-ending normalized output of the "fossil settings" |
|
42
|
# command. It assumes that a setting name must begin with a lowercase |
|
43
|
# letter. It also assumes that any output lines that start with a |
|
44
|
# lowercase letter contain a setting name starting at that same point. |
|
45
|
# |
|
46
|
proc extract_setting_names { data } { |
|
47
|
set names [list] |
|
48
|
|
|
49
|
foreach {dummy name} [regexp \ |
|
50
|
-all -line -inline -- {^([a-z][a-z0-9\-]*) ?.*$} $data] { |
|
51
|
lappend names $name |
|
52
|
} |
|
53
|
|
|
54
|
return $names |
|
55
|
} |
|
56
|
|
|
57
|
############################################################################### |
|
58
|
|
|
59
|
set all_settings [get_all_settings] |
|
60
|
|
|
61
|
fossil settings |
|
62
|
set local_settings [extract_setting_names [normalize_result_no_trim]] |
|
63
|
|
|
64
|
fossil settings --global |
|
65
|
set global_settings [extract_setting_names [normalize_result_no_trim]] |
|
66
|
|
|
67
|
foreach name $all_settings { |
|
68
|
test settings-have-local-$name { |
|
69
|
[lsearch -exact $local_settings $name] != -1 |
|
70
|
} |
|
71
|
|
|
72
|
test settings-have-global-$name { |
|
73
|
[lsearch -exact $global_settings $name] != -1 |
|
74
|
} |
|
75
|
} |
|
76
|
|
|
77
|
foreach name $local_settings { |
|
78
|
test settings-valid-local-$name { |
|
79
|
[lsearch -exact $all_settings $name] != -1 |
|
80
|
} |
|
81
|
} |
|
82
|
|
|
83
|
foreach name $global_settings { |
|
84
|
test settings-valid-global-$name { |
|
85
|
[lsearch -exact $all_settings $name] != -1 |
|
86
|
} |
|
87
|
} |
|
88
|
|
|
89
|
############################################################################### |
|
90
|
|
|
91
|
set pattern(1) {^%name%$} |
|
92
|
set pattern(2) {^%name%[ ]+\((?:local|global)\)[ ]+[^ ]+$} |
|
93
|
|
|
94
|
foreach name $all_settings { |
|
95
|
fossil settings $name --exact |
|
96
|
set data [normalize_result] |
|
97
|
|
|
98
|
test settings-query-local-$name { |
|
99
|
[regexp -- [string map [list %name% $name] $pattern(1)] $data] || |
|
100
|
[regexp -- [string map [list %name% $name] $pattern(2)] $data] |
|
101
|
} |
|
102
|
|
|
103
|
if {$name eq "manifest"} { |
|
104
|
fossil settings $name --exact --global -expectError |
|
105
|
} else { |
|
106
|
fossil settings $name --exact --global |
|
107
|
} |
|
108
|
set data [normalize_result] |
|
109
|
|
|
110
|
if {$name eq "manifest"} { |
|
111
|
test settings-query-global-$name { |
|
112
|
$data eq "cannot set 'manifest' globally" |
|
113
|
} |
|
114
|
} else { |
|
115
|
test settings-query-global-$name { |
|
116
|
[regexp -- [string map [list %name% $name] $pattern(1)] $data] || |
|
117
|
[regexp -- [string map [list %name% $name] $pattern(2)] $data] |
|
118
|
} |
|
119
|
} |
|
120
|
} |
|
121
|
|
|
122
|
############################################################################### |
|
123
|
|
|
124
|
fossil settings bad-setting -expectError |
|
125
|
|
|
126
|
test settings-query-bad-local { |
|
127
|
[normalize_result] eq "no such setting: bad-setting" |
|
128
|
} |
|
129
|
|
|
130
|
fossil settings bad-setting --global -expectError |
|
131
|
|
|
132
|
test settings-query-bad-global { |
|
133
|
[normalize_result] eq "no such setting: bad-setting" |
|
134
|
} |
|
135
|
|
|
136
|
############################################################################### |
|
137
|
|
|
138
|
test_cleanup |
|
139
|
|