#!/bin/bash # Copyright 2015 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Unit tests for pkg_deb and pkg_tar global DIR := $[cd $[dirname $(BASH_SOURCE[0])] && pwd] source $(DIR)/testenv.sh || do { echo "testenv.sh not found!" > !2; exit 1; } proc get_tar_listing { var input = $1 var test_data = ""$(TEST_DATA_DIR)/$(input)"" tar tvf $(test_data) | sed -e 's/^.*:00 //' } proc get_tar_permission { var input = $1 var file = $2 var test_data = ""$(TEST_DATA_DIR)/$(input)"" tar tvf $(test_data) | fgrep "00 $file" | cut -d " " -f 1 } proc get_deb_listing { var input = $1 var test_data = ""$(TEST_DATA_DIR)/$(input)"" dpkg-deb -c $(test_data) | sed -e 's/^.*:00 //' } proc get_deb_description { var input = $1 var test_data = ""$(TEST_DATA_DIR)/$(input)"" dpkg-deb -I $(test_data) } proc get_deb_permission { var input = $1 var file = $2 var test_data = ""$(TEST_DATA_DIR)/$(input)"" dpkg-deb -c $(test_data) | fgrep "00 $file" | cut -d " " -f 1 } proc get_deb_ctl_file { var input = $1 var file = $2 var test_data = ""$(TEST_DATA_DIR)/$(input)"" dpkg-deb -I $(test_data) $(file) } proc get_deb_ctl_listing { var input = $1 var test_data = ""$(TEST_DATA_DIR)/$(input)"" dpkg-deb --ctrl-tarfile $(test_data) | tar tf - | sort } proc get_deb_ctl_permission { var input = $1 var file = $2 var test_data = ""$(TEST_DATA_DIR)/$(input)"" dpkg-deb --ctrl-tarfile $(test_data) | tar tvf - | egrep " $file\$" | cut -d " " -f 1 } proc dpkg_deb_supports_ctrl_tarfile { var input = $1 var test_data = ""$(TEST_DATA_DIR)/$(input)"" dpkg-deb --ctrl-tarfile $(test_data) > /dev/null !2 > /dev/null } proc get_changes { var input = $1 cat "$(TEST_DATA_DIR)/$(input)" } proc test_tar { var listing = '"./ ./etc/ ./etc/nsswitch.conf ./usr/ ./usr/titi ./usr/bin/ ./usr/bin/java -> /path/to/bin/java'" for i in ["" ".gz" ".bz2" ".xz]" { check_eq $listing $[get_tar_listing test-tar-$(i:1).tar$i] check_eq "-rwxr-xr-x" $[get_tar_permission test-tar-$(i:1).tar$i ./usr/titi] check_eq "-rw-r--r--" $[get_tar_permission test-tar-$(i:1).tar$i ./etc/nsswitch.conf] # Test merging tar files check_eq $listing $[get_tar_listing test-tar-inclusion-$(i:1).tar] check_eq "-rwxr-xr-x" $[get_tar_permission test-tar-inclusion-$(i:1).tar ./usr/titi] check_eq "-rw-r--r--" $[get_tar_permission test-tar-inclusion-$(i:1).tar ./etc/nsswitch.conf] }; check_eq "./ ./nsswitch.conf" $[get_tar_listing test-tar-strip_prefix-empty.tar] check_eq "./ ./nsswitch.conf" $[get_tar_listing test-tar-strip_prefix-none.tar] check_eq "./ ./nsswitch.conf" $[get_tar_listing test-tar-strip_prefix-etc.tar] check_eq "./ ./etc/ ./etc/nsswitch.conf" $[get_tar_listing test-tar-strip_prefix-dot.tar] } proc test_deb { if ! shell {which dpkg-deb} { echo "Unable to run test for debian, no dpkg-deb!" > !2 return 0 } var listing = '"./ ./etc/ ./etc/nsswitch.conf ./usr/ ./usr/titi ./usr/bin/ ./usr/bin/java -> /path/to/bin/java'" check_eq $listing $[get_deb_listing test-deb.deb] check_eq "-rwxr-xr-x" $[get_deb_permission test-deb.deb ./usr/titi] check_eq "-rw-r--r--" $[get_deb_permission test-deb.deb ./etc/nsswitch.conf] get_deb_description test-deb.deb >$TEST_log expect_log "Description: toto" expect_log "Package: titi" expect_log "Depends: dep1, dep2" get_changes titi_test_all.changes >$TEST_log expect_log "Urgency: low" expect_log "Distribution: trusty" if ! dpkg_deb_supports_ctrl_tarfile test-deb.deb { echo "Unable to test deb control files, too old dpkg-deb!" > !2 return 0 } var ctrl_listing = '"conffiles control'" check_eq $ctrl_listing $[get_deb_ctl_listing test-deb.deb] check_eq "-rw-r--r--" $[get_deb_ctl_permission test-deb.deb conffiles] check_eq "-rw-r--r--" $[get_deb_ctl_permission test-deb.deb control] var conffiles = '"/etc/nsswitch.conf /etc/other'" check_eq $conffiles $[get_deb_ctl_file test-deb.deb conffiles] } run_suite "build_test" (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:DIR) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (AndOr children: [ (C {(cd)} { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(dirname)} { (DQ (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w:{(Lit_Digits 0)}) ) spids: [57 62] ) ) } ) ] ) left_token: spids: [53 64] ) ) } ) (C {(pwd)}) ] op_id: Op_DAmp ) ] ) left_token: spids: [49 70] ) } spids: [48] ) ] spids: [48] ) (AndOr children: [ (C {(source)} {(${ VSub_Name DIR) (/testenv.sh)}) (BraceGroup children: [ (Sentence child: (SimpleCommand words: [{(echo)} {(DQ ("testenv.sh not found!"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[89])] ) terminator: ) (Sentence child:(C {(exit)} {(1)}) terminator:) ] spids: [81] ) ] op_id: Op_DPipe ) (FuncDef name: get_tar_listing body: (BraceGroup children: [ (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:input) op: Equal rhs: {($ VSub_Number "$1")} spids: [112] ) ] spids: [110] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:test_data) op: Equal rhs: {(DQ (${ VSub_Name TEST_DATA_DIR) (/) (${ VSub_Name input))} spids: [118] ) ] spids: [116] ) (Pipeline children: [ (C {(tar)} {(tvf)} {(DQ (${ VSub_Name test_data))}) (C {(sed)} {(-e)} {(SQ <"s/^.*:00 //">)}) ] negated: False ) ] spids: [107] ) spids: [101 106] ) (FuncDef name: get_tar_permission body: (BraceGroup children: [ (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:input) op: Equal rhs: {($ VSub_Number "$1")} spids: [164] ) ] spids: [162] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:file) op: Equal rhs: {($ VSub_Number "$2")} spids: [170] ) ] spids: [168] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:test_data) op: Equal rhs: {(DQ (${ VSub_Name TEST_DATA_DIR) (/) (${ VSub_Name input))} spids: [176] ) ] spids: [174] ) (Pipeline children: [ (C {(tar)} {(tvf)} {(DQ (${ VSub_Name test_data))}) (C {(fgrep)} {(DQ ("00 ") ($ VSub_Name "$file"))}) (C {(cut)} {(-d)} {(DQ (" "))} {(-f)} {(1)}) ] negated: False ) ] spids: [159] ) spids: [153 158] ) (FuncDef name: get_deb_listing body: (BraceGroup children: [ (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:input) op: Equal rhs: {($ VSub_Number "$1")} spids: [235] ) ] spids: [233] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:test_data) op: Equal rhs: {(DQ (${ VSub_Name TEST_DATA_DIR) (/) (${ VSub_Name input))} spids: [241] ) ] spids: [239] ) (Pipeline children: [ (C {(dpkg-deb)} {(-c)} {(DQ (${ VSub_Name test_data))}) (C {(sed)} {(-e)} {(SQ <"s/^.*:00 //">)}) ] negated: False ) ] spids: [230] ) spids: [224 229] ) (FuncDef name: get_deb_description body: (BraceGroup children: [ (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:input) op: Equal rhs: {($ VSub_Number "$1")} spids: [287] ) ] spids: [285] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:test_data) op: Equal rhs: {(DQ (${ VSub_Name TEST_DATA_DIR) (/) (${ VSub_Name input))} spids: [293] ) ] spids: [291] ) (C {(dpkg-deb)} {(-I)} {(DQ (${ VSub_Name test_data))}) ] spids: [282] ) spids: [276 281] ) (FuncDef name: get_deb_permission body: (BraceGroup children: [ (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:input) op: Equal rhs: {($ VSub_Number "$1")} spids: [329] ) ] spids: [327] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:file) op: Equal rhs: {($ VSub_Number "$2")} spids: [335] ) ] spids: [333] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:test_data) op: Equal rhs: {(DQ (${ VSub_Name TEST_DATA_DIR) (/) (${ VSub_Name input))} spids: [341] ) ] spids: [339] ) (Pipeline children: [ (C {(dpkg-deb)} {(-c)} {(DQ (${ VSub_Name test_data))}) (C {(fgrep)} {(DQ ("00 ") ($ VSub_Name "$file"))}) (C {(cut)} {(-d)} {(DQ (" "))} {(-f)} {(1)}) ] negated: False ) ] spids: [324] ) spids: [318 323] ) (FuncDef name: get_deb_ctl_file body: (BraceGroup children: [ (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:input) op: Equal rhs: {($ VSub_Number "$1")} spids: [400] ) ] spids: [398] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:file) op: Equal rhs: {($ VSub_Number "$2")} spids: [406] ) ] spids: [404] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:test_data) op: Equal rhs: {(DQ (${ VSub_Name TEST_DATA_DIR) (/) (${ VSub_Name input))} spids: [412] ) ] spids: [410] ) (C {(dpkg-deb)} {(-I)} {(DQ (${ VSub_Name test_data))} {(DQ (${ VSub_Name file))}) ] spids: [395] ) spids: [389 394] ) (FuncDef name: get_deb_ctl_listing body: (BraceGroup children: [ (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:input) op: Equal rhs: {($ VSub_Number "$1")} spids: [454] ) ] spids: [452] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:test_data) op: Equal rhs: {(DQ (${ VSub_Name TEST_DATA_DIR) (/) (${ VSub_Name input))} spids: [460] ) ] spids: [458] ) (Pipeline children: [ (C {(dpkg-deb)} {(--ctrl-tarfile)} {(DQ (${ VSub_Name test_data))}) (C {(tar)} {(tf)} {(-)}) (C {(sort)}) ] negated: False ) ] spids: [449] ) spids: [443 448] ) (FuncDef name: get_deb_ctl_permission body: (BraceGroup children: [ (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:input) op: Equal rhs: {($ VSub_Number "$1")} spids: [508] ) ] spids: [506] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:file) op: Equal rhs: {($ VSub_Number "$2")} spids: [514] ) ] spids: [512] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:test_data) op: Equal rhs: {(DQ (${ VSub_Name TEST_DATA_DIR) (/) (${ VSub_Name input))} spids: [520] ) ] spids: [518] ) (Pipeline children: [ (C {(dpkg-deb)} {(--ctrl-tarfile)} {(DQ (${ VSub_Name test_data))}) (C {(tar)} {(tvf)} {(-)}) (C {(egrep)} { (DQ (" ") ($ VSub_Name "$file") (EscapedLiteralPart token:)) } ) (C {(cut)} {(-d)} {(DQ (" "))} {(-f)} {(1)}) ] negated: False ) ] spids: [503] ) spids: [497 502] ) (FuncDef name: dpkg_deb_supports_ctrl_tarfile body: (BraceGroup children: [ (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:input) op: Equal rhs: {($ VSub_Number "$1")} spids: [588] ) ] spids: [586] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:test_data) op: Equal rhs: {(DQ (${ VSub_Name TEST_DATA_DIR) (/) (${ VSub_Name input))} spids: [594] ) ] spids: [592] ) (SimpleCommand words: [{(dpkg-deb)} {(--ctrl-tarfile)} {(DQ (${ VSub_Name test_data))}] redirects: [ (Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[616]) (Redir op_id:Redir_Great fd:2 arg_word:{(/dev/null)} spids:[620]) ] ) ] spids: [583] ) spids: [577 582] ) (FuncDef name: get_changes body: (BraceGroup children: [ (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:input) op: Equal rhs: {($ VSub_Number "$1")} spids: [638] ) ] spids: [636] ) (C {(cat)} {(DQ (${ VSub_Name TEST_DATA_DIR) (/) (${ VSub_Name input))}) ] spids: [633] ) spids: [627 632] ) (FuncDef name: test_tar body: (BraceGroup children: [ (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:listing) op: Equal rhs: { (DQ ("./\n") ("./etc/\n") ("./etc/nsswitch.conf\n") ("./usr/\n") ("./usr/titi\n") ("./usr/bin/\n") ("./usr/bin/java -> /path/to/bin/java") ) } spids: [668] ) ] spids: [666] ) (Sentence child: (ForEach iter_name: i iter_words: [{(DQ )} {(DQ (.gz))} {(DQ (.bz2))} {(DQ (.xz))}] do_arg_iter: False body: (DoGroup children: [ (C {(check_eq)} {(DQ ($ VSub_Name "$listing"))} { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(get_tar_listing)} {(test-tar-) (BracedVarSub token: suffix_op: (Slice begin:(ArithWord w:{(Lit_Digits 1)})) spids: [716 720] ) (.tar) ($ VSub_Name "$i") } ) ] ) left_token: spids: [712 723] ) ) } ) (C {(check_eq)} {(DQ (-rwxr-xr-x))} { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(get_tar_permission)} {(test-tar-) (BracedVarSub token: suffix_op: (Slice begin:(ArithWord w:{(Lit_Digits 1)})) spids: [738 742] ) (.tar) ($ VSub_Name "$i") } {(./usr/titi)} ) ] ) left_token: spids: [734 747] ) ) } ) (C {(check_eq)} {(DQ (-rw-r--r--))} { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(get_tar_permission)} {(test-tar-) (BracedVarSub token: suffix_op: (Slice begin:(ArithWord w:{(Lit_Digits 1)})) spids: [762 766] ) (.tar) ($ VSub_Name "$i") } {(./etc/nsswitch.conf)} ) ] ) left_token: spids: [758 771] ) ) } ) (C {(check_eq)} {(DQ ($ VSub_Name "$listing"))} { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(get_tar_listing)} {(test-tar-inclusion-) (BracedVarSub token: suffix_op: (Slice begin:(ArithWord w:{(Lit_Digits 1)})) spids: [790 794] ) (.tar) } ) ] ) left_token: spids: [786 796] ) ) } ) (C {(check_eq)} {(DQ (-rwxr-xr-x))} { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(get_tar_permission)} {(test-tar-inclusion-) (BracedVarSub token: suffix_op: (Slice begin:(ArithWord w:{(Lit_Digits 1)})) spids: [811 815] ) (.tar) } {(./usr/titi)} ) ] ) left_token: spids: [807 819] ) ) } ) (C {(check_eq)} {(DQ (-rw-r--r--))} { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(get_tar_permission)} {(test-tar-inclusion-) (BracedVarSub token: suffix_op: (Slice begin:(ArithWord w:{(Lit_Digits 1)})) spids: [834 838] ) (.tar) } {(./etc/nsswitch.conf)} ) ] ) left_token: spids: [830 842] ) ) } ) ] spids: [702 846] ) spids: [685 700] ) terminator: ) (C {(check_eq)} {(DQ ("./\n") (./nsswitch.conf))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(get_tar_listing)} {(test-tar-strip_prefix-empty.tar)})] ) left_token: spids: [859 863] ) ) } ) (C {(check_eq)} {(DQ ("./\n") (./nsswitch.conf))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(get_tar_listing)} {(test-tar-strip_prefix-none.tar)})] ) left_token: spids: [875 879] ) ) } ) (C {(check_eq)} {(DQ ("./\n") (./nsswitch.conf))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(get_tar_listing)} {(test-tar-strip_prefix-etc.tar)})] ) left_token: spids: [891 895] ) ) } ) (C {(check_eq)} {(DQ ("./\n") ("./etc/\n") (./etc/nsswitch.conf))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(get_tar_listing)} {(test-tar-strip_prefix-dot.tar)})] ) left_token: spids: [908 912] ) ) } ) ] spids: [663] ) spids: [657 662] ) (FuncDef name: test_deb body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (Pipeline children: [(Subshell child:(C {(which)} {(dpkg-deb)}) spids:[931935])] negated: True ) terminator: ) ] action: [ (SimpleCommand words: [{(echo)} {(DQ ("Unable to run test for debian, no dpkg-deb!"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[947])] ) (ControlFlow token: arg_word:{(0)}) ] spids: [-1 938] ) ] spids: [-1 956] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:listing) op: Equal rhs: { (DQ ("./\n") ("./etc/\n") ("./etc/nsswitch.conf\n") ("./usr/\n") ("./usr/titi\n") ("./usr/bin/\n") ("./usr/bin/java -> /path/to/bin/java") ) } spids: [961] ) ] spids: [959] ) (C {(check_eq)} {(DQ ($ VSub_Name "$listing"))} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(get_deb_listing)} {(test-deb.deb)})]) left_token: spids: [980 984] ) ) } ) (C {(check_eq)} {(DQ (-rwxr-xr-x))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(get_deb_permission)} {(test-deb.deb)} {(./usr/titi)})] ) left_token: spids: [995 1001] ) ) } ) (C {(check_eq)} {(DQ (-rw-r--r--))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(get_deb_permission)} {(test-deb.deb)} {(./etc/nsswitch.conf)})] ) left_token: spids: [1012 1018] ) ) } ) (SimpleCommand words: [{(get_deb_description)} {(test-deb.deb)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {($ VSub_Name "$TEST_log")} spids: [1026] ) ] ) (C {(expect_log)} {(DQ ("Description: toto"))}) (C {(expect_log)} {(DQ ("Package: titi"))}) (C {(expect_log)} {(DQ ("Depends: dep1, dep2"))}) (SimpleCommand words: [{(get_changes)} {(titi_test_all.changes)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {($ VSub_Name "$TEST_log")} spids: [1056] ) ] ) (C {(expect_log)} {(DQ ("Urgency: low"))}) (C {(expect_log)} {(DQ ("Distribution: trusty"))}) (If arms: [ (if_arm cond: [ (Sentence child: (Pipeline children: [(C {(dpkg_deb_supports_ctrl_tarfile)} {(test-deb.deb)})] negated: True ) terminator: ) ] action: [ (SimpleCommand words: [{(echo)} {(DQ ("Unable to test deb control files, too old dpkg-deb!"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[1094])] ) (ControlFlow token: arg_word:{(0)}) ] spids: [-1 1085] ) ] spids: [-1 1103] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:ctrl_listing) op: Equal rhs: {(DQ ("conffiles\n") (control))} spids: [1108] ) ] spids: [1106] ) (C {(check_eq)} {(DQ ($ VSub_Name "$ctrl_listing"))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(get_deb_ctl_listing)} {(test-deb.deb)})] ) left_token: spids: [1122 1126] ) ) } ) (C {(check_eq)} {(DQ (-rw-r--r--))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(get_deb_ctl_permission)} {(test-deb.deb)} {(conffiles)})] ) left_token: spids: [1137 1143] ) ) } ) (C {(check_eq)} {(DQ (-rw-r--r--))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(get_deb_ctl_permission)} {(test-deb.deb)} {(control)})] ) left_token: spids: [1154 1160] ) ) } ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:conffiles) op: Equal rhs: {(DQ ("/etc/nsswitch.conf\n") (/etc/other))} spids: [1166] ) ] spids: [1164] ) (C {(check_eq)} {(DQ ($ VSub_Name "$conffiles"))} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(get_deb_ctl_file)} {(test-deb.deb)} {(conffiles)})] ) left_token: spids: [1180 1186] ) ) } ) ] spids: [924] ) spids: [918 923] ) (C {(run_suite)} {(DQ (build_test))}) ] )