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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
#
# Copyright (c) 2016 D. Richard Hipp
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the Simplified BSD License (also
# known as the "2-Clause License" or "FreeBSD License".)
#
# This program is distributed in the hope that it will be useful,
# but without any warranty; without even the implied warranty of
# merchantability or fitness for a particular purpose.
#
# Author contact information:
# drh@hwaci.com
# http://www.hwaci.com/drh/
#
############################################################################
#
# The "settings" and "unset" commands.
#
set path [file dirname [info script]]; test_setup
###############################################################################
#
# Complete syntax as tested:
#
# fossil settings ?PROPERTY? ?VALUE? ?OPTIONS?
# fossil unset PROPERTY ?OPTIONS?
#
# Where the only supported options are "--global" and "--exact".
#
###############################################################################
#
# NOTE: The [get_all_settings] procedure from test/tester.tcl returns the list
# of settings to test and needs to be manually updated when new settings
# are added.
#
###############################################################################
#
# NOTE: The [extract_setting_names] procedure extracts the list of setting
# names from the line-ending normalized output of the "fossil settings"
# command. It assumes that a setting name must begin with a lowercase
# letter. It also assumes that any output lines that start with a
# lowercase letter contain a setting name starting at that same point.
#
proc extract_setting_names { data } {
set names [list]
foreach {dummy name} [regexp \
-all -line -inline -- {^([a-z][a-z0-9\-]*) ?.*$} $data] {
lappend names $name
}
return $names
}
###############################################################################
set all_settings [get_all_settings]
fossil settings
set local_settings [extract_setting_names [normalize_result_no_trim]]
fossil settings --global
set global_settings [extract_setting_names [normalize_result_no_trim]]
foreach name $all_settings {
test settings-have-local-$name {
[lsearch -exact $local_settings $name] != -1
}
test settings-have-global-$name {
[lsearch -exact $global_settings $name] != -1
}
}
foreach name $local_settings {
test settings-valid-local-$name {
[lsearch -exact $all_settings $name] != -1
}
}
foreach name $global_settings {
test settings-valid-global-$name {
[lsearch -exact $all_settings $name] != -1
}
}
###############################################################################
set pattern(1) {^%name%$}
set pattern(2) {^%name%[ ]+\((?:local|global)\)[ ]+[^ ]+$}
foreach name $all_settings {
fossil settings $name --exact
set data [normalize_result]
test settings-query-local-$name {
[regexp -- [string map [list %name% $name] $pattern(1)] $data] ||
[regexp -- [string map [list %name% $name] $pattern(2)] $data]
}
if {$name eq "manifest"} {
fossil settings $name --exact --global -expectError
} else {
fossil settings $name --exact --global
}
set data [normalize_result]
if {$name eq "manifest"} {
test settings-query-global-$name {
$data eq "cannot set 'manifest' globally"
}
} else {
test settings-query-global-$name {
[regexp -- [string map [list %name% $name] $pattern(1)] $data] ||
[regexp -- [string map [list %name% $name] $pattern(2)] $data]
}
}
}
###############################################################################
fossil settings bad-setting -expectError
test settings-query-bad-local {
[normalize_result] eq "no such setting: bad-setting"
}
fossil settings bad-setting --global -expectError
test settings-query-bad-global {
[normalize_result] eq "no such setting: bad-setting"
}
###############################################################################
test_cleanup
|