/ tests / frontend / set.sh
set.sh
  1  #! /usr/bin/env atf-sh
  2  
  3  . $(atf_get_srcdir)/test_environment.sh
  4  
  5  tests_init \
  6  	set_automatic \
  7  	set_change_name \
  8  	set_change_origin \
  9  	set_change_name_not_origin \
 10  	set_vital \
 11  	set_partial
 12  
 13  initialize_pkg() {
 14  
 15  	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg test test 1
 16  	sed -i'' -e 's#origin.*#origin: origin/test#' test.ucl
 17  
 18  	atf_check \
 19  		-o match:".*Installing.*\.\.\.$" \
 20  		-e empty \
 21  		-s exit:0 \
 22  		pkg register -t -M test.ucl
 23  }
 24  
 25  set_automatic_body() {
 26  	initialize_pkg
 27  
 28  	atf_check \
 29  		-o inline:"0\n" \
 30  		-e empty \
 31  		-s exit:0 \
 32  		pkg query "%a" test
 33  
 34  	atf_check \
 35  		-o empty \
 36  		-e empty \
 37  		-s exit:0 \
 38  		pkg set -y -A 1 test
 39  
 40  	atf_check \
 41  		-o inline:"1\n" \
 42  		-e empty \
 43  		-s exit:0 \
 44  		pkg query "%a" test
 45  
 46  	atf_check \
 47  		-o empty \
 48  		-e empty \
 49  		-s exit:0 \
 50  		pkg set -y -A 0 test
 51  
 52  	atf_check \
 53  		-o inline:"0\n" \
 54  		-e empty \
 55  		-s exit:0 \
 56  		pkg query "%a" test
 57  }
 58  
 59  set_change_name_body() {
 60  	initialize_pkg
 61  
 62  	atf_check \
 63  		-o empty \
 64  		-e empty \
 65  		-s exit:0 \
 66  		pkg set -yn test:new
 67  
 68  	atf_check \
 69  		-o inline:"new-1\n" \
 70  		-e empty \
 71  		-s exit:0 \
 72  		pkg info -q
 73  }
 74  
 75  set_change_origin_body() {
 76  	initialize_pkg
 77  
 78  	atf_check \
 79  		-o empty \
 80  		-e empty \
 81  		-s exit:0 \
 82  		pkg set -yo origin/test:neworigin/test
 83  
 84  	atf_check \
 85  		-o inline:"neworigin/test\n" \
 86  		-e empty \
 87  		-s exit:0 \
 88  		pkg info -qo
 89  }
 90  
 91  set_change_name_not_origin_body() {
 92  	initialize_pkg
 93  
 94  	# pkg set -n should match by name only, not by origin (issue #1187).
 95  	# "origin/test" contains a slash and matches the origin, but -n
 96  	# must not find the package through its origin and rename it.
 97  	atf_check \
 98  		-s exit:0 \
 99  		pkg set -yn origin/test:newname
100  
101  	# Verify the package name and origin are unchanged:
102  	# Before the fix, the name would become "newname" because -n
103  	# matched via origin instead of name.
104  	atf_check \
105  		-o inline:"test-1\n" \
106  		-e empty \
107  		-s exit:0 \
108  		pkg info -q
109  
110  	atf_check \
111  		-o inline:"origin/test\n" \
112  		-e empty \
113  		-s exit:0 \
114  		pkg info -qo
115  }
116  
117  set_vital_body() {
118  	initialize_pkg
119  
120  	atf_check \
121  		-o inline:"0\n" \
122  		-e empty \
123  		-s exit:0 \
124  		pkg query "%V" test
125  
126  	atf_check \
127  		-o empty \
128  		-e empty \
129  		-s exit:0 \
130  		pkg set -y -v 1 test
131  
132  	atf_check \
133  		-o inline:"1\n" \
134  		-e empty \
135  		-s exit:0 \
136  		pkg query "%V" test
137  
138  	atf_check \
139  		-o empty \
140  		-e empty \
141  		-s exit:0 \
142  		pkg set -y -v 0 test
143  
144  	atf_check \
145  		-o inline:"0\n" \
146  		-e empty \
147  		-s exit:0 \
148  		pkg query "%V" test
149  }
150  
151  set_partial_body() {
152  	initialize_pkg
153  
154  	rm test.ucl
155  	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkgf test plop-test origin/plop-test 1 /prefix
156  
157  	atf_check \
158  		-o match:".*Installing.*\.\.\.$" \
159  		-e empty \
160  		-s exit:0 \
161  		pkg register -t -M test.ucl
162  
163  	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkgf test plop-foo origin/plop-foo 1 /prefix
164  
165  	atf_check \
166  		-o match:".*Installing.*\.\.\.$" \
167  		-e empty \
168  		-s exit:0 \
169  		pkg register -t -M test.ucl
170  
171  	atf_check \
172  		-o inline:"plop-foo-1\nplop-test-1\ntest-1\n" \
173  		-e empty \
174  		-s exit:0 \
175  		pkg info -q
176  
177  	atf_check \
178  		-o inline:"2 packages have been renamed.\n" \
179  		-e empty \
180  		-s exit:0 \
181  		pkg set -ypn test:bla
182  
183  	atf_check \
184  		-o inline:"bla-1\nplop-bla-1\nplop-foo-1\n" \
185  		-e empty \
186  		-s exit:0 \
187  		pkg info -q
188  
189  	atf_check \
190  		-o inline:"2 packages have been renamed.\n" \
191  		-e empty \
192  		-s exit:0 \
193  		pkg set -ypn bla:test
194  
195  	atf_check \
196  		-o inline:"plop-foo-1\nplop-test-1\ntest-1\n" \
197  		-e empty \
198  		-s exit:0 \
199  		pkg info -q
200  
201  	atf_check \
202  		-o inline:"origin/plop-foo\norigin/plop-test\norigin/test\n" \
203  		-e empty \
204  		-s exit:0 \
205  		pkg info -qo
206  
207  	atf_check \
208  		-o inline:"2 packages have been renamed.\n" \
209  		-e empty \
210  		-s exit:0 \
211  		pkg set -ypo test:bla
212  
213  	atf_check \
214  		-o inline:"origin/plop-foo\norigin/plop-bla\norigin/bla\n" \
215  		-e empty \
216  		-s exit:0 \
217  		pkg info -qo
218  
219  }