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# drh@hwaci.com 14# http://www.hwaci.com/drh/ 15# 16############################################################################ 17# 18# Test manifest setting 19# 20 21proc file_contains {fname match} { 22 set fp [open $fname r] 23 set contents [read $fp] 24 close $fp 25 set lines [split $contents "\n"] 26 foreach line $lines { 27 if {[regexp $match $line]} { 28 return 1 29 } 30 } 31 return 0 32} 33 34# We need SHA1 to effectively test the manifest files produced by 35# fossil. It looks like the one from tcllib is exactly what we need. 36# On ActiveTcl, add it with teacup. On other platforms, YMMV. 37# teacup install sha1 38if {[catch {package require sha1}] != 0} { 39 puts "The \"sha1\" package is not available." 40 test_cleanup_then_return 41} 42 43# We need a respository, so let it have one. 44test_setup 45 46#### Verify classic behavior of the manifest setting 47 48# Setting is off by default, and there are no extra files. 49fossil settings manifest 50test "set-manifest-1" {[regexp {^manifest *$} $RESULT]} 51set filelist [glob -nocomplain manifest*] 52test "set-manifest-1-n" {[llength $filelist] == 0} 53 54# Classic behavior: TRUE value creates manifest and manifest.uuid 55set truths [list true on 1] 56foreach v $truths { 57 fossil settings manifest $v 58 test "set-manifest-2-$v" {$RESULT eq ""} 59 fossil settings manifest 60 test "set-manifest-2-$v-a" {[regexp "^manifest\\s+\\(local\\)\\s+$v\\s*$" $RESULT]} 61 set filelist [glob manifest*] 62 test "set-manifest-2-$v-n" {[llength $filelist] == 2} 63 foreach f $filelist { 64 test "set-manifest-2-$v-f-$f" {[file isfile $f]} 65 } 66} 67 68# ... and manifest.uuid is the checkout's hash 69fossil info 70regexp {(?m)^checkout:\s+([0-9a-f]{40,64})\s.*$} $RESULT ckoutline ckid 71set uuid [string trim [read_file "manifest.uuid"]] 72test "set-manifest-2-uuid" {[same_uuid $ckid $uuid]} 73 74 75# ... which is also the SHA1 of the file "manifest" before it was 76# sterilized by appending an extra line when writing the file. The 77# extra text begins with # and is a full line, so we'll just strip 78# it with a brute-force substitution. This probably has the right 79# effect even if the checkin was PGP-signed, but we don't have that 80# setting turned on for this manifest in any case. 81#regsub {(?m)^#.*\n} [read_file "manifest"] "" manifest 82#set muuid [::sha1::sha1 $manifest] 83#test "set-manifest-2-manifest" {[same_uuid $muuid $uuid]} 84 85 86# Classic behavior: FALSE value removes manifest and manifest.uuid 87set falses [list false off 0] 88foreach v $falses { 89 fossil settings manifest $v 90 test "set-manifest-3-$v" {$RESULT eq ""} 91 fossil settings manifest 92 test "set-manifest-3-$v-a" {[regexp "^manifest\\s+\\(local\\)\\s+$v\\s*$" $RESULT]} 93 set filelist [glob -nocomplain manifest*] 94 test "set-manifest-3-$v-n" {[llength $filelist] == 0} 95} 96 97 98# Classic behavior: unset removes manifest and manifest.uuid 99fossil unset manifest 100test "set-manifest-4" {$RESULT eq ""} 101fossil settings manifest 102test "set-manifest-4-a" {[regexp {^manifest *$} $RESULT]} 103set filelist [glob -nocomplain manifest*] 104test "set-manifest-4-n" {[llength $filelist] == 0} 105 106 107##### Tags Manifest feature extends the manifest setting 108 109# Manifest Tags: use letters r, u, and t to select each of manifest, 110# manifest.uuid, and manifest.tags files. 111set truths [list r u t ru ut rt rut] 112foreach v $truths { 113 fossil settings manifest $v 114 test "set-manifest-5-$v" {$RESULT eq ""} 115 fossil settings manifest 116 test "set-manifest-5-$v-a" {[regexp "^manifest\\s+\\(local\\)\\s+$v\\s*$" $RESULT]} 117 set filelist [glob manifest*] 118 test "set-manifest-5-$v-n" {[llength $filelist] == [string length $v]} 119 foreach f $filelist { 120 test "set-manifest-5-$v-f-$f" {[file isfile $f]} 121 } 122} 123 124# Quick check for tags applied in trunk 125test_file_contents "set-manifest-6" "manifest.tags" "branch trunk\ntag trunk\n" 126 127 128##### Test manifest.tags file content updates after commits 129 130# Explicitly set manifest.tags mode 131fossil set manifest t 132test "set-manifest-7-1" {[file isfile manifest.tags]} 133 134# Add a tag and make sure it appears in manifest.tags 135fossil tag add manifest-7-tag-1 tip 136test "set-manifest-7-2" {[file_contains "manifest.tags" "^tag manifest-7-tag-1$"]} 137 138# Add a file and make sure tag has disappeared from manifest.tags 139write_file file1 "file1 contents" 140fossil add file1 141fossil commit -m "Added file1." 142test "set-manifest-7-3" {![file_contains "manifest.tags" "^tag manifest-7-tag-1$"]} 143 144# Add new tag and check that it is in manifest.tags 145fossil tag add manifest-7-tag-2 tip 146test "set-manifest-7-4" {[file_contains "manifest.tags" "^tag manifest-7-tag-2$"]} 147 148 149##### Tags manifest branch= updates 150 151# Add file, create new branch on commit and check that 152# manifest.tags has been updated appropriately 153write_file file3 "file3 contents" 154fossil add file3 155fossil commit -m "Added file3." --branch manifest-8-branch 156test "set-manifest-8" {[file_contains "manifest.tags" "^branch manifest-8-branch$"]} 157 158 159test_cleanup 160