pax_global_header00006660000000000000000000000064124664525600014524gustar00rootroot0000000000000052 comment=deafc98cba995251a444ba223447613dab4b3065 git-ftp-1.0.2/000077500000000000000000000000001246645256000130765ustar00rootroot00000000000000git-ftp-1.0.2/.gitignore000066400000000000000000000000201246645256000150560ustar00rootroot00000000000000MANIFEST */man1 git-ftp-1.0.2/.travis.yml000066400000000000000000000015061246645256000152110ustar00rootroot00000000000000language: sh install: - sudo apt-get install -y vsftpd before_script: - git config --global user.email "you@example.com" - git config --global user.name "Your Name" - echo write_enable=YES | sudo tee -a /etc/vsftpd.conf - echo anon_upload_enable=YES | sudo tee -a /etc/vsftpd.conf - echo anon_mkdir_write_enable=YES | sudo tee -a /etc/vsftpd.conf - echo anon_umask=000 | sudo tee -a /etc/vsftpd.conf - echo anon_other_write_enable=YES | sudo tee -a /etc/vsftpd.conf - echo anon_root=/var/ftp | sudo tee -a /etc/vsftpd.conf - sudo mkdir -p /var/ftp/pub - sudo chmod a+rwx /var/ftp/pub - sudo service vsftpd restart - export GIT_FTP_ROOT=localhost/pub - export GIT_FTP_USER=ftp - export GIT_FTP_PASSWD=ftp script: - tests/git-ftp-test.sh after_failure: - ls -la /var/ftp/pub/* - cat /etc/vsftpd.conf git-ftp-1.0.2/AUTHORS000066400000000000000000000010771246645256000141530ustar00rootroot00000000000000René Moser Eric Greve Timo Besenreuther Eric Doughty-Papassideris Woody Gilk Jo-Herman Haugholt Martin Ueding Ingo Migliarina Jonathan Patt Tasos Latsas Łukasz Stelmach Adam Brengesjö Kang 'ikasty' Dae Youn Maikel Linke Marc Addeo git-ftp-1.0.2/CHANGELOG.md000066400000000000000000000117321246645256000147130ustar00rootroot00000000000000Version 1.0.2 ============= René Moser: * Removed optimistic directory deletion, fixes GH-168 (reported by Justin Maier) Version 1.0.1 ============= Maikel Linke (1): * Fixed 'deployedsha1file' was not always considered ysakmrkm: * Docs: Add --remote-root to man file. Version 1.0.0 ============= Maikel Linke (mkllnk): * Added test to ignore single file in root directory. * Added Travis support. * Added tests for git-ftp-include with git-ftp-ignore. * Added test uploading heaps. * Improved and extended testing. * Improved checking remote access before initial upload. * Fixed upload_sha1 at end of push action. * Fixed not recognizing different SHA1 object. * Fixed upload local sha1 only if files where pushed. * Fixed delete buffer. Fire before ARG_MAX reached. * Fixed counting bug in handle_file_sync(). * Fixed upload buffer length check. * Fixed prevent deleting of unversioned files. * Removed duplicate code of setting curl args. Andrew Minion, Szerémi Attila, Max Horn, Ryan Ponce, Rob Upcraft, Pablo Alejandro Fiumara: * Documentation updates. René Moser: * Fixed scope may not contain spaces * Fixed error level of failing delete action. * Several improvements. Sudaraka Wijesinghe: * Fix for url from git config not being identified correctly. Matteo Manchi: * Fixed DEPLOYED_SHA1_FILE now cares about scope. iKasty: * Added support for different remote root directory, option --remote-root. Brad Jones: * Fixed delete for SFTP. Version 1.0.0-rc.2 ================== Maikel Linke (mkllnk): * Added more tests, tests clean up and improvements. See README.md in /tests. * Improved docs. Jason Woof, mkllnk: * Fixed .git-ftp-include split lines on whitespace. * Fixed .git-ftp-include will not upload files that are a substr of another path being uploaded. René Moser: * Added netrc in docs. * Fixed sha1 not updated if amended. Version 1.0.0-rc.1 ================== Moz Morris: * Delete files using a single connection. m4grio: * Added --disable-epsv option. Martin Hradil: * Support for .git-ftp-including files without any git dependencies. René Moser: * Updated docs. * Fixed git init fails when using .git-ftp-include as SHA1_DEPLOYED is defined. * Code cleanup. Version 0.9.0 ============= Adam Brengesjö: * Add action 'log'. Jason Woofenden: * Fixed quoting of REMOTE_PASSWD. * Fixed detection of curl verbosity setting. * Fixed log deletion failure even when being verbose. Joyce Babu: * Public key authentication key files path as configurable option. * Renamed the parameter names to match curl options. Louis Li: * Fixed a minor formatting issue in INSTALL. Mar Cejas: * Fixed bug, Error: binary operator expected. Shea Bunge: * Doc: Updated Windows installation instructions. mamzellejuu: * Doc: Fixed Repo path wasn't updated. René Moser: * Fixed egrep: repetition-operator operand invalid OS X 10.9 Version 0.8.4 ============= * Performance improvments in submodule handling. Thanks to Adam Brengesjö. * Hotfix 0.8.2 did not fix the bug. Another try fixing bug related to ARG_MAX. * Info for OS X 10.8 users: Make sure you are using GNU grep. See commit f4baf02731ada267d399a6206d21fffc0357d75a. * Info: Repo moved to https://github.com/git-ftp/git-ftp * Added support for syncing untracked files. Thanks to Jonathan Patt. * Added support for --insecure in config. Thanks to Erik Erkelens. * Fixed issues with insecure config option being ignored. Thanks to Andrew Fenn. * Fixed error output not using stderr. * Fixed sync root missing from submodule sync. Thanks to John Learn. * Lots of minor fixes and documentation updates. Version 0.8.2 ============= * Hotfixed bug, string length buffer was too small. This could cause the file upload to fail. Version 0.8.1 ============= * Added feature, --scope without argument takes the current branch name as scope. Thanks to Chris J. Lee. * Fixed bug, respect ARG_MAX if there is a large number of files. * Fixed bug, local locking did not work correctly with submodule handilng. Removed. * Added feature --insecure to not verify server certificate. Thanks to Łukasz Stelmach. * Added feature --cacert to provide custom cacert. Thanks to Łukasz Stelmach. Version 0.8.0 ============= * Fixed bug, DEFAULTS config are not over-writeable by SCOPES config using emtpy string. Thanks to Ingo Migliarina. * Fixed long outstanding issue, using a single connection for all uploads now. This makes git-ftp 5x faster! * Fixed bug, respect syncroot while syncing a submodule. Thanks to https://github.com/escaped. * Added feature, show error log at the end. Version 0.7.5 ============= * Updated man page. * Fixed bug, check for dirty repository was dependent on english. Version 0.7.4 ============= * Code cleanup. * Fixed bug in add-scope action, related to OS X only. Version 0.7.3 ============= * Added add-scope and remove-scope actions. * .git-ftp-ignore can now contain comments (#...) and whitespaces. * Fixed bug if path to git project contains whitespaces. * Fixed bug in syncroot feature. * Removed parallel connections feature. * Code cleanup (syncroot). git-ftp-1.0.2/INSTALL.md000066400000000000000000000055311246645256000145320ustar00rootroot00000000000000INSTALL ======= Stable on Linux/Unix based systems using make --------------------------------------------- Note: Make sure Git and cURL are installed. This should work on Mac OS X, Debian, Ubuntu, Fedora, RedHat, etc. The easiest way is to use Git for installing: $ git clone https://github.com/git-ftp/git-ftp.git $ cd git-ftp $ git tag # see available tags $ git checkout # checkout the latest tag by replacing $ sudo make install Updating using git $ git pull $ git tag # see available tags $ git checkout # checkout the latest tag by replacing $ sudo make install Debian official --------------- See http://packages.qa.debian.org/g/git-ftp.html Ubuntu official --------------- See https://launchpad.net/ubuntu/+source/git-ftp Ubuntu PPA (Personal Package Archive) repository ------------------------------------------------ Adding PPA on Ubuntu $ sudo -s # add-apt-repository ppa:resmo/git-ftp # aptitude update # aptitude install git-ftp Note: Usually updated after every release (tag). ArchLinux (AUR: unofficial) --------------------------- See https://aur.archlinux.org/packages/?O=0&C=0&SeB=nd&K=git-ftp&SB=v&SO=d&PP=50&do_Search=Go Mac OS X -------- Using homebrew: # brew install git # brew install curl --with-ssl --with-ssh # brew install git-ftp Windows ------- There are at least two ways to install git-ftp on Windows. * Using cygwin * Using msysgit (recommended) ### cygwin Install cygwin and install the package 'curl'. ### msysgit Install msysgit. It comes with 'curl' installed by default, however it doesn't support SFTP by default. In order to use SFTP, download curl for Windows with SFTP support on the [curl website]( http://curl.haxx.se/download.html). Win32 2000/XP MSI or Win64 2000/XP x86_64 MSI is recommended. Then in your msysgit installation folder, remove bin/curl.exe. This will allow for all calls to curl to fall back from Git's curl to the one you just installed that also supports SFTP. After this, open git bash (or cygwin bash for cygwin only): $ cd ~ $ git clone https://github.com/git-ftp/git-ftp $ cd git-ftp && chmod +x git-ftp $ cd /bin $ ln -s ~/git-ftp/git-ftp *Note: the /bin/ directory is a alias, and if you use msysgit this is the same as C:\Program Files (x86)\Git\bin\* Upstream using symlinking ------------------------- This usually works on Linux based systems, but not on Mac OS X without extending $PATH. Note: Make sure Git and cURL is installed. This is a easy way to have more then one git-ftp installed $ mkdir -p ~/develop/git-ftp.git $ cd ~/develop/git-ftp.git $ git clone https://github.com/git-ftp/git-ftp.git . $ chmod +x git-ftp $ mkdir ~/bin && cd ~/bin/ $ ln -s ~/develop/git-ftp.git/git-ftp git-ftp.dev After this you can use 'git ftp.dev' or 'git-ftp.dev' Update to the latest version is simple as: $ cd ~/develop/git-ftp.git $ git pull git-ftp-1.0.2/LICENSE000066400000000000000000001045131246645256000141070ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 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. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . git-ftp-1.0.2/Makefile000066400000000000000000000021711246645256000145370ustar00rootroot00000000000000#! /usr/bin/make -f SHELL=/bin/sh DESTDIR?=/usr/local prefix?=${DESTDIR} # files that need mode 755 EXEC_FILES=git-ftp # files that need mode 644 MAN_FILE=man1/git-ftp.1 all: @echo "usage: make install -> installs git-ftp only" @echo " make install-man -> installs man pages only" @echo " make install-all -> installs git-ftp and man pages" @echo " make uninstall" @echo " make uninstall-man" @echo " make uninstall-all" @echo " make clean" install: install -d -m 0755 $(prefix)/bin install -m 0755 $(EXEC_FILES) $(prefix)/bin install-man: install -d -m 0755 $(prefix)/man cd man && \ make man && \ install -d -m 0755 $(prefix)/man/man1 && \ install -m 0644 $(MAN_FILE) $(prefix)/man/man1 && \ mandb $(prefix)/man/man1 install-all: install install-man uninstall: test -d $(prefix)/bin && \ cd $(prefix)/bin && \ rm -f $(EXEC_FILES) uninstall-man: test -d $(prefix)/man && \ cd $(prefix)/man && \ rm -f $(MAN_FILE) mandb -f $(prefix)/man/$(MAN_FILE) rmdir --ignore-fail-on-non-empty $(prefix)/man/man1 uninstall-all: uninstall uninstall-man clean: cd man && make clean git-ftp-1.0.2/README.md000066400000000000000000000043161246645256000143610ustar00rootroot00000000000000[![Build Status](https://travis-ci.org/git-ftp/git-ftp.svg?branch=develop)](https://travis-ci.org/git-ftp/git-ftp) README of git-ftp ================= * This application is licensed under [GNU General Public License, Version 3.0] * Follow this project on twitter [@gitftp](https://twitter.com/gitftp) Summary ------- Git powered FTP client written as shell script. About ----- I use git-ftp for my script based projects, mostly PHP. Most of the low-cost web hosting companies do not provide SSH or git support, but only FTP. That is why I needed an easy way to deploy my git tracked projects. Instead of transferring the whole project, I thought, why not only transfer the files that changed since the last time, git can tell me those files. Even if you are playing with different branches, git-ftp knows which files are different. No ordinary FTP client can do that. Known Issues ------------ * See [git-ftp issues on GitHub] for open issues Installing ---------- See [INSTALL](INSTALL.md) file. Usage ----- ``` sh $ cd my_git_tracked_project $ git ftp push --user --passwd ftp://host.example.com/public_html ``` For interactive password prompt use: ``` sh $ git ftp push -u -p - ftp://host.example.com/public_html ``` Pushing for the first time: ``` sh $ git ftp init -u -p - ftp://host.example.com/public_html ``` See [man page](man/git-ftp.1.md) for more options, features and examples! Limitations ----------- * Windows and OS X: I am very limited in testing on Windows and OS X. Thanks for helping me out fixing bugs on these platforms. * git-ftp as deployment tool: git-ftp was not designed as centralized deployment tool. While running git-ftp, you have to take care, no one pushes or touches this repo (e.g. no commits, no checkouts, no file modifications)! Unit Tested ----------- Core functionality is unit tested on Linux using shunit2. You can find the tests in `tests/`. Contributions ------------- Don't hesitate to use GitHub to improve this tool. Don't forget to add yourself to the [AUTHORS](AUTHORS) file. [git-ftp issues on GitHub]: http://github.com/git-ftp/git-ftp/issues [GNU General Public License, Version 3.0]: http://www.gnu.org/licenses/gpl-3.0-standalone.html git-ftp-1.0.2/git-ftp000077500000000000000000001025231246645256000144010ustar00rootroot00000000000000#!/usr/bin/env bash # # Copyright 2010-2014 René Moser # http://github.com/git-ftp/git-ftp # # Git-ftp is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Git-ftp 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. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Git-ftp. If not, see . # ------------------------------------------------------------ # Setup Environment # ------------------------------------------------------------ # General config readonly DEFAULT_PROTOCOL="ftp" readonly REMOTE_LCK_FILE="$(basename "$0").lck" readonly SYSTEM="$(uname)" readonly VERSION='1.0.2' # ------------------------------------------------------------ # Defaults # ------------------------------------------------------------ URL="" REMOTE_PROTOCOL="" REMOTE_HOST="" REMOTE_USER="" REMOTE_PASSWD="" REMOTE_ROOT="" REMOTE_PATH="" REMOTE_CACERT="" REMOTE_DELETE_CMD="-*DELE " REMOTE_CMD_OPTIONS="-s" ACTION="" LOG_CACHE="" ERROR_LOG="" SCOPE="" KEYCHAIN_USER="" KEYCHAIN_HOST="" DEPLOYED_SHA1_FILE=".git-ftp.log" DEPLOYED_SHA1="" LOCAL_SHA1="" SYNCROOT="" CURL_INSECURE="" CURL_PUBLIC_KEY="" CURL_PRIVATE_KEY="" CURL_UPLOADS=() CURL_DELETE=() CURL_DISABLE_EPSV=0 declare -a CURL_ARGS declare -i VERBOSE=0 declare -i IGNORE_DEPLOYED=0 declare -i DRY_RUN=0 declare -i FORCE=0 declare -i ENABLE_REMOTE_LCK=0 declare -i ACTIVE_MODE=0 declare -i USE_KEYCHAIN=0 declare -i ARG_MAX=4096 declare -a GIT_SUBMODULES # ------------------------------------------------------------ # Constant Exit Error Codes # ------------------------------------------------------------ readonly ERROR_USAGE=2 readonly ERROR_MISSING_ARGUMENTS=3 readonly ERROR_UPLOAD=4 readonly ERROR_DOWNLOAD=5 readonly ERROR_UNKNOWN_PROTOCOL=6 readonly ERROR_REMOTE_LOCKED=7 readonly ERROR_GIT=8 # ------------------------------------------------------------ # Functions # ------------------------------------------------------------ usage_long() { local pager=$(git config --get core.pager) ${GIT_PAGER:-${pager:-${PAGER:-less -FRSX}}} << EOF USAGE git-ftp [] DESCRIPTION git-ftp does FTP the Git way. It uses Git to determine which local files have changed since the last deployment to the remote server and saves you time and bandwidth by uploading only those files. It keeps track of the deployed state by uploading the SHA1 of the last deployed commit in a log file. ACTIONS . init Does an initial upload of the latest version of all non-ignored git-tracked files to the remote server and creates .git-ftp.log file containing the SHA1 of the latest commit. . push Uploads git-tracked files which have changed since last upload. . show Downloads last uploaded SHA1 from log and hooks \`git show\`. . log Downloads last uploaded SHA1 from log and hooks \`git log\`. . catchup Uploads current SHA1 to log, does not upload any files. This is useful if you used another FTP client to upload the files and now want to remember the SHA1. . add-scope Add a scope (e.g. dev, production, testing). . remove-scope Completely remove a scope. . help Shows this help screen. URL . FTP (default) host.example.com[:][/] . FTP ftp://host.example.com[:][/] . SFTP sftp://host.example.com[:][/] . FTPS ftps://host.example.com[:][/] . FTPES ftpes://host.example.com[:][/] OPTIONS -h, --help Shows this help screen. -u, --user FTP login name. -p, --passwd FTP password. -k, --keychain FTP password from KeyChain (Mac OS X only). -s, --scope Using a scope (e.g. dev, production, testing). -D, --dry-run Dry run: Does not upload anything. -a, --all Uploads all files, ignores deployed SHA1 hash. -c, --commit Sets SHA1 hash of last deployed commit by option. -A, --active Use FTP active mode. -l, --lock Enable/Disable remote locking. -f, --force Force, does not ask questions. -n, --silent Silent mode. -v, --verbose Verbose mode. -vv Very verbose or debug mode. --remote-root Specifies remote root directory --syncroot Specifies a local directory to sync from as if it were the git project root path. --insecure Don't verify server's certificate. --cacert Specify a as CA certificate store. Useful when a server has got a self-signed certificate. --disable-epsv Tell curl to disable the use of the EPSV command when doing passive FTP transfers. Curl will normally always first attempt to use EPSV before PASV, but with this option, it will not try using EPSV. --version Prints version. EXAMPLES . git-ftp push -u john ftp://ftp.example.com:4445/public_ftp -p -v . git-ftp push -p -u john -v ftp.example.com:4445:/public_ftp . git-ftp add-scope production ftp://user:secr3t@ftp.example.com:4445/public_ftp . git-ftp push --scope production . git-ftp remove-scope production SET DEFAULTS . git config git-ftp.user john . git config git-ftp.url ftp.example.com . git config git-ftp.password secr3t . git config git-ftp.remote-root "~/www/" . git config git-ftp.syncroot path/dir . git config git-ftp.cacert path/cacert . git config git-ftp.deployedsha1file mySHA1File . git config git-ftp.insecure 1 SET SCOPE DEFAULTS e.g. your scope is 'testing' . git config git-ftp.testing.url ftp.example.local VERSION $VERSION EOF exit 0 } usage() { echo "git-ftp [] " exit "$ERROR_USAGE" } escape() { echo "$1" | sed 's/\([\.\+\$]\)/\\\1/g' } has() { local item=$1; shift echo " $@ " | grep -q " $(escape "$item") " } cache_git_submodules() { GIT_SUBMODULES="$(git submodule | awk '{print $2}')" } is_submodule() { has "$1" "${GIT_SUBMODULES[@]}" } is_arg_max_reached() { local ARGS=("$@") ARGS_STRING=$(echo ${ARGS[@]}) CURRENT_LENGTH=$(( ${#ARGS_STRING} )) if [ $CURRENT_LENGTH -lt $ARG_MAX ]; then return 1 fi return 0 } ask_for_passwd() { echo -n "Password: " stty -echo > /dev/null 2>&1 read REMOTE_PASSWD stty echo > /dev/null 2>&1 echo "" } get_keychain_password () { if [ "$SYSTEM" = "Darwin" ]; then # Split user and host if necessary if echo "$KEYCHAIN_USER" | grep -q '@'; then KEYCHAIN_HOST=$(echo "$KEYCHAIN_USER" | cut -d '@' -f2) KEYCHAIN_USER=$(echo "$KEYCHAIN_USER" | cut -d '@' -f1) else [ -z "$KEYCHAIN_USER" ] && KEYCHAIN_USER="$REMOTE_USER" [ -z "$KEYCHAIN_HOST" ] && KEYCHAIN_HOST="$REMOTE_HOST" fi [ -z "$KEYCHAIN_USER" ] && print_error_and_die "Missing keychain account." "$ERROR_MISSING_ARGUMENTS" CURL_ARGS=(-a "$KEYCHAIN_USER") [ -n "$KEYCHAIN_HOST" ] && CURL_ARGS+=(-s "$KEYCHAIN_HOST") local pass if pass="$(security find-internet-password ${CURL_ARGS[@]} -g 2>&1 > /dev/null)"; then without_prefix="${pass#password: \"}" REMOTE_PASSWD="${without_prefix%\"}" else print_error_and_die "Password not found in keychain for account '$KEYCHAIN_USER @ $KEYCHAIN_HOST'." "$ERROR_MISSING_ARGUMENTS" fi else write_log "Ignoring -k on non-Darwin systems." fi } # Checks if last command was successful check_exit_status() { if [ $? -ne 0 ]; then print_error_and_die "$1, exiting..." "$2" fi } get_config() { # try .git-ftp-config [ -n "$SCOPE" ] && [ -f '.git-ftp-config' ] && OUT="$(git config -f '.git-ftp-config' --get "git-ftp.$SCOPE.$1")" if [ $? -eq 0 ]; then echo "$OUT" return 0 fi [ -f '.git-ftp-config' ] && OUT="$(git config -f '.git-ftp-config' --get "git-ftp.$1")" if [ $? -eq 0 ]; then echo "$OUT" return 0 fi [ -n "$SCOPE" ] && OUT="$(git config --get "git-ftp.$SCOPE.$1")" if [ $? -eq 0 ]; then echo "$OUT" return 0 fi OUT="$(git config --get "git-ftp.$1")" if [ $? -eq 0 ]; then echo "$OUT" return 0 fi [ -n "$2" ] && OUT="$2" echo "$OUT" } set_deployed_sha1_file() { DEPLOYED_SHA1_FILE="$(get_config deployedsha1file .git-ftp.log)" } # Simple log func write_log() { if [ $VERBOSE -eq 1 ]; then echo "$(date): $1" else if [ -n "$LOG_CACHE" ]; then LOG_CACHE="$LOG_CACHE\n$(date): $1" else LOG_CACHE="$(date): $1" fi fi } write_error_log() { write_log "$1" if [ -n "$ERROR_LOG" ]; then ERROR_LOG="$ERROR_LOG\n: $1" else ERROR_LOG="$1" fi } print_error_log() { if [ -n "$ERROR_LOG" ]; then echo "Error log:" echo "$ERROR_LOG" fi } # Simple error printer print_error_and_die() { if [ $VERBOSE -eq 0 ]; then echo "fatal: $1" >&2 else write_log "fatal: $1" fi exit "$2" } # Simple info printer print_info() { if [ $VERBOSE -eq 0 ]; then echo "$1" else write_log "$1" fi } set_default_curl_options() { OIFS="$IFS" IFS=" " CURL_ARGS=(${REMOTE_CMD_OPTIONS[@]}) IFS="$OIFS" CURL_ARGS+=(--globoff) if [ ! -z "$REMOTE_USER" ]; then CURL_ARGS+=(--user "$REMOTE_USER:$REMOTE_PASSWD") else CURL_ARGS+=(--netrc) fi CURL_ARGS+=(-#) if [ $ACTIVE_MODE -eq 1 ]; then CURL_ARGS+=(-P "-") else if [ $CURL_DISABLE_EPSV -eq 1 ]; then CURL_ARGS+=(--disable-epsv) fi fi } upload_file() { local SRC_FILE="$1" local DEST_FILE="$2" if [ -z "$DEST_FILE" ]; then DEST_FILE="${SRC_FILE#$SYNCROOT}" fi set_default_curl_options CURL_ARGS+=(-T "$SRC_FILE") CURL_ARGS+=(--ftp-create-dirs) CURL_ARGS+=("$REMOTE_PROTOCOL://$REMOTE_HOST/${REMOTE_PATH}${DEST_FILE}") curl "${CURL_ARGS[@]}" check_exit_status "Could not upload file: '${REMOTE_PATH}$DEST_FILE'." "$ERROR_UPLOAD" } set_upload_curl_arguments() { set_default_curl_options CURL_ARGS+=(--ftp-create-dirs) CURL_ARGS+=("${CURL_UPLOADS[@]}") } upload_file_buffered() { local SRC_FILE="$1" local DEST_FILE="$2" local ADD_ARGS=() if [ -z "$DEST_FILE" ]; then DEST_FILE="${SRC_FILE#$SYNCROOT}" fi ADD_ARGS+=(-T "./$SRC_FILE") ADD_ARGS+=("$REMOTE_PROTOCOL://$REMOTE_HOST/${REMOTE_PATH}${DEST_FILE}") set_upload_curl_arguments if is_arg_max_reached "${CURL_ARGS[@]}" "${ADD_ARGS[@]}"; then IFS="$OIFS" fire_upload_buffer IFS="$NIFS" fi CURL_UPLOADS+=("${ADD_ARGS[@]}") } fire_upload_buffer() { if [ -z "$CURL_UPLOADS" ]; then return 0 fi print_info "Uploading ..." set_upload_curl_arguments curl "${CURL_ARGS[@]}" check_exit_status "Could not upload files." "$ERROR_UPLOAD" CURL_UPLOADS=() } delete_file() { local FILENAME="$1" set_default_curl_options CURL_ARGS+=(-Q "${REMOTE_DELETE_CMD}${REMOTE_PATH}${FILENAME}") CURL_ARGS+=("$REMOTE_PROTOCOL://$REMOTE_HOST") if [ "${REMOTE_CMD_OPTIONS:0:2}" = "-v" ]; then curl "${CURL_ARGS[@]}" else curl "${CURL_ARGS[@]}" > /dev/null 2>&1 fi if [ $? -ne 0 ]; then write_log "WARNING: Could not delete ${REMOTE_PATH}${FILENAME}, continuing..." fi } set_delete_curl_arguments() { set_default_curl_options CURL_ARGS+=("${CURL_DELETE[@]}") CURL_ARGS+=("$REMOTE_PROTOCOL://$REMOTE_HOST") } delete_file_buffered() { local FILENAME="$1" local ADD_ARGS=() ADD_ARGS+=(-Q "${REMOTE_DELETE_CMD}${REMOTE_PATH}${FILENAME}") set_delete_curl_arguments if is_arg_max_reached "${CURL_ARGS[@]}" "${ADD_ARGS[@]}"; then IFS="$OIFS" fire_delete_buffer IFS="$NIFS" fi CURL_DELETE+=("${ADD_ARGS[@]}") } fire_delete_buffer() { if [ -z "$CURL_DELETE" ]; then return 0 fi print_info "Deleting ..." set_delete_curl_arguments if [ "${REMOTE_CMD_OPTIONS:0:2}" = "-v" ]; then curl "${CURL_ARGS[@]}" else curl "${CURL_ARGS[@]}" > /dev/null 2>&1 fi if [ $? -ne 0 ]; then write_log "WARNING: Some files and/or directories could not be deleted." fi CURL_DELETE=() } get_file_content() { local SRC_FILE="$1" set_default_curl_options CURL_ARGS+=("$REMOTE_PROTOCOL://$REMOTE_HOST/${REMOTE_PATH}${SRC_FILE}") curl "${CURL_ARGS[@]}" } set_local_sha1() { LOCAL_SHA1=$(git log -n 1 --pretty=format:%H) } upload_local_sha1() { DEPLOYED_SHA1=$LOCAL_SHA1 write_log "Uploading commit log to $REMOTE_PROTOCOL://$REMOTE_HOST/${REMOTE_PATH}$DEPLOYED_SHA1_FILE." if [ $DRY_RUN -ne 1 ]; then echo "$DEPLOYED_SHA1" | upload_file - "$DEPLOYED_SHA1_FILE" check_exit_status "Could not upload." "$ERROR_UPLOAD" fi print_info "Last deployment changed to $DEPLOYED_SHA1."; } remote_lock() { [ $ENABLE_REMOTE_LCK -ne 1 ] && return [ $FORCE -ne 1 ] && check_remote_lock local LCK_MESSAGE="${USER}@$(hostname --fqdn) on $(date --utc --rfc-2822)" write_log "Remote locking $LCK_MESSAGE." if [ $DRY_RUN -ne 1 ]; then echo "${LOCAL_SHA1}\n${LCK_MESSAGE}" | upload_file - "$REMOTE_LCK_FILE" check_exit_status "Could not upload remote lock file." "$ERROR_UPLOAD" fi } release_remote_lock() { [ $ENABLE_REMOTE_LCK -ne 1 ] && return; write_log "Releasing remote lock." delete_file "$REMOTE_LCK_FILE" } set_remote_host() { [ -z "$URL" ] && URL="$(get_config url)" REMOTE_HOST=$(expr "$URL" : ".*://\([[:alpha:]0-9\.:-]*\).*") [ -z "$REMOTE_HOST" ] && REMOTE_HOST=$(expr "$URL" : "\([[:alpha:]0-9\.:-]*\).*") [ -z "$REMOTE_HOST" ] && print_error_and_die "Remote host not set." "$ERROR_MISSING_ARGUMENTS" } set_remote_protocol() { # Split protocol from url REMOTE_PROTOCOL="$(get_protocol_of_url "$URL")" # Protocol found? if [ ! -z "$REMOTE_PROTOCOL" ]; then REMOTE_PATH=$(echo "$URL" | cut -d '/' -f 4-) handle_remote_protocol_options return fi # Check if a unknown protocol is set, handle it or use default protocol local UNKNOWN_PROTOCOL=$(expr "$URL" : "\(.*:[/]*\).*") if [ -z "$UNKNOWN_PROTOCOL" ]; then write_log "Protocol not set, using default protocol $DEFAULT_PROTOCOL://." REMOTE_PROTOCOL=$DEFAULT_PROTOCOL echo "$URL" | egrep -q "/" && REMOTE_PATH=$(echo "$URL" | cut -d '/' -f 2-) handle_remote_protocol_options return fi print_error_and_die "Protocol unknown '$UNKNOWN_PROTOCOL'." "$ERROR_UNKNOWN_PROTOCOL" } set_remote_path() { # Check remote root directory [ -z "$REMOTE_ROOT" ] && REMOTE_ROOT="$(get_config remote-root)" if [ ! -z "$REMOTE_ROOT" ]; then ! echo "$REMOTE_ROOT" | egrep -q "/$" && REMOTE_ROOT="$REMOTE_ROOT/" REMOTE_PATH="$REMOTE_ROOT$REMOTE_PATH" fi # Add trailing slash if missing if [ ! -z "$REMOTE_PATH" ] && ! echo "$REMOTE_PATH" | egrep -q "/$"; then write_log "Added missing trailing / in path." REMOTE_PATH="$REMOTE_PATH/" fi } set_deployed_sha1() { # Return if commit is set by user interaction using --commit if [ -n "$DEPLOYED_SHA1" ]; then return fi # Get the last commit (SHA) we deployed if not ignored or not found write_log "Retrieving last commit from $REMOTE_PROTOCOL://$REMOTE_HOST/$REMOTE_PATH." DEPLOYED_SHA1="$(get_file_content "$DEPLOYED_SHA1_FILE")" check_exit_status "Could not get last commit. Network down? Wrong URL? Use 'git ftp init' for the initial push." "$ERROR_DOWNLOAD" write_log "Last deployed SHA1 for $REMOTE_HOST/$REMOTE_PATH is $DEPLOYED_SHA1." } set_changed_files() { # Get raw list of files if [ $IGNORE_DEPLOYED -ne 0 ]; then write_log "Taking all files."; git ls-files -t -- "$SYNCROOT" > '.git-ftp-tmp' else git diff --name-status --no-renames "$DEPLOYED_SHA1" -- "$SYNCROOT" 2>/dev/null > '.git-ftp-tmp' local git_diff_status=$? local changed_file_count="$(wc -l < '.git-ftp-tmp')" if [ "$git_diff_status" -ne 0 ]; then if [ $FORCE -ne 1 ]; then print_info "Unknown SHA1 object, make sure you are deploying the right branch and it is up-to-date." echo -n "Do you want to ignore and upload all files again? [y/N]: " read ANSWER_STATE if [ "$ANSWER_STATE" != "y" ] && [ "$ANSWER_STATE" != "Y" ]; then print_info "Aborting..." exit 0 else write_log "Taking all files."; git ls-files -t -- "$SYNCROOT" > '.git-ftp-tmp' fi else print_info "Unknown SHA1 object, could not determine changed filed, taking all files." git ls-files -t -- "$SYNCROOT" > '.git-ftp-tmp' fi elif [ "$LOCAL_SHA1" == "$DEPLOYED_SHA1" ]; then print_info "No changed files for $REMOTE_HOST/$REMOTE_PATH. Everything up-to-date." exit 0 elif [ "$changed_file_count" -eq 0 ]; then write_log "No changed files, but different commit ID. Changed files ignored or commit amended."; return fi fi # Add files from include file if [ -f '.git-ftp-include' ]; then grep -v '^#.*$\|^\s*$' '.git-ftp-include' | tr -d '\r' > '.git-ftp-include-tmp' grep '^!' '.git-ftp-include-tmp' | while read LINE do FILE_STATUS='M' FILE_PAIR=$(echo "$LINE" | sed 's/^!//') echo "$FILE_STATUS $FILE_PAIR" >> '.git-ftp-tmp' done grep ':' '.git-ftp-include-tmp' | while read LINE do OIFS="$IFS" IFS=":" FILE_PAIR=($LINE) IFS="$OIFS" cat .git-ftp-tmp | tr '\t' ' ' | cut -f2- -d ' ' > .git-ftp-tmp-files if grep -Fx -q "${FILE_PAIR[1]}" '.git-ftp-tmp-files' && ! grep -Fx -q "${FILE_PAIR[0]}" '.git-ftp-tmp-files'; then DELETE_COUNT=0 MODIFY_COUNT=0 for SUB_LINE in $(grep -F "${FILE_PAIR[0]}" '.git-ftp-include-tmp') do OIFS="$IFS" IFS=":" SUB_FILE_PAIR=($SUB_LINE) IFS="$OIFS" if [ $IGNORE_DEPLOYED -eq 0 ] && git diff --name-status --no-renames "$DEPLOYED_SHA1" -- "$SYNCROOT" -- "${SUB_FILE_PAIR[1]}" | grep -q '^D'; then let DELETE_COUNT++ else let MODIFY_COUNT++ fi done if [ -f "${FILE_PAIR[0]}" ]; then if [ "$DELETE_COUNT" -gt 0 ] && [ "$MODIFY_COUNT" -eq 0 ]; then FILE_STATUS='D' else FILE_STATUS='M' fi echo "$FILE_STATUS ${FILE_PAIR[0]}" >> '.git-ftp-tmp' fi if [ -d "${FILE_PAIR[0]}" ]; then FILE_STATUS='M' find ${FILE_PAIR[0]} -type f -print0 | xargs -0 -I{} echo "$FILE_STATUS {}" >> '.git-ftp-tmp' fi fi done fi # Filter against ignore file if [ -f '.git-ftp-ignore' ]; then grep -v '^#.*$\|^\s*$' '.git-ftp-ignore' | tr -d '\r' > '.git-ftp-ignore-tmp' FILES_CHANGED=$(grep --invert-match -f '.git-ftp-ignore-tmp' '.git-ftp-tmp' | tr '\t' ' ') else FILES_CHANGED="$(tr '\t' ' ' < '.git-ftp-tmp')" fi rm -f '.git-ftp-tmp' rm -f '.git-ftp-tmp-files' rm -f '.git-ftp-include-tmp' rm -f '.git-ftp-ignore-tmp' if [ -n "$FILES_CHANGED" ]; then write_log "Having files to sync."; else write_log "No files to sync. All changed files ignored."; fi } handle_file_sync() { if [ -z "$FILES_CHANGED" ]; then print_info "There are no files to sync." return fi # Calculate total file count local DONE_ITEMS=0 local TOTAL_ITEMS=$(echo "$FILES_CHANGED" | wc -l) TOTAL_ITEMS=$((TOTAL_ITEMS+0)) # trims whitespaces produced by wc print_info "There are $TOTAL_ITEMS files to sync:" # Changing internal field separator, file names could have spaces OIFS="$IFS" NIFS=$'\n' IFS="$NIFS" for FILE_ITERATOR in $FILES_CHANGED; do (( DONE_ITEMS++ )) FILE_MODE="$(echo "$FILE_ITERATOR" | cut -f1 -d ' ')" FILE_NAME="$(printf "$FILE_ITERATOR" | cut -f2- -d ' ')" FILE_NAME="${FILE_NAME/#\"/}" FILE_NAME="${FILE_NAME/%\"/}" if [ "$FILE_MODE" != "D" ]; then print_info "[$DONE_ITEMS of $TOTAL_ITEMS] Buffered for upload '$FILE_NAME'." if is_submodule "$FILE_NAME"; then handle_submodule_sync "${FILE_NAME#$SYNCROOT}" elif [ $DRY_RUN -ne 1 ]; then upload_file_buffered "$FILE_NAME" fi # Removing file else print_info "[$DONE_ITEMS of $TOTAL_ITEMS] Buffered for delete '$FILE_NAME'." if [ $DRY_RUN -ne 1 ]; then delete_file_buffered "${FILE_NAME#$SYNCROOT}" fi fi done IFS="$OIFS" fire_upload_buffer fire_delete_buffer } handle_submodule_sync() { print_info "Handling submodule sync for $1." # Duplicate the current required parameters args=(--user "$REMOTE_USER" --passwd "$REMOTE_PASSWD") # Do not ask any questions for submodules args+=(--force) if [ $ACTIVE_MODE -eq 1 ]; then args+=(--active) else if [ $CURL_DISABLE_EPSV -eq 1 ]; then args+=(--disable-epsv) fi fi [ $IGNORE_DEPLOYED -eq 1 ] && args+=(--all) if [ $VERBOSE -eq 1 ]; then args+=(--verbose) elif [ $VERBOSE -eq -1 ]; then args+=(--silent) fi [ $DRY_RUN -eq 1 ] && args+=(--dry-run) ( cd "${SYNCROOT}$1" && "$0" "$ACTION" ${args[@]} "$REMOTE_PROTOCOL://$REMOTE_HOST/${REMOTE_PATH}$1" ) local EXIT_CODE=$? # Pushing failed. Submodule may not be initialized if [ "$EXIT_CODE" -eq "$ERROR_DOWNLOAD" ] && [ "$ACTION" == "push" ]; then print_info "Could not push $1, trying to init..." ( cd "${SYNCROOT}$1" && "$0" init ${args[@]} "$REMOTE_PROTOCOL://$REMOTE_HOST/${REMOTE_PATH}$1" ) check_exit_status "Failed to sync submodules." "$ERROR_UPLOAD" elif [ $EXIT_CODE -ne 0 ]; then print_error_and_die "Failed to sync submodules." "$ERROR_UPLOAD" fi } handle_remote_protocol_options() { if [ "$REMOTE_PROTOCOL" = "sftp" ]; then set_sftp_config if [ ! -z "$CURL_PRIVATE_KEY" ]; then write_log "Using ssh private key file $CURL_PRIVATE_KEY" if [ -z "$CURL_PUBLIC_KEY" ]; then # If public key is not specified, use private key with .pub extension CURL_PUBLIC_KEY="$CURL_PRIVATE_KEY.pub" fi write_log "Using ssh public key file $CURL_PUBLIC_KEY" REMOTE_CMD_OPTIONS="$REMOTE_CMD_OPTIONS --key $CURL_PRIVATE_KEY --pubkey $CURL_PUBLIC_KEY" fi # SFTP uses a different remove command and uses absolute paths REMOTE_DELETE_CMD="rm /" fi # Check for using cacert if [ "$REMOTE_PROTOCOL" = "ftpes" -o "$REMOTE_PROTOCOL" = "ftps" ] && \ [ -n "$REMOTE_CACERT" -a -r "$REMOTE_CACERT" ]; then REMOTE_CMD_OPTIONS="$REMOTE_CMD_OPTIONS --cacert $REMOTE_CACERT" fi # Options for curl if using FTPES if [ "$REMOTE_PROTOCOL" = "ftpes" ]; then REMOTE_PROTOCOL="ftp" REMOTE_CMD_OPTIONS="$REMOTE_CMD_OPTIONS --ssl" fi # Require users' explicit consent for insecure connections [ "$CURL_INSECURE" != "0" ] && REMOTE_CMD_OPTIONS="$REMOTE_CMD_OPTIONS -k" } handle_action() { case "$ACTION" in init) action_init ;; push) action_push ;; catchup) action_catchup ;; show) action_show ;; log) action_log ;; add-scope) action_add_scope ;; remove-scope) action_remove_scope ;; *) print_error_and_die "Action unknown." "$ERROR_MISSING_ARGUMENTS" ;; esac } set_remote_user() { [ -z $REMOTE_USER ] && REMOTE_USER="$(get_config user)" } set_remote_cacert() { [ -z $REMOTE_CACERT ] && REMOTE_CACERT="$(get_config cacert)" } set_remote_password() { [ -z "$REMOTE_PASSWD" ] && [ $USE_KEYCHAIN -eq 1 ] && get_keychain_password "$KEYCHAIN_USER" [ -z "$REMOTE_PASSWD" ] && REMOTE_PASSWD="$(get_config password)" } set_syncroot() { [ -z "$SYNCROOT" ] && SYNCROOT="$(get_config syncroot)" if [ "$SYNCROOT" ]; then [ -d "$SYNCROOT" ] || print_error_and_die "'$SYNCROOT' is not a directory! Exiting..." "$ERROR_GIT" SYNCROOT="$(echo "$SYNCROOT" | sed 's#/*$##')/" fi } set_sftp_config() { [ -z "$CURL_PRIVATE_KEY" ] && CURL_PRIVATE_KEY="$(get_config key)" [ -z "$CURL_PUBLIC_KEY" ] && CURL_PUBLIC_KEY="$(get_config pubkey)" } set_remotes() { set_remote_host write_log "Host is '$REMOTE_HOST'." set_remote_user write_log "User is '$REMOTE_USER'." set_remote_password if [ -z "$REMOTE_PASSWD" ]; then write_log "No password is set." else write_log "Password is set." fi set_remote_protocol set_remote_path write_log "Path is '$REMOTE_PATH'." set_syncroot write_log "Syncroot is '$SYNCROOT'." set_deployed_sha1_file write_log "The remote sha1 is saved in file '$DEPLOYED_SHA1_FILE'." set_remote_cacert write_log "CACert is '$REMOTE_CACERT'." set_curl_insecure write_log "Insecure is '$CURL_INSECURE'." } set_curl_insecure() { [ -z "$CURL_INSECURE" ] && CURL_INSECURE="$(get_config insecure)" } get_protocol_of_url() { echo "$1" | tr '[:upper:]' '[:lower:]' | egrep '^(ftp|sftp|ftps|ftpes)://' | cut -d ':' -f 1 } set_scope() { [ -z "$SCOPE" ] && print_error_and_die "Missing scope argument." "$ERROR_MISSING_ARGUMENTS" [ -z "$URL" ] && print_error_and_die "Missing URL." "$ERROR_MISSING_ARGUMENTS" # URI without credentials if ! echo "$URL" | grep -q '@'; then git config "git-ftp.$SCOPE.url" "$URL" return fi # set url local protocol=$(get_protocol_of_url "$URL") local path="${URL##*@}" git config "git-ftp.$SCOPE.url" "${protocol}${path}" # strip protocol local credentials=${URL#${protocol}} # cut at last '@' occurrence local credentials=${credentials%${URL##*@}} # strip trailing '@' local credentials=${credentials%?} local colons=${credentials//[^:]/} case ${#colons} in 0) # assume only username git config "git-ftp.$SCOPE.user" "${credentials}" ;; 1) # credentials have both username and password git config "git-ftp.$SCOPE.user" "${credentials%:*}" git config "git-ftp.$SCOPE.password" "${credentials#*:}" ;; *) # we can't know where to cut with multiple ':' print_info "Warning, multiple ':' characters detected, only URL was set in scope." print_info "Use --user and --passwd options to set login and password respectively." esac } remove_scope() { [ -z "$SCOPE" ] && print_error_and_die "Missing scope argument." "$ERROR_MISSING_ARGUMENTS" git config --remove-section "git-ftp.$SCOPE" &>/dev/null [ $? -ne 0 ] && print_error_and_die "Cannot fine scope $SCOPE." "$ERROR_GIT" print_info "Successfully removed scope $SCOPE." } # ------------------------------------------------------------ # Actions # ------------------------------------------------------------ action_init() { check_git_version check_is_git_project check_is_dirty_repository set_remotes check_remote_access check_deployed_sha1 set_local_sha1 set_changed_files remote_lock handle_file_sync upload_local_sha1 release_remote_lock } action_push() { check_git_version check_is_git_project check_is_dirty_repository set_remotes set_deployed_sha1 set_local_sha1 set_changed_files remote_lock handle_file_sync upload_local_sha1 release_remote_lock } action_catchup() { check_is_git_project check_is_dirty_repository set_remotes set_local_sha1 upload_local_sha1 } action_show() { set_remotes DEPLOYED_SHA1="$(get_file_content "$DEPLOYED_SHA1_FILE")" check_exit_status "Could not get uploaded log file" "$ERROR_DOWNLOAD" git show "$DEPLOYED_SHA1" } action_log() { set_remotes DEPLOYED_SHA1="$(get_file_content "$DEPLOYED_SHA1_FILE")" check_exit_status "Could not get uploaded log file" "$ERROR_DOWNLOAD" git log "$DEPLOYED_SHA1" } action_add_scope() { check_is_git_project set_scope } action_remove_scope() { check_is_git_project remove_scope } # ------------------------------------------------------------ # Checks # ------------------------------------------------------------ check_remote_access() { local url="$REMOTE_PROTOCOL://$REMOTE_HOST/$REMOTE_PATH" write_log "Check if $url is accessible." set_default_curl_options CURL_ARGS+=(--ftp-create-dirs) CURL_ARGS+=("$url") curl "${CURL_ARGS[@]}" > /dev/null check_exit_status "Can't access remote '$url'." "$ERROR_DOWNLOAD" } check_deployed_sha1() { write_log "Check if $REMOTE_PROTOCOL://$REMOTE_HOST/$REMOTE_PATH is clean." DEPLOYED_SHA1="$(get_file_content "$DEPLOYED_SHA1_FILE")" if [ "$DEPLOYED_SHA1" != "" ]; then print_error_and_die "Commit found, use 'git ftp push' to sync. Exiting..." "$ERROR_USAGE" fi # Make sure if sync all files if no sha1 was found IGNORE_DEPLOYED=1 } check_git_version() { local GIT_VERSION="$(git --version | cut -d ' ' -f 3)" local MAJOR="$(echo "$GIT_VERSION" | cut -d '.' -f 1)" local MINOR="$(echo "$GIT_VERSION" | cut -d '.' -f 2)" if [ "$MAJOR" -lt 2 ] && [ "$MINOR" -lt 7 ]; then print_error_and_die "Git is too old, 1.7.0 or higher supported only." "$ERROR_GIT" fi } check_remote_lock() { write_log "Checking remote lock." local LCK_CONTENT="$(get_file_content "$REMOTE_LCK_FILE" 2>/dev/null)" if [ -n "$LCK_CONTENT" ]; then local LCK_SHA1=$(echo "$LCK_CONTENT" | head -n 1) write_log "Remote lock sha1 $LCK_SHA1." write_log "Local sha1 $LOCAL_SHA1." if [ "$LCK_SHA1" != "$LOCAL_SHA1" ]; then local LCK_USER=$(echo "$LCK_CONTENT" | tail -n 1) print_error_and_die "Remote locked by $LCK_USER." "$ERROR_REMOTE_LOCKED" fi fi } check_is_git_project() { local git_project_dir="$(git rev-parse --show-toplevel 2>/dev/null)" [ -z "$git_project_dir" ] && print_error_and_die "Not a Git project? Exiting..." "$ERROR_GIT" cd "$git_project_dir" } check_is_dirty_repository() { [ "$(git status -uno --porcelain | wc -l)" -ne 0 ] && print_error_and_die "Dirty repository: Having uncommitted changes. Exiting..." "$ERROR_GIT" } # ------------------------------------------------------------ # Main # ------------------------------------------------------------ main() { cache_git_submodules handle_action print_error_log exit 0 } # 2 args are needed: action and url if [ $# = 0 ]; then usage; fi while test $# != 0 do case "$1" in init|push|catchup|show|add-scope|remove-scope|log) ACTION="$1" # catch scope if [ "$1" == "add-scope" ] || [ "$1" == "remove-scope" ]; then SCOPE="$2" if ! echo "$SCOPE" | grep -q '^[-0-9a-zA-Z_]*$' ; then print_error_and_die "Invalid scope name." "$ERROR_USAGE" fi shift fi ;; -h|--h|--he|--hel|--help|help) usage_long ;; -u|--user*) case "$#,$1" in *,*=*) REMOTE_USER=$(expr "z$1" : 'z-[^=]*=\(.*\)') ;; 1,*) REMOTE_USER="$USER" ;; *) if ! echo "$2" | egrep -q '^-'; then REMOTE_USER="$2" shift else REMOTE_USER="$USER" fi ;; esac ;; -s|--scope*) case "$#,$1" in *,*=*) SCOPE=$(expr "z$1" : 'z-[^=]*=\(.*\)') ;; 1,*) check_is_git_project && SCOPE="$(git rev-parse --abbrev-ref HEAD)" ;; *) if ! echo "$2" | egrep -q '^-'; then SCOPE="$2" shift else check_is_git_project && SCOPE="$(git rev-parse --abbrev-ref HEAD)" fi ;; esac if ! echo "$SCOPE" | grep -q '^[-0-9a-zA-Z_]*$' ; then print_error_and_die "Invalid scope name." "$ERROR_USAGE" fi write_log "Using scope $SCOPE if available" ;; --syncroot*) case "$#,$1" in *,*=*) SYNCROOT="$(expr "z$1" : 'z-[^=]*=\(.*\)')" ;; 1,*) print_error_and_die "Too few arguments for option --syncroot." "$ERROR_MISSING_ARGUMENTS" ;; *) if ! echo "$2" | egrep -q '^-'; then SYNCROOT="$2" shift else print_error_and_die "Too few arguments for option --syncroot." "$ERROR_MISSING_ARGUMENTS" fi ;; esac write_log "Using syncroot $SYNCROOT if exists." ;; -c|--commit*) case "$#,$1" in *,*=*) DEPLOYED_SHA1=$(expr "z$1" : 'z-[^=]*=\(.*\)') ;; 1,*) print_error_and_die "Too few arguments for option -c." "$ERROR_MISSING_ARGUMENTS" ;; *) if ! echo "$2" | egrep -q '^-'; then DEPLOYED_SHA1="$2" shift else print_error_and_die "Too few arguments for option -c." "$ERROR_MISSING_ARGUMENTS" fi ;; esac write_log "Using commit $DEPLOYED_SHA1 as deployed." ;; -p|--passwd*) case "$#,$1" in *,*=*) REMOTE_PASSWD=$(expr "z$1" : 'z-[^=]*=\(.*\)') ;; 1,*) ask_for_passwd ;; *) if ! echo "$2" | egrep -q '^-'; then REMOTE_PASSWD="$2" else ask_for_passwd fi shift ;; esac ;; -k|--keychain*) USE_KEYCHAIN=1 write_log "Enabled keychain." case "$#,$1" in *,*=*) KEYCHAIN_USER=$(expr "z$1" : 'z-[^=]*=\(.*\)') ;; 1,*) # Nothing is handed over, this is okay ;; *) if ! echo "$2" | egrep -q '^-'; then KEYCHAIN_USER="$2" shift fi ;; esac ;; -a|--all) IGNORE_DEPLOYED=1 ;; -l|--lock) if [ $ENABLE_REMOTE_LCK -ne 1 ]; then write_log "Enabling remote locking feature." ENABLE_REMOTE_LCK=1 else write_log "Disabling remote locking feature." ENABLE_REMOTE_LCK=0 fi ;; -D|--dry-run) DRY_RUN=1 write_log "Running dry, won't do anything." ;; -n|--silent) VERBOSE=-1 REMOTE_CMD_OPTIONS="-s" ;; -v|--verbose) VERBOSE=1 [ -n "$LOG_CACHE" ] && echo -e "$LOG_CACHE" REMOTE_CMD_OPTIONS="" ;; -vv) VERBOSE=1 [ -n "$LOG_CACHE" ] && echo -e "$LOG_CACHE" REMOTE_CMD_OPTIONS="-v" ;; -f|--force) FORCE=1 write_log "Forced mode enabled." ;; --version|version) echo "git-ftp version $VERSION" exit 0 ;; --insecure) CURL_INSECURE=1 write_log "Insecure SSL/TLS connection allowed" ;; --cacert*) case "$#,$1" in *,*=*) REMOTE_CACERT=$(expr "z$1" : 'z-[^=]*=\(.*\)') ;; 1,*) print error_and_die "Too few arguments for option --cacert" "$ERROR_MISSING_ARGUMENTS" ;; *) if ! echo "$2" | egrep -q '^-'; then REMOTE_CACERT="$2" shift else print_error_and_die "Too few arguments for option --cacert" "$ERROR_MISSING_ARGUMENTS" fi ;; esac ;; --key) case "$#,$1" in *,*=*) CURL_PRIVATE_KEY=$(expr "z$1" : 'z-[^=]*=\(.*\)') ;; 1,*) print_error_and_die "Too few arguments for option --key." "$ERROR_MISSING_ARGUMENTS" ;; *) if ! echo "$2" | egrep -q '^-'; then CURL_PRIVATE_KEY="$2" shift else print_error_and_die "Too few arguments for option --key." "$ERROR_MISSING_ARGUMENTS" fi ;; esac ;; --pubkey) case "$#,$1" in *,*=*) CURL_PUBLIC_KEY=$(expr "z$1" : 'z-[^=]*=\(.*\)') ;; 1,*) print_error_and_die "Too few arguments for option --pubkey." "$ERROR_MISSING_ARGUMENTS" ;; *) if ! echo "$2" | egrep -q '^-'; then CURL_PUBLIC_KEY="$2" shift else print_error_and_die "Too few arguments for option --pubkey." "$ERROR_MISSING_ARGUMENTS" fi ;; esac ;; -A|--active) ACTIVE_MODE=1 write_log "Using active mode." ;; --disable-epsv) if [ $ACTIVE_MODE -eq 0 ]; then CURL_DISABLE_EPSV=1 write_log "Disabling EPSV." fi ;; --remote-root) REMOTE_ROOT="$2" shift ;; *) # Pass thru anything that may be meant for fetch. [ -n "$1" ] && URL=$1 ;; esac shift done main git-ftp-1.0.2/man/000077500000000000000000000000001246645256000136515ustar00rootroot00000000000000git-ftp-1.0.2/man/Makefile000066400000000000000000000006211246645256000153100ustar00rootroot00000000000000SHELL=/bin/sh # files that need mode 644 MAN_FILE=man1/git-ftp.1 HTML_FILE=html/git-ftp.html all: @echo "usage: make man" @echo " make clean" man: install -d -m 0755 man1 pandoc -s \ -w man git-ftp.1.md \ -o $(MAN_FILE) html: pandoc -s -S --toc \ -c git-ftp.css git-ftp.1.md \ -o $(HTML_FILE) clean: rm -f $(MAN_FILE) rm -f $(HTML_FILE) rmdir man1 --ignore-fail-on-non-empty git-ftp-1.0.2/man/git-ftp.1.md000066400000000000000000000164201246645256000157070ustar00rootroot00000000000000% GIT-FTP(1) git-ftp User Manual % Rene Moser % 2013-12-01 # NAME Git-ftp - Git powered FTP client written as shell script. # SYNOPSIS git-ftp [actions] [options] [url]... # DESCRIPTION This manual page documents briefly the git-ftp program. Git-ftp is a FTP client using Git to determine which local files to upload or which files should be deleted on the remote host. It saves the deployed state by uploading the SHA1 hash in the .git-ftp.log file. There is no need for [Git] to be installed on the remote host. Even if you play with different branches, git-ftp knows which files are different and only handles those files. No ordinary FTP client can do this and it saves time and bandwidth. Another advantage is Git-ftp only handles files which are tracked with [Git]. # ACTIONS `init` : Initializes the first upload to remote host. `push` : Uploads files which have changed since last upload. `catchup` : Uploads the .git-ftp.log file only. We have already uploaded the files to remote host with a different program and want to remember its state by uploading the .git-ftp.log file. `show` : Downloads last uploaded SHA1 from log and hooks \`git show\`. `log` : Downloads last uploaded SHA1 from log and hooks \`git log\`. `add-scope ` : Creates a new scope (e.g. dev, production, testing, foobar). This is a wrapper action over git-config. See **SCOPES** section for more information. `remove-scope ` : Remove a scope. `help` : Prints a usage help. # OPTIONS `-u [username]`, `--user [username]` : FTP login name. If no argument is given, local user will be taken. `-p [password]`, `--passwd [password]` : FTP password. If no argument is given, a password prompt will be shown. `-k [[user]@[account]]`, `--keychain [[user]@[account]]` : FTP password from KeyChain (Mac OS X only). `-a`, `--all` : Uploads all files of current Git checkout. `-A`, `--active` : Uses FTP active mode. `-s [scope]`, `--scope [scope]` : Using a scope (e.g. dev, production, testing, foobar). See **SCOPE** and **DEFAULTS** section for more information. `-l`, `--lock` : Enable remote locking. `-D`, `--dry-run` : Does not upload or delete anything, but tries to get the .git-ftp.log file from remote host. `-f`, `--force` : Does not ask any questions, it just does. `-n`, `--silent` : Be silent. `-h`, `--help` : Prints some usage information. `-v`, `--verbose` : Be verbose. `-vv` : Be as verbose as possible. Useful for debug information. `--remote-root` : Specifies remote root directory `--syncroot` : Specifies a local directory to sync from as if it were the git project root path. `--key` : SSH Private key file name. `--pubkey` : SSH Public key file name. Used with --key option. `--insecure` : Don't verify server's certificate. `--cacert ` : Use as CA certificate store. Useful when a server has got a self-signed certificate. `--disable-epsv` : Tell curl to disable the use of the EPSV command when doing passive FTP transfers. Curl will normally always first attempt to use EPSV before PASV, but with this option, it will not try using EPSV. `--version` : Prints version. # URL The scheme of an URL is what you would expect protocol://host.domain.tld:port/path Below a full featured URL to *host.example.com* on port *2121* to path *mypath* using protocol *ftp*: ftp://host.example.com:2121/mypath But, there is not just FTP. Supported protocols are: `ftp://...` : FTP (default if no protocol is set) `sftp://...` : SFTP `ftps://...` : FTPS `ftpes://...` : FTP over explicit SSL (FTPES) protocol # DEFAULTS Don't repeat yourself. Setting defaults for git-ftp in .git/config $ git config git-ftp.<(url|user|password|syncroot|cacert)> Everyone likes examples: $ git config git-ftp.user john $ git config git-ftp.url ftp.example.com $ git config git-ftp.password secr3t $ git config git-ftp.syncroot path/dir $ git config git-ftp.cacert caCertStore $ git config git-ftp.deployedsha1file mySHA1File $ git config git-ftp.insecure 1 $ git config git-ftp.key ~/.ssh/id_rsa After setting those defaults, push to *john@ftp.example.com* is as simple as $ git ftp push # SCOPES Need different defaults per each system or environment? Use the so called scope feature. Useful if you use multi environment development. Like a development, testing and a production environment. $ git config git-ftp..<(url|user|password|syncroot|cacert)> So in the case below you would set a testing scope and a production scope. Here we set the params for the scope "testing" $ git config git-ftp.testing.url ftp.testing.com:8080/foobar-path $ git config git-ftp.testing.password simp3l Here we set the params for the scope "production" $ git config git-ftp.production.user manager $ git config git-ftp.production.url live.example.com $ git config git-ftp.production.password n0tThatSimp3l Pushing to scope *testing* alias *john@ftp.testing.com:8080/foobar-path* using password *simp3l* $ git ftp push -s testing *Note:* The **SCOPE** feature can be mixed with the **DEFAULTS** feature. Because we didn't set the user for this scope, git-ftp uses *john* as user as set before in **DEFAULTS**. Pushing to scope *production* alias *manager@live.example.com* using password *n0tThatSimp3l* $ git ftp push -s production *Hint:* If your scope name is identical with your branch name. You can skip the scope argument, e.g. if your current branch is "production": $ git ftp push -s You can also create scopes using the add-scope action. All settings can be defined in the URL. Here we create the *production* scope using add-scope $ git ftp add-scope production ftp://manager:n0tThatSimp3l@live.example.com/foobar-path Deleting scopes is easy using the `remove-scope` action. $ git ftp remove-scope production # IGNORING FILES TO BE SYNCED Add file names to `.git-ftp-ignore` to be ignored. Ignoring all in Directory `config`: config/.* Ignoring all files having extension `.txt` in `./` : .*\.txt This ignores `a.txt` and `b.txt` but not `dir/c.txt` Ignoring a single file called `foobar.txt`: foobar\.txt # SYNCING UNTRACKED FILES To upload an untracked file when a paired tracked file changes (e.g. uploading a compiled CSS file when its source SCSS or LESS file changes), add a file pair to `.git-ftp-include`: css/style.css:scss/style.scss If you have multiple source files being combined into a single untracked file, you can pair the untracked file with multiple tracked files, one per line. This ensures the combined untracked file is properly uploaded when any of the component tracked files change: css/style.css:scss/style.scss css/style.css:scss/mixins.scss # NETRC In the backend, Git-ftp uses curl. This means `~/.netrc` could be used beside the other options of Git-ftp to authenticate. $ editor ~/.netrc machine ftp.example.com login john password SECRET # EXIT CODES There are a bunch of different error codes and their corresponding error messages that may appear during bad conditions. At the time of this writing, the exit codes are: `1` : Unknown error `2` : Wrong Usage `3` : Missing arguments `4` : Error while uploading `5` : Error while downloading `6` : Unknown protocol `7` : Remote locked `8` : Not a Git project # KNOWN ISSUES & BUGS The upstream BTS can be found at . [Git]: http://git-scm.org git-ftp-1.0.2/man/html/000077500000000000000000000000001246645256000146155ustar00rootroot00000000000000git-ftp-1.0.2/man/html/git-ftp.css000077500000000000000000000017121246645256000167050ustar00rootroot00000000000000body { color: black; font-family: Verdana, sans-serif; font-size: 100%; color: #333; } pre { border: 1px dotted gray; background-color: #ececec; color: #1111111; padding: 0.5em; } code { font-family: monospace; } h1 a, h2 a, h3 a, h4 a, h5 a { text-decoration: none; color: #7a5ada; } h1, h2, h3, h4, h5 { font-family: verdana; font-weight: bold; border-bottom: 1px dotted black; color: #7a5ada; } h1 { font-size: 130%; } h2 { font-size: 110%; } h3 { font-size: 95%; } h4 { font-size: 90%; font-style: italic; } h5 { font-size: 90%; font-style: italic; } h1.title { font-size: 200%; font-weight: bold; padding-top: 0.2em; padding-bottom: 0.2em; text-align: left; border: none; } dt code { font-weight: bold; } dd p { margin-top: 0; } git-ftp-1.0.2/tests/000077500000000000000000000000001246645256000142405ustar00rootroot00000000000000git-ftp-1.0.2/tests/Makefile000066400000000000000000000000731246645256000157000ustar00rootroot00000000000000#! /usr/bin/make -f SHELL=/bin/sh all: ./git-ftp-test.sh git-ftp-1.0.2/tests/README.md000066400000000000000000000012141246645256000155150ustar00rootroot00000000000000Testing Environment =================== The tests require access to an FTP server. They need full access to create, read and delete directories and files. You can provide the account data via environment variables. $ GIT_FTP_USER=kate $ GIT_FTP_PASSWD=s3cret $ GIT_FTP_ROOT=localhost/test_dir/ # trailing slash! $ export GIT_FTP_USER $ export GIT_FTP_PASSWD $ export GIT_FTP_ROOT Run the unit tests by executing `make`. $ make If you don't have [lftp] installed, the test will leave a bunch of test directories on the server. They are all named like git-ftp-XXXX. You should delete them. [lftp]: http://lftp.yar.ru/ git-ftp-1.0.2/tests/git-ftp-test.sh000077500000000000000000000450341246645256000171340ustar00rootroot00000000000000#!/bin/sh # # Usage: git-ftp-test.sh # # You can define environment variables to choose the FTP server to test on. # # Example: # export GIT_FTP_ROOT='localhost/git-ftp-tests' # export GIT_FTP_USER='git-ftp-test' # export GIT_FTP_PASSWD='s3cr3t' # ./git-ftp-test.sh # # You can choose test cases as well: # export TEST_CASES='test_displays_usage test_prints_version' # ./git-ftp-test.sh # # Or you can write it in one line: # TEST_CASES='test_displays_usage' GIT_FTP_PASSWD='s3cr3t' ./git-ftp-test.sh suite() { for testcase in ${TEST_CASES}; do suite_addTest "$testcase" done } oneTimeSetUp() { cd "$TESTDIR/../" GIT_FTP_CMD="$(pwd)/git-ftp" : ${GIT_FTP_USER=ftp} : ${GIT_FTP_PASSWD=} : ${GIT_FTP_ROOT=localhost} START=$(date +%s) } oneTimeTearDown() { END=$(date +%s) DIFF=$(( $END - $START )) echo "It took $DIFF seconds" } setUp() { GIT_PROJECT_PATH=$(mktemp -d -t git-ftp-XXXX) GIT_PROJECT_NAME=$(basename $GIT_PROJECT_PATH) GIT_FTP_URL="$GIT_FTP_ROOT/$GIT_PROJECT_NAME" CURL_URL="ftp://$GIT_FTP_USER:$GIT_FTP_PASSWD@$GIT_FTP_URL" [ -n "$GIT_FTP_USER" ] && GIT_FTP_USER_ARG="-u $GIT_FTP_USER" [ -n "$GIT_FTP_PASSWD" ] && GIT_FTP_PASSWD_ARG="-p $GIT_FTP_PASSWD" GIT_FTP="$GIT_FTP_CMD $GIT_FTP_USER_ARG $GIT_FTP_PASSWD_ARG $GIT_FTP_URL" cd $GIT_PROJECT_PATH # make some content for i in 1 2 3 4 5 do echo "$i" >> ./"test $i.txt" mkdir -p "dir $i" echo "$i" >> "dir $i/test $i.txt" done; # git them git init > /dev/null 2>&1 git add . > /dev/null 2>&1 git commit -a -m "init" > /dev/null 2>&1 } tearDown() { rm -rf $GIT_PROJECT_PATH command -v lftp >/dev/null 2>&1 && { lftp -u $GIT_FTP_USER,$GIT_FTP_PASSWD $GIT_FTP_ROOT -e "set ftp:list-options -a; rm -rf '$GIT_PROJECT_NAME'; exit" > /dev/null 2>&1 } } test_displays_usage() { usage=$($GIT_FTP_CMD 2>&1) assertEquals "git-ftp [] " "$usage" } test_prints_version() { version=$($GIT_FTP_CMD 2>&1 --version) assertEquals = "git-ftp version 1.0.2" "$version" } test_inits() { init=$($GIT_FTP init) assertEquals 0 $? assertTrue 'file does not exist' "remote_file_exists 'test 1.txt'" assertTrue 'file differs' "remote_file_equals 'test 1.txt'" } test_init_fails() { init=$($GIT_FTP_CMD -v -u wrong_user -p wrong_passwd $GIT_FTP_URL init 2>&1) assertEquals 5 $? error_count=$(echo "$init" | grep -F 'Access denied' | wc -l) assertEquals 1 $error_count } test_inits_and_pushes() { cd $GIT_PROJECT_PATH # this should pass init=$($GIT_FTP init) rtrn=$? assertEquals 0 $rtrn # this should fail init2=$($GIT_FTP init 2>&1) rtrn=$? assertEquals 2 $rtrn assertEquals "fatal: Commit found, use 'git ftp push' to sync. Exiting..." "$init2" # make some changes echo "1" >> "./test 1.txt" git commit -a -m "change" > /dev/null 2>&1 # this should pass push=$($GIT_FTP push) rtrn=$? assertEquals 0 $rtrn } test_init_more() { cd $GIT_PROJECT_PATH # Generate a number of files exceeding the upload buffer long_prefix='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' long_file_list='' for i in `seq 50`; do long_file_list="$long_file_list $long_prefix$i" done touch $long_file_list git add . git commit -m 'Some more files.' > /dev/null init=$($GIT_FTP init) assertEquals 0 $? assertTrue 'file does not exist' "remote_file_exists '${long_prefix}50'" # Counting the number of uploads to estimate correct buffering upload_count=$(echo "$init" | grep -Fx 'Uploading ...' | wc -l) assertTrue "[ $upload_count -gt 1 ]" } test_delete_more() { cd $GIT_PROJECT_PATH # Generate a number of files exceeding the upload buffer long_prefix='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' long_file_list='' for i in `seq 50`; do long_file_list="$long_file_list $long_prefix$i" done touch $long_file_list git add . git commit -m 'Some more files.' > /dev/null init=$($GIT_FTP init) assertEquals 0 $? # Delete a number of files exceeding the upload buffer git rm $long_file_list > /dev/null git commit -m 'Deleting some more files.' > /dev/null push=$($GIT_FTP push) assertEquals 0 $? # Counting the number of deletes to estimate correct buffering delete_count=$(echo "$push" | grep -Fx 'Deleting ...' | wc -l) assertTrue "[ $delete_count -gt 1 ]" assertFalse 'file does exist' "remote_file_exists '${long_prefix}50'" } # this test takes a couple of minutes (revealing a performance issue) disabled_test_init_heaps() { cd $GIT_PROJECT_PATH # Generate a large number of files which fails to upload on some systems touch `seq 3955` git add . git commit -m 'A lot of files.' > /dev/null $GIT_FTP init> /dev/null assertEquals 0 $? assertTrue 'file does not exist' "remote_file_exists '3955'" } test_pushes_and_fails() { cd $GIT_PROJECT_PATH push="$($GIT_FTP push 2>&1)" rtrn=$? assertEquals "fatal: Could not get last commit. Network down? Wrong URL? Use 'git ftp init' for the initial push., exiting..." "$push" assertEquals 5 $rtrn } test_push_unknown_commit() { $GIT_FTP init > /dev/null echo '000000000' | curl -s -T - $CURL_URL/.git-ftp.log push="$($GIT_FTP push 0>&- 2>&1)" assertEquals 0 $? assertContains 'Unknown SHA1 object' "$push" assertContains 'Do you want to ignore' "$push" } test_push_nothing() { cd $GIT_PROJECT_PATH init=$($GIT_FTP init) # make some changes echo "1" >> "./test 1.txt" git commit -a -m "change" > /dev/null 2>&1 push=$($GIT_FTP push --dry-run) assertEquals 0 $? assertTrue "$push" "echo \"$push\" | grep 'There are 1 files to sync:'" echo 'test 1.txt' >> .git-ftp-ignore push=$($GIT_FTP push) assertEquals 0 $? firstline=$(echo "$push" | head -n 1) assertEquals 'There are no files to sync.' "$firstline" } test_push_added() { cd $GIT_PROJECT_PATH init=$($GIT_FTP init) # add a file file='newfile.txt' echo "1" > "./$file" git add $file git commit -m "change" > /dev/null 2>&1 push=$($GIT_FTP push) assertEquals 0 $? || echo "Push: $push" assertEquals "1" "$(curl -s $CURL_URL/$file)" } test_push_twice() { cd $GIT_PROJECT_PATH init=$($GIT_FTP init) # make some changes echo "1" >> "./test 1.txt" git commit -a -m "change" > /dev/null 2>&1 push=$($GIT_FTP push) assertEquals 0 $? || echo "First push: $push" push=$($GIT_FTP push) assertEquals 0 $? || echo "Second push: $push" assertTrue "$push" "echo \"$push\" | grep 'Everything up-to-date.'" } test_push_unknown_sha1() { cd $GIT_PROJECT_PATH init=$($GIT_FTP init) # make some changes echo "1" >> "./test 1.txt" git commit -a -m "change" > /dev/null 2>&1 # change remote SHA1 echo '000000000' | curl -T - $CURL_URL/.git-ftp.log 2> /dev/null push=$(echo 'N' | $GIT_FTP push) assertEquals 0 $? echo "$push" | grep 'Unknown SHA1 object' > /dev/null assertFalse ' test 1.txt uploaded' "remote_file_equals 'test 1.txt'" } test_push_unknown_sha1_Y() { cd $GIT_PROJECT_PATH init=$($GIT_FTP init) # make some changes echo "1" >> "./test 1.txt" git commit -a -m "change" > /dev/null 2>&1 # change remote SHA1 echo '000000000' | curl -T - $CURL_URL/.git-ftp.log 2> /dev/null push=$(echo 'Y' | $GIT_FTP push) assertEquals 0 $? echo "$push" | grep 'Unknown SHA1 object' > /dev/null assertEquals 0 $? assertTrue ' test 1.txt uploaded' "remote_file_equals 'test 1.txt'" } test_defaults() { cd $GIT_PROJECT_PATH git config git-ftp.user $GIT_FTP_USER git config git-ftp.password $GIT_FTP_PASSWD git config git-ftp.url $GIT_FTP_URL init=$($GIT_FTP_CMD init) rtrn=$? assertEquals 0 $rtrn } test_defaults_uses_url_by_cli() { cd $GIT_PROJECT_PATH git config git-ftp.user $GIT_FTP_USER git config git-ftp.password $GIT_FTP_PASSWD git config git-ftp.url notexisits init=$($GIT_FTP_CMD init $GIT_FTP_URL) rtrn=$? assertEquals 0 $rtrn } test_defaults_uses_user_by_cli() { [ -z "$GIT_FTP_USER" ] && startSkipping cd $GIT_PROJECT_PATH git config git-ftp.user johndoe git config git-ftp.password $GIT_FTP_PASSWD git config git-ftp.url $GIT_FTP_URL init=$($GIT_FTP_CMD init $GIT_FTP_USER_ARG) rtrn=$? assertEquals 0 $rtrn } test_defaults_uses_password_by_cli() { [ -z "$GIT_FTP_PASSWD" ] && startSkipping cd $GIT_PROJECT_PATH git config git-ftp.user $GIT_FTP_USER git config git-ftp.password wrongpasswd git config git-ftp.url $GIT_FTP_URL init=$($GIT_FTP_CMD init $GIT_FTP_PASSWD_ARG) rtrn=$? assertEquals 0 $rtrn } test_deployedsha1file_rename() { local file='git-ftp.txt' git config git-ftp.deployedsha1file "$file" init=$($GIT_FTP init) assertEquals 0 $? assertTrue " '$file' does not exist" "remote_file_exists '$file'" assertFalse " '.git-ftp.log' does exist" "remote_file_exists '.git-ftp.log'" } test_scopes() { cd $GIT_PROJECT_PATH git config git-ftp.user $GIT_FTP_USER git config git-ftp.password wrongpasswd git config git-ftp.url $GIT_FTP_URL git config git-ftp.testing.password $GIT_FTP_PASSWD init=$($GIT_FTP_CMD init -s testing) rtrn=$? assertEquals 0 $rtrn } test_invalid_scope_name() { out=$($GIT_FTP_CMD init -s invalid:scope 2>&1) assertEquals 2 $? assertEquals 'fatal: Invalid scope name.' "$out" out=$($GIT_FTP_CMD add-scope invalid:scope 2>&1) assertEquals 2 $? assertEquals 'fatal: Invalid scope name.' "$out" } test_scopes_using_branchname_as_scope() { cd $GIT_PROJECT_PATH git config git-ftp.production.user $GIT_FTP_USER git config git-ftp.production.password $GIT_FTP_PASSWD git config git-ftp.production.url $GIT_FTP_URL git checkout -b production > /dev/null 2>&1 init=$($GIT_FTP_CMD init -s) rtrn=$? assertEquals 0 $rtrn } test_overwrite_defaults_by_scopes_emtpy_string() { cd $GIT_PROJECT_PATH git config git-ftp.user $GIT_FTP_USER git config git-ftp.password $GIT_FTP_PASSWD git config git-ftp.url $GIT_FTP_URL git config git-ftp.testing.url '' init=$($GIT_FTP_CMD init -s testing 2>/dev/null) rtrn=$? assertEquals 3 $rtrn } test_scopes_uses_password_by_cli() { cd $GIT_PROJECT_PATH git config git-ftp.user $GIT_FTP_USER git config git-ftp.password wrongpasswd git config git-ftp.url $GIT_FTP_URL git config git-ftp.testing.password wrongpasswdtoo init=$($GIT_FTP_CMD init -s testing $GIT_FTP_PASSWD_ARG) rtrn=$? assertEquals 0 $rtrn } test_delete() { cd $GIT_PROJECT_PATH init=$($GIT_FTP init) assertTrue 'test failed: file does not exist' "remote_file_exists 'test 1.txt'" git rm "test 1.txt" > /dev/null 2>&1 git commit -a -m "delete file" > /dev/null 2>&1 push=$($GIT_FTP push) rtrn=$? assertEquals 0 $rtrn assertFalse 'test failed: file still exists' "remote_file_exists 'test 1.txt'" assertTrue 'test failed: file does not exist' "remote_file_exists 'dir 1/test 1.txt'" git rm -r "dir 1" > /dev/null 2>&1 git commit -a -m "delete dir" > /dev/null 2>&1 push=$($GIT_FTP push) assertFalse 'test failed: dir and file still exists' "remote_file_exists 'dir 1/test 1.txt'" # See https://github.com/git-ftp/git-ftp/issues/168 # assertFalse 'test failed: dir still exists' "remote_file_exists 'dir 1/'" } test_ignore_single_file() { cd $GIT_PROJECT_PATH echo "test 1\.txt" > .git-ftp-ignore init=$($GIT_FTP init) assertFalse 'test failed: file was not ignored' "remote_file_exists 'test 1.txt'" } test_ignore_single_file_force_unknown_commit() { init=$($GIT_FTP init) local file='ignored.txt' touch $file echo $file > .git-ftp-ignore git add . git commit -m 'added new file that should be ignored' -q echo '000000000' | curl -s -T - $CURL_URL/.git-ftp.log push=$($GIT_FTP push -f) assertFalse 'test failed: file was not ignored' "remote_file_exists '$file'" } test_ignore_dir() { cd $GIT_PROJECT_PATH echo "dir 1/.*" > .git-ftp-ignore init=$($GIT_FTP init) assertFalse 'test failed: dir was not ignored' "remote_file_exists 'dir 1/test 1.txt'" assertTrue 'test failed: wrong dir was ignored' "remote_file_exists 'dir 2/test 2.txt'" } test_ignore_pattern() { cd $GIT_PROJECT_PATH echo "test" > .git-ftp-ignore init=$($GIT_FTP init) for i in 1 2 3 4 5 do assertFalse 'test failed: was not ignored' "remote_file_exists 'test $i.txt'" done; } disabled_test_ignore_pattern_single() { cd $GIT_PROJECT_PATH echo 'test' > 'test' echo "^test$" > .git-ftp-ignore git add . git commit -m 'adding file that should not be uploaded' > /dev/null init=$($GIT_FTP init) assertFalse 'test failed: was not ignored' "remote_file_exists 'test'" for i in 1 2 3 4 5 do assertTrue 'test failed: was ignored' "remote_file_exists 'test $i.txt'" done; } # TODO: make this test fail an the previous test work test_ignore_pattern_single_dirty() { echo 'test' > 'test' echo '^. test$' > .git-ftp-ignore git add . git commit -m 'adding file that should not be uploaded' > /dev/null init=$($GIT_FTP init) assertFalse 'test failed: was not ignored' "remote_file_exists 'test'" for i in 1 2 3 4 5 do assertTrue 'test failed: was ignored' "remote_file_exists 'test $i.txt'" done; } test_ignore_wildcard_files() { cd $GIT_PROJECT_PATH echo "test.*\.txt" > .git-ftp-ignore init=$($GIT_FTP init) for i in 1 2 3 4 5 do assertFalse 'test failed: was not ignored' "remote_file_exists 'test $i.txt'" done; } test_include_init() { cd $GIT_PROJECT_PATH echo 'unversioned' > unversioned.txt echo 'unversioned.txt' >> .gitignore echo 'unversioned.txt:test 1.txt' > .git-ftp-include echo 'new content' >> 'test 1.txt' git add . git commit -m 'unversioned file unversioned.txt should be uploaded with test 1.txt' > /dev/null init=$($GIT_FTP init) assertTrue 'unversioned.txt was not uploaded' "remote_file_exists 'unversioned.txt'" } test_include_directory() { mkdir unversioned touch unversioned/file.txt echo 'unversioned/:test 1.txt' > .git-ftp-include mkdir unversioned-not-included touch unversioned-not-included/file.txt init=$($GIT_FTP init) assertTrue 'unversioned/file.txt was not uploaded' "remote_file_exists 'unversioned/file.txt'" assertFalse 'unversioned-not-included/file.txt was uploaded' "remote_file_exists 'unversioned-not-included/file.txt'" } test_include_whitespace_init() { cd $GIT_PROJECT_PATH echo 'unversioned' > unversioned.txt echo 'unversioned.txt' >> .gitignore echo 'unversioned.txt:test X.txt' > .git-ftp-include git add . git commit -m 'unversioned file unversioned.txt should not be uploaded. test X.txt does not exist.' > /dev/null init=$($GIT_FTP init) assertFalse 'unversioned.txt was uploaded' "remote_file_exists 'unversioned.txt'" } test_include_push() { cd $GIT_PROJECT_PATH init=$($GIT_FTP init) echo 'unversioned' > unversioned.txt echo 'unversioned.txt' >> .gitignore echo 'unversioned.txt:test 1.txt' > .git-ftp-include echo 'new content' >> 'test 1.txt' git add . git commit -m 'unversioned file unversioned.txt should be uploaded with test 1.txt' > /dev/null push=$($GIT_FTP push) assertTrue 'unversioned.txt was not uploaded' "remote_file_exists 'unversioned.txt'" } test_include_ignore_init() { cd $GIT_PROJECT_PATH echo 'htaccess' > .htaccess echo 'htaccess.prod' > .htaccess.prod echo '.htaccess:.htaccess.prod' > .git-ftp-include echo '.htaccess.prod' > .gitignore git add . git commit -m 'htaccess setup' > /dev/null init=$($GIT_FTP init) assertTrue ' .htaccess was ignored' "remote_file_exists '.htaccess'" assertFalse ' .htaccess.prod was uploaded' "remote_file_exists '.htaccess.prod'" } test_include_ignore_push() { cd $GIT_PROJECT_PATH init=$($GIT_FTP init) echo 'htaccess' > .htaccess echo 'htaccess.prod' > .htaccess.prod echo '.htaccess:.htaccess.prod' > .git-ftp-include echo '.htaccess.prod' > .gitignore git add . git commit -m 'htaccess setup' > /dev/null push=$($GIT_FTP push) assertTrue ' .htaccess was ignored' "remote_file_exists '.htaccess'" assertFalse ' .htaccess.prod was uploaded' "remote_file_exists '.htaccess.prod'" } test_include_ftp_ignore_init() { cd $GIT_PROJECT_PATH echo 'htaccess' > .htaccess echo 'htaccess.prod' > .htaccess.prod echo '.htaccess:.htaccess.prod' > .git-ftp-include echo '.htaccess.prod' > .git-ftp-ignore git add . git commit -m 'htaccess setup' > /dev/null init=$($GIT_FTP init) assertTrue ' .htaccess was ignored' "remote_file_exists '.htaccess'" assertFalse ' .htaccess.prod was uploaded' "remote_file_exists '.htaccess.prod'" } test_include_ftp_ignore_push() { cd $GIT_PROJECT_PATH init=$($GIT_FTP init) echo 'htaccess' > .htaccess echo 'htaccess.prod' > .htaccess.prod echo '.htaccess:.htaccess.prod' > .git-ftp-include echo '.htaccess.prod' > .git-ftp-ignore git add . git commit -m 'htaccess setup' > /dev/null push=$($GIT_FTP push) assertTrue ' .htaccess was ignored' "remote_file_exists '.htaccess'" assertFalse ' .htaccess.prod was uploaded' "remote_file_exists '.htaccess.prod'" } # addresses issue #41 test_include_similar() { cd $GIT_PROJECT_PATH echo 'unversioned' > foo.html echo '/foo.html' >> .gitignore echo 'foo.html:templates/foo.html' > .git-ftp-include mkdir templates echo 'new content' >> 'templates/foo.html' git add . git commit -m 'unversioned file foo.html should be uploaded with templates/foo.html' > /dev/null init=$($GIT_FTP init) assertTrue 'foo.html was not uploaded' "remote_file_exists 'foo.html'" assertTrue 'templates/foo.html was not uploaded' "remote_file_exists 'templates/foo.html'" } test_hidden_file_only() { cd $GIT_PROJECT_PATH echo "test" > .htaccess git add . > /dev/null 2>&1 git commit -a -m "init" > /dev/null 2>&1 init=$($GIT_FTP init) assertTrue 'test failed: .htaccess not uploaded' "remote_file_exists '.htaccess'" } test_file_with_nonchar() { cd $GIT_PROJECT_PATH echo "test" > ./#4253-Release Contest.md git add . > /dev/null 2>&1 git commit -a -m "init" > /dev/null 2>&1 init=$($GIT_FTP init) assertTrue 'test failed: #4253-Release Contest.md not uploaded' "remote_file_exists '#4253-Release Contest.md'" git rm './#4253-Release Contest.md' > /dev/null 2>&1 git commit -a -m "delete" > /dev/null 2>&1 push=$($GIT_FTP push) assertFalse 'test failed: #4253-Release Contest.md still exists in '$CURL_URL "remote_file_exists '\#4253-Release Contest.md'" } test_syncroot() { cd $GIT_PROJECT_PATH syncroot='foo bar' mkdir "$syncroot" && echo "test" > "$syncroot/syncroot.txt" git add . > /dev/null 2>&1 git commit -a -m "syncroot test" > /dev/null 2>&1 init=$($GIT_FTP init --syncroot "$syncroot") assertTrue 'test failed: syncroot.txt not there as expected' "remote_file_exists 'syncroot.txt'" } disabled_test_file_named_dash() { cd $GIT_PROJECT_PATH echo "foobar" > - assertTrue 'test failed: file named - not there as expected' "[ -f '$GIT_PROJECT_PATH/-' ]" git add . > /dev/null 2>&1 git commit -a -m "file named - test" > /dev/null 2>&1 init=$($GIT_FTP init) rtrn=$? assertEquals 0 $rtrn } remote_file_exists() { curl "$CURL_URL/$1" --head > /dev/null } remote_file_equals() { curl -s "$CURL_URL/$1" | diff - "$1" > /dev/null } assertContains() { assertTrue "Could not find expression: $1\nTested: $2" "echo \"$2\" | grep '$1'" } # load and run shUnit2 TESTDIR=$(dirname $0) . $TESTDIR/shunit2-2.1.6/src/shunit2 git-ftp-1.0.2/tests/shunit2-2.1.6/000077500000000000000000000000001246645256000162765ustar00rootroot00000000000000git-ftp-1.0.2/tests/shunit2-2.1.6/bin/000077500000000000000000000000001246645256000170465ustar00rootroot00000000000000git-ftp-1.0.2/tests/shunit2-2.1.6/bin/gen_test_results.sh000077500000000000000000000032001246645256000227710ustar00rootroot00000000000000#! /bin/sh # $Id: gen_test_results.sh 54 2008-10-21 23:29:23Z kate.ward@forestent.com $ # vim:et:ft=sh:sts=2:sw=2 # # Copyright 2008 Kate Ward. All Rights Reserved. # Released under the LGPL (GNU Lesser General Public License) # # Author: kate.ward@forestent.com (Kate Ward) # # This script runs the provided unit tests and sends the output to the # appropriate file. # # treat unset variables as an error set -u die() { [ $# -gt 0 ] && echo "error: $@" >&2 exit 1 } BASE_DIR="`dirname $0`/.." LIB_DIR="${BASE_DIR}/lib" # load libraries . ${LIB_DIR}/shflags || die 'unable to load shflags library' . ${LIB_DIR}/shlib || die 'unable to load shlib library' . ${LIB_DIR}/versions || die 'unable to load versions library' BASE_DIR=`shlib_relToAbsPath "${BASE_DIR}"` SRC_DIR="${BASE_DIR}/src" os_name=`versions_osName |sed 's/ /_/g'` os_version=`versions_osVersion` DEFINE_boolean force false 'force overwrite' f DEFINE_string output_dir "`pwd`" 'output dir' d DEFINE_string output_file "${os_name}-${os_version}.txt" 'output file' o DEFINE_string suite 'shunit2_test.sh' 'unit test suite' s FLAGS "${@:-}" || exit $?; shift ${FLAGS_ARGC} # determine output filename output="${FLAGS_output_dir:+${FLAGS_output_dir}/}${FLAGS_output_file}" output=`shlib_relToAbsPath "${output}"` # checks if [ -f "${output}" ]; then if [ ${FLAGS_force} -eq ${FLAGS_TRUE} ]; then rm -f "${output}" else echo "not overwriting '${output}'" >&2 exit ${FLAGS_ERROR} fi fi touch "${output}" 2>/dev/null || die "unable to write to '${output}'" # run tests ( cd "${SRC_DIR}"; ./${FLAGS_suite} |tee "${output}" ) echo >&2 echo "output written to '${output}'" >&2 git-ftp-1.0.2/tests/shunit2-2.1.6/bin/which000077500000000000000000000012371246645256000201010ustar00rootroot00000000000000#! /bin/sh # $Id: which 12 2007-02-18 03:31:14Z sfsetse $ # # This is a simple implementation of the 'which' command for those OSes that # don't have one. # true; TRUE=$? false; FALSE=$? showAll=${FALSE} # process command line flags while getopts 'a' opt; do case ${opt} in a) showAll=${TRUE} esac done shift `expr ${OPTIND} - 1` # exit if no arguments were given [ $# -eq 0 ] && exit 1 command=$1 # search for command out=`echo "${PATH}" |sed "s/:/\n/g" |\ while read path; do fullPath="${path}/${command}" if [ -x "${fullPath}" ]; then echo "${fullPath}" [ ${showAll} -eq ${FALSE} ] && break fi done` [ -z "${out}" ] && exit 1 echo "${out}" git-ftp-1.0.2/tests/shunit2-2.1.6/doc/000077500000000000000000000000001246645256000170435ustar00rootroot00000000000000git-ftp-1.0.2/tests/shunit2-2.1.6/doc/CHANGES-2.1.txt000066400000000000000000000162051246645256000211560ustar00rootroot00000000000000Changes in shUnit2 2.1.X ======================== Changes with 2.1.6 ------------------ Removed all references to the DocBook documentation. Simplified the 'src' structure. Fixed error message in fail() that stated wrong number of required arguments. Updated lib/versions. Fixed bug in _shunit_mktempDir() where a failure occurred when the 'od' command was not present in /usr/bin. Renamed shunit_tmpDir variable to SHUNIT_TMPDIR to closer match the standard TMPDIR variable. Added support for calling shunit2 as an executable, in addition to the existing method of sourcing it in as a library. This allows users to keep tests working despite the location of the shunit2 executable being different for each OS distribution. Issue #14: Improved handling of some strange chars (e.g. single and double quotes) in messages. Issue# 27: Fixed error message for assertSame(). Issue# 25: Added check and error message to user when phantom functions are written to a partition mounted with noexec. Issue# 11: Added support for defining functions like 'function someFunction()'. Changes with 2.1.5 ------------------ Issue# 1: Fixed bug pointed out by R Bernstein in the trap code where certain types of exit conditions did not generate the ending report. Issue# 2: Added assertNotEquals() assert. Issue# 3: Moved check for unset variables out of shUnit2 into the unit tests. Testing poorly written software blows up if this check is in, but it is only interesting for shUnit2 itself. Added shunit_test_output.sh unit test for this. Some shells still do not catch such errors properly (e.g. Bourne shell and BASH 2.x). Added new custom assert in test_helpers to check for output to STDOUT, and none to STDERR. Replaced fatal message in the temp directory creation with a _shunit_fatal() function call. Fixed test_output unit test so it works now that the 'set -u' stuff was removed for Issue# 3. Flushed out the coding standards in the README.txt a bit more, and brought the shunit2 code up to par with the documented standards. Issue# 4: Completely changed the reporting output to be a closer match for JUnit and PyUnit. As a result, tests are counted separately from assertions. Provide public shunit_tmpDir variable that can be used by unit test scripts that need automated and guaranteed cleanup. Issue# 7: Fixed duplicated printing of messages passed to asserts. Per code review, fixed wording of failSame() and failNotSame() messages. Replaced version_info.sh with versions library and made appropriate changes in other scripts to use it. Added gen_test_results.sh to make releases easier. Fixed bugs in shlib_relToAbsPath() in shlib. Converted DocBook documentation to reStructuredText for easier maintenance. The DocBook documentation is now considered obsolete, and will be removed in a future release. Issue# 5: Fixed the documentation around the usage of failures. Issue# 9: Added unit tests and updated documentation to demonstrate the requirement of quoting values twice when macros are used. This is due to how shell parses arguments. When an invalid number of arguments is passed to a function, the invalid number is returned to the user so they are more aware of what the cause might be. Changes with 2.1.4 ------------------ Removed the _shunit_functionExists() function as it was dead code. Fixed zsh version number check in version_info. Fixed bug in last resort temporary directory creation. Fixed off-by-one in exit value for scripts caught by the trap handler. Added argument count error checking to all functions. Added mkdir_test.sh example. Moved src/test into src/shell to better match structure used with shFlags. Fixed problem where null values were not handled properly under ksh. Added support for outputting line numbers as part of assert messages. Started documenting the coding standards, and changed some variable names as a result. Improved zsh version and option checks. Renamed the __SHUNIT_VERSION variable to SHUNIT_VERSION. Changes with 2.1.3 ------------------ Added some explicit variable defaults, even though the variables are set, as they sometimes behave strange when the script is canceled. Additional workarounds for zsh compatibility. shUnit2 now exits with a non-zero exit code if any of the tests failed. This was done for automated testing frameworks. Tests that were skipped are not considered failures, and do not affect the exit code. Changed detection of STDERR output in unit tests. Changes with 2.1.2 ------------------ Unset additional variables that were missed. Added checks and workarounds to improve zsh compatibility. Added some argument count checks ``assertEquals()``, ``assertNull()``, and ``assertSame()`` Changes with 2.1.1 ------------------ Fixed bug where ``fail()`` was not honoring skipping. Fixed problem with ``docs-docbook-prep`` target that prevented it from working. (Thanks to Bryan Larsen for pointing this out.) Changed the test in ``assertFalse()`` so that any non-zero value registers as false. (Credits to Bryan Larsen) Major fiddling to bring more in line with `JUnit `. Asserts give better output when no message is given, and failures now just fail. It was pointed out that the simple 'failed' message for a failed assert was not only insufficient, it was nonstandard (when compared to JUnit) and didn't provide the user with an expected vs actual result. The code was revised somewhat to bring closer into alignment with JUnit (v4.3.1 specifically) so that it feels more "normal". (Credits to Richard Jensen) As part of the JUnit realignment, it was noticed that fail*() functions in JUnit don't actually do any comparisons themselves. They only generate a failure message. Updated the code to match. Added self-testing unit tests. Kinda horkey, but they did find bugs during the JUnit realignment. Fixed the code for returning from asserts as the return was being called before the unsetting of variables occurred. (Credits to Mathias Goldau) The assert(True|False)() functions now accept an integer value for a conditional test. A value of '0' is considered 'true', while any non-zero value is considered 'false'. All public functions now fill use default values to work properly with the '-x' shell debugging flag. Fixed the method of percent calculation for the report to get achieve better accuracy. Changes with 2.1.0 (since 2.0.1) -------------------------------- This release is a branch of the 2.0.1 release. Moving to `reStructured Text `_ for the documentation. Fixed problem with ``fail()``. The failure message was not properly printed. Fixed the ``Makefile`` so that the DocBook XML and XSLT files would be downloaded before parsing can continue. Renamed the internal ``__SHUNIT_TRUE`` and ``__SHUNIT_FALSE`` variables to ``SHUNIT_TRUE`` and ``SHUNIT_FALSE`` so that unit tests can "use" them. Added support for test "skipping". If skipping is turned on with the ``startSkip()`` function, ``assert`` and ``fail`` functions will return immediately, and the skip will be recorded. The report output format was changed to include the percentage for each test result, rather than just those successful. .. $Revision: 326 $ .. vim:fileencoding=latin1:ft=text:spell:tw=80 git-ftp-1.0.2/tests/shunit2-2.1.6/doc/LGPL-2.1000066400000000000000000000634761246645256000200420ustar00rootroot00000000000000 GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! git-ftp-1.0.2/tests/shunit2-2.1.6/doc/README.html000066400000000000000000000364661246645256000207050ustar00rootroot00000000000000 shUnit2 2.1.x README

shUnit2 2.1.x README

code.google.com

This project is stored on code.google.com as http://code.google.com/p/shunit2/. All releases as of 2.1.4 and full source are available there. Documentation is included as part of the source and each release. Source code is stored in Subversion and can be accessed using the following information.

Browse the code in a web browser:

Check out the code locally

$ svn checkout http://shunit2.googlecode.com/svn/trunk/ shflags-read-only

SourceForge

DEPRECATED

This project is stored on SourceForge as http://sf.net/projects/shunit2. The source code is stored in Subversion and can be accessed using the following information.

Check out the code locally

$ svn co https://shunit2.svn.sourceforge.net/svnroot/shunit2/trunk/source/2.1 shunit2

Browse the code in a web browser:

Making a release

For these steps, it is assumed we are working with release 2.0.0.

Steps:

  • write release notes
  • update version
  • finish changelog
  • check all the code in
  • tag the release
  • export the release
  • create tarball
  • md5sum the tarball and sign with gpg
  • update website
  • post to SourceForge and Freshmeat

Write Release Notes

This should be pretty self explanatory. Use one of the release notes from a previous release as an example.

The versions of the various platforms and shells are included when the master unit test script is run, or when bin/gen_test_results.sh is used. To determine the versions of the installed shells by hand, use the lib/versions script.

Alternatively, do the following:

Shell OS Notes
bash   $ bash --version
dash Linux $ dpkg -l |grep dash
ksh   $ ksh --version -or- $ echo 'echo $KSH_VERSION' |ksh
Cygwin see pdksh
Solaris $ strings /usr/bin/ksh |grep 'Version'
pdksh   $ strings /bin/pdksh |grep 'PD KSH'
Cygwin look in the downloaded Cygwin directory
sh Solaris not possible
zsh   $ zsh --version

Update Version

Edit src/shell/shunit2 and change the version number in the comment, as well as in the SHUNIT_VERSION variable.

Finish Documentation

Make sure that any remaining changes get put into the CHANGES-X.X.txt file.

Finish writing the RELEASE_NOTES-X.X.X.txt. If necessary, run it through the fmt command to make it pretty (hopefully it is already).

$ fmt -w 80 RELEASE_NOTES-2.0.0.txt >RELEASE_NOTES-2.0.0.txt.new
$ mv RELEASE_NOTES-2.0.0.txt.new RELEASE_NOTES-2.0.0.txt

We want to have an up-to-date version of the documentation in the release, so we'd better build it.

$ pwd
.../shunit2/source/2.1
$ cd doc
$ RST2HTML_OPTS='--stylesheet-path=rst2html.css'
$ rst2html ${RST2HTML_OPTS} shunit2.txt >shunit2.html
$ rst2html ${RST2HTML_OPTS} README.txt >README.html

Check In All the Code

This step is pretty self-explanatory

$ pwd
.../shunit2/source/2.0
$ svn ci -m "finalizing release"

Tag the Release

$ pwd
.../shunit2/source
$ ls
2.0  2.1
$ svn cp -m "Release 2.0.0" 2.0 https://shunit2.googlecode.com/svn/tags/source/2.0.0

Export the Release

$ pwd
.../shunit2/builds
$ svn export https://shunit2.googlecode.com/svn/tags/source/2.0.0 shunit2-2.0.0

Create Tarball

$ tar cfz ../releases/shunit2-2.0.0.tgz shunit2-2.0.0

Sign the Tarball with gpg

$ cd ../releases
$ gpg --default-key kate.ward@forestent.com --detach-sign shunit2-2.0.0.tgz

Update Website

Again, pretty self-explanatory. Make sure to copy the GPG signature file. Once that is done, make sure to tag the website so we can go back in time if needed.

$ pwd
.../shunit2
$ ls
source  website
$ svn cp -m "Release 2.0.0" \
website https://shunit2.googlecode.com/svn/tags/website/20060916

Now, update the website. It too is held in Subversion, so ssh into the web server and use svn up to grab the latest version.

Post to code.google.com and Freshmeat

git-ftp-1.0.2/tests/shunit2-2.1.6/doc/README.txt000066400000000000000000000151411246645256000205430ustar00rootroot00000000000000==================== shUnit2 2.1.x README ==================== code.google.com =============== This project is stored on code.google.com as http://code.google.com/p/shunit2/. All releases as of 2.1.4 and full source are available there. Documentation is included as part of the source and each release. Source code is stored in Subversion and can be accessed using the following information. Browse the code in a web browser: - http://code.google.com/p/shunit2/source/browse - svn > trunk > source > 2.1 Check out the code locally :: $ svn checkout http://shunit2.googlecode.com/svn/trunk/ shflags-read-only SourceForge =========== DEPRECATED This project is stored on SourceForge as http://sf.net/projects/shunit2. The source code is stored in Subversion and can be accessed using the following information. Check out the code locally :: $ svn co https://shunit2.svn.sourceforge.net/svnroot/shunit2/trunk/source/2.1 shunit2 Browse the code in a web browser: - http://shunit2.svn.sourceforge.net/viewvc/shunit2/trunk/source/2.1/ - http://shunit2.svn.sourceforge.net/svnroot/shunit2/trunk/source/2.1/ Making a release ================ For these steps, it is assumed we are working with release 2.0.0. Steps: - write release notes - update version - finish changelog - check all the code in - tag the release - export the release - create tarball - md5sum the tarball and sign with gpg - update website - post to SourceForge and Freshmeat Write Release Notes ------------------- This should be pretty self explanatory. Use one of the release notes from a previous release as an example. The versions of the various platforms and shells are included when the master unit test script is run, or when ``bin/gen_test_results.sh`` is used. To determine the versions of the installed shells by hand, use the ``lib/versions`` script. Alternatively, do the following: +-------+---------+-----------------------------------------------------------+ | Shell | OS | Notes | +=======+=========+===========================================================+ | bash | | ``$ bash --version`` | +-------+---------+-----------------------------------------------------------+ | dash | Linux | ``$ dpkg -l |grep dash`` | +-------+---------+-----------------------------------------------------------+ | ksh | | ``$ ksh --version`` | | | | -or- | | | | ``$ echo 'echo $KSH_VERSION' |ksh`` | | +---------+-----------------------------------------------------------+ | | Cygwin | see pdksh | | +---------+-----------------------------------------------------------+ | | Solaris | ``$ strings /usr/bin/ksh |grep 'Version'`` | +-------+---------+-----------------------------------------------------------+ | pdksh | | ``$ strings /bin/pdksh |grep 'PD KSH'`` | | +---------+-----------------------------------------------------------+ | | Cygwin | look in the downloaded Cygwin directory | +-------+---------+-----------------------------------------------------------+ | sh | Solaris | not possible | +-------+---------+-----------------------------------------------------------+ | zsh | | ``$ zsh --version`` | +-------+---------+-----------------------------------------------------------+ Update Version -------------- Edit ``src/shell/shunit2`` and change the version number in the comment, as well as in the ``SHUNIT_VERSION`` variable. Finish Documentation -------------------- Make sure that any remaining changes get put into the ``CHANGES-X.X.txt`` file. Finish writing the ``RELEASE_NOTES-X.X.X.txt``. If necessary, run it through the **fmt** command to make it pretty (hopefully it is already). :: $ fmt -w 80 RELEASE_NOTES-2.0.0.txt >RELEASE_NOTES-2.0.0.txt.new $ mv RELEASE_NOTES-2.0.0.txt.new RELEASE_NOTES-2.0.0.txt We want to have an up-to-date version of the documentation in the release, so we'd better build it. :: $ pwd .../shunit2/source/2.1 $ cd doc $ RST2HTML_OPTS='--stylesheet-path=rst2html.css' $ rst2html ${RST2HTML_OPTS} shunit2.txt >shunit2.html $ rst2html ${RST2HTML_OPTS} README.txt >README.html Check In All the Code --------------------- This step is pretty self-explanatory :: $ pwd .../shunit2/source/2.0 $ svn ci -m "finalizing release" Tag the Release --------------- :: $ pwd .../shunit2/source $ ls 2.0 2.1 $ svn cp -m "Release 2.0.0" 2.0 https://shunit2.googlecode.com/svn/tags/source/2.0.0 Export the Release ------------------ :: $ pwd .../shunit2/builds $ svn export https://shunit2.googlecode.com/svn/tags/source/2.0.0 shunit2-2.0.0 Create Tarball -------------- :: $ tar cfz ../releases/shunit2-2.0.0.tgz shunit2-2.0.0 Sign the Tarball with gpg ------------------------- :: $ cd ../releases $ gpg --default-key kate.ward@forestent.com --detach-sign shunit2-2.0.0.tgz Update Website -------------- Again, pretty self-explanatory. Make sure to copy the GPG signature file. Once that is done, make sure to tag the website so we can go back in time if needed. :: $ pwd .../shunit2 $ ls source website $ svn cp -m "Release 2.0.0" \ website https://shunit2.googlecode.com/svn/tags/website/20060916 Now, update the website. It too is held in Subversion, so **ssh** into the web server and use ``svn up`` to grab the latest version. Post to code.google.com and Freshmeat ------------------------------------- - http://code.google.com/p/shunit2/ - http://freshmeat.net/ Related Documentation ===================== Docbook: http://www.docbook.org/ Docbook XML docbook-xml-4.4.zip: http://www.docbook.org/xml/4.4/docbook-xml-4.4.zip http://www.oasis-open.org/docbook/xml/4.4/docbook-xml-4.4.zip docbook-xml-4.5.zip: http://www.docbook.org/xml/4.5/docbook-xml-4.5.zip Docbook XSL docbook-xsl-1.71.0.tar.bz2: http://prdownloads.sourceforge.net/docbook/docbook-xsl-1.71.0.tar.bz2?download docbook-xsl-1.71.1.tar.bz2: http://downloads.sourceforge.net/docbook/docbook-xsl-1.71.1.tar.bz2?use_mirror=puzzle JUnit: http://www.junit.org/ reStructuredText: http://docutils.sourceforge.net/docs/user/rst/quickstart.html .. generate HTML using rst2html from Docutils of .. http://docutils.sourceforge.net/ .. .. vim:fileencoding=latin1:ft=rst:spell:tw=80 .. $Revision: 310 $ git-ftp-1.0.2/tests/shunit2-2.1.6/doc/RELEASE_NOTES-2.1.0.txt000066400000000000000000000043151246645256000222730ustar00rootroot00000000000000Release Notes for shUnit2 2.1.0 =============================== This release was branched from shUnit2 2.0.1. It mostly adds new functionality, but there are couple of bugs fixed from the previous release. See the ``CHANGES-2.1.rst`` file for a full list of changes. Tested Platforms ---------------- This list of platforms comes from the latest version of log4sh as shUnit2 is used in the testing of log4sh on each of these platforms. Cygwin - bash 3.2.9(10) - pdksh 5.2.14 Linux - bash 3.1.17(1), 3.2.10(1) - dash 0.5.3 - ksh 1993-12-28 - pdksh 5.2.14 - zsh 4.3.2 (does not work) Mac OS X 10.4.8 (Darwin 8.8) - bash 2.05b.0(1) - ksh 1993-12-28 Solaris 8 U3 (x86) - /bin/sh - bash 2.03.0(1) - ksh M-11/16/88i Solaris 10 U2 (sparc) - /bin/sh - bash 3.00.16(1) - ksh M-11/16/88i Solaris 10 U2 (x86) - /bin/sh - bash 3.00.16(1) - ksh M-11/16/88i New Features ------------ Test skipping Support added for test "skipping". A skip mode can be enabled so that subsequent ``assert`` and ``fail`` functions that are called will be recorded as "skipped" rather than as "passed" or "failed". This functionality can be used such that when a set of tests makes sense on one platform but not on another, they can be effectively disabled without altering the total number of tests. One example might be when something is supported under ``bash``, but not under a standard Bourne shell. New functions: ``startSkipping()``, ``endSkipping``, ``isSkipping`` Changes and Enhancements ------------------------ Moving to the use of `reStructured Text `_ for documentation. It is easy to read and edit in textual form, but converts nicely to HTML. The report format has changed. Rather than including a simple "success" percentage at the end, a percentage is given for each type of test. Bug Fixes --------- The ``fail()`` function did not output the optional failure message. Fixed the ``Makefile`` so that the DocBook XML and XSLT files would be downloaded before documentation parsing will continue. Deprecated Features ------------------- None. Known Bugs and Issues --------------------- None. .. $Revision: 273 $ .. vim:fileencoding=latin1:spell:syntax=rst:textwidth=80 git-ftp-1.0.2/tests/shunit2-2.1.6/doc/RELEASE_NOTES-2.1.1.txt000066400000000000000000000031421246645256000222710ustar00rootroot00000000000000Release Notes for shUnit2 2.1.1 =============================== This is mainly a bug fix release, but it also incorporates a realignment with the JUnit 4 code. Asserts now provide better failure messages, and the failure functions no longer perform tests. See the ``CHANGES-2.1.txt`` file for a full list of changes. Tested Platforms ---------------- This list of platforms comes from the latest version of log4sh as shUnit2 is used in the testing of log4sh on each of these platforms. Cygwin - bash 3.2.15(13) - pdksh 5.2.14 Linux - bash 3.1.17(1), 3.2.10(1) - dash 0.5.3 - ksh 1993-12-28 - pdksh 5.2.14 - zsh 4.3.2 (does not work) Mac OS X 10.4.9 (Darwin 8.9.1) - bash 2.05b.0(1) - ksh 1993-12-28 Solaris 8 U3 (x86) - /bin/sh - bash 2.03.0(1) - ksh M-11/16/88i Solaris 10 U2 (sparc, x86) - /bin/sh - bash 3.00.16(1) - ksh M-11/16/88i New Features ------------ None. Changes and Enhancements ------------------------ The internal test in ``assertFalse()`` now accepts any non-zero value as false. The ``assertTrue()`` and ``assertFalse()`` functions now accept an integer value for a conditional test. A value of '0' is considered 'true', while any non-zero value is considered 'false'. Self-testing unit tests were added. Bug Fixes --------- The ``fail()`` assert now honors skipping. The ``docs-docbook-prep`` target now works properly. All asserts now properly unset their variables. Deprecated Features ------------------- None. Known Bugs and Issues --------------------- Functions do not properly test for an invalid number of arguments. .. vim:fileencoding=latin1:ft=rst:spell:textwidth=80 git-ftp-1.0.2/tests/shunit2-2.1.6/doc/RELEASE_NOTES-2.1.2.txt000066400000000000000000000032401246645256000222710ustar00rootroot00000000000000Release Notes for shUnit2 2.1.2 =============================== This release adds initial support for the zsh shell. Due to some differences with this shell as compared with others, some special checks have been added, and there are some extra requirements necessary when this shell is to be used. To use zsh with shUnit2, the following two requirements must be met: * The ``shwordsplit`` option must be set. * The ``function_argzero`` option must be unset. Please read the Shell Errata section of the documentation for guidance on how to meet these requirements. See the ``CHANGES-2.1.txt`` file for a full list of changes. Tested Platforms ---------------- This list of platforms comes from the latest version of log4sh as shUnit2 is used in the testing of log4sh on each of these platforms. Linux - bash 3.1.17(1), 3.2.25(1) - dash 0.5.4 - ksh 1993-12-28 - pdksh 5.2.14 - zsh 4.2.5, 4.3.4 Mac OS X 10.4.11 (Darwin 8.11.1) - bash 2.05b.0(1) - ksh 1993-12-28 - zsh 4.2.3 Solaris 10 U3 (x86) - /bin/sh - bash 3.00.16(1) - ksh M-11/16/88i - zsh 4.2.1 New Features ------------ Support for the zsh shell. Changes and Enhancements ------------------------ Added some argument count checks. Bug Fixes --------- None. Deprecated Features ------------------- None. Known Bugs and Issues --------------------- Functions do not properly test for an invalid number of arguments. ksh and pdksh do not pass null arguments (i.e. empty strings as '') properly, and as such checks do not work properly. zsh requires the ``shwordsplit`` option to be set, and the ``function_argzero`` option to be unset for proper operation. .. vim:fileencoding=latin1:ft=rst:spell:textwidth=80 git-ftp-1.0.2/tests/shunit2-2.1.6/doc/RELEASE_NOTES-2.1.3.txt000066400000000000000000000030421246645256000222720ustar00rootroot00000000000000Release Notes for shUnit2 2.1.3 =============================== This release is minor feature release. It improves support for zsh (although it still isn't what it could be) and adds automated testing framework support by returning a non-zero exit when tests fail. To use zsh with shUnit2, the following two requirements must be met: * The ``shwordsplit`` option must be set. * The ``function_argzero`` option must be unset. Please read the Shell Errata section of the documentation for guidance on how to meet these requirements. See the ``CHANGES-2.1.txt`` file for a full list of changes. Tested Platforms ---------------- Cygwin - bash 3.2.33(18) - pdksh 5.2.14 Linux - bash 3.2.33(1) - dash 0.5.4 - ksh 1993-12-28 - pdksh 5.2.14 - zsh 4.3.4 Mac OS X 10.5.2 (Darwin 9.2.2) - bash 3.2.17(1) - ksh 1993-12-28 - zsh 4.3.4 Solaris 11 x86 (Nevada 77) - /bin/sh - bash 3.2.25(1) - ksh M-11/16/88i - zsh 4.3.4 New Features ------------ None. Changes and Enhancements ------------------------ Support for automated testing frameworks. Bug Fixes --------- Fixed some issues with zsh support. Deprecated Features ------------------- None. Known Bugs and Issues --------------------- Functions do not properly test for an invalid number of arguments. ksh and pdksh do not pass null arguments (i.e. empty strings as '') properly, and as such checks do not work properly. zsh requires the ``shwordsplit`` option to be set, and the ``function_argzero`` option to be unset for proper operation. .. vim:fileencoding=latin1:ft=rst:spell:textwidth=80 git-ftp-1.0.2/tests/shunit2-2.1.6/doc/RELEASE_NOTES-2.1.4.txt000066400000000000000000000032641246645256000223010ustar00rootroot00000000000000Release Notes for shUnit2 2.1.4 =============================== This release contains lots of bug fixes and changes. Mostly, it fixes zsh support in zsh 3.0, and the handling of null values in ksh. To use zsh with shUnit2, the following requirement must be met: - The ``shwordsplit`` option must be set. Please read the Shell Errata section of the documentation for guidance on how to meet these requirements. See the ``CHANGES-2.1.txt`` file for a full list of changes. Tested Platforms ---------------- Cygwin - bash 3.2.39(19) - pdksh 5.2.14 - zsh 4.3.4 Linux (Ubuntu Dapper 6.06) - bash 3.1.17(1) - pdksh 5.2.14 - zsh 4.2.5 Linux (Ubuntu Hardy 8.04) - bash 3.2.39(1) - dash 0.5.4 - ksh 1993-12-28 - pdksh 5.2.14 - zsh 4.3.4 Mac OS X 10.5.4 (Darwin 9.4.0) - bash 3.2.17(1) - ksh 1993-12-28 - zsh 4.3.4 Solaris 9 U6 x86 - /bin/sh - bash 2.05.0(1) - ksh M-11/16/88i - zsh 3.0.8 Solaris 11 x86 (Nevada 77) - /bin/sh - bash 3.2.25(1) - ksh M-11/16/88i - zsh 4.3.4 New Features ------------ Support added to output assert source line number as part of assert messages. Changes and Enhancements ------------------------ Support for automated testing frameworks. Added argument count error checking to all functions. Bug Fixes --------- Fixed some issues with ksh and zsh support. Fixed off-by-one of exit value in trap handler. Fixed handling of null values under ksh. Fixed bug in last resort temporary directory creation. Deprecated Features ------------------- None. Known Bugs and Issues --------------------- zsh requires the ``shwordsplit`` option to be set. Line numbers in assert messages do not work properly with Bash 2.x. .. vim:fileencoding=latin1:ft=rst:spell:tw=80 git-ftp-1.0.2/tests/shunit2-2.1.6/doc/RELEASE_NOTES-2.1.5.txt000066400000000000000000000054561246645256000223070ustar00rootroot00000000000000Release Notes for shUnit2 2.1.5 =============================== This release contains several bug fixes and changes. Additionally, it includes a rewrite of the test output to better match JUnit and PyUnit. This version also includes a slightly expanded set of coding standards by which shUnit2 is coded. It should help anyone reading the code to better understand it. Please read the Shell Errata section of the documentation for guidance on how to meet these requirements. See the ``CHANGES-2.1.txt`` file for a full list of changes. Tested Platforms ---------------- Cygwin - bash 3.2.39(20) - ksh (sym-link to pdksh) - pdksh 5.2.14 - zsh 4.3.4 Linux (Ubuntu Dapper 6.06) - bash 3.1.17(1) - ksh M-1993-12-28 - pdksh 5.2.14-99/07/13.2 - zsh 4.2.5 Linux (Ubuntu Hardy 8.04) - bash 3.2.39(1) - dash 0.5.4 - ksh M-1993-12-28 - pdksh 5.2.14-99/07/13.2 - zsh 4.3.4 Mac OS X 10.5.4 (Darwin 9.4.0) - bash 3.2.17(1) - ksh M-1993-12-28 - zsh 4.3.4 Solaris 9 U6 x86 - /bin/sh - bash 2.05.0(1) - ksh M-11/16/88i - zsh 3.0.8 Solaris 11 x86 (Nevada 77) - /bin/sh - bash 3.2.25(1) - ksh M-11/16/88i - zsh 4.3.4 New Features ------------ Support added for output assert source line number as part of assert messages. Issue #2: Added assertNotEquals() assert. Provided a public ``shunit_tmpDir`` variable that can be used by unit test scripts that need automated and guaranteed cleanup. Changes and Enhancements ------------------------ Issue #3: Removed the check for unset variables as shUnit2 should not expect scripts being tested to be clean. Issue #4: Rewrote the test summary. It is now greatly simplified and much more script friendly. Issue #5: Fixed the documentation around the usage of failures. Issue #9: Added unit tests and improved documentation around the use of macros. Code updated to meet documented coding standards. Improved code reuse of ``_shunit_exit()`` and ``_shunit_fatal()`` functions. All output except shUnit2 error messages now goes to STDOUT. Converted DocBook documentation to reStructuredText for easier maintenance. Bug Fixes --------- Issue #1: Fixed bug in rap code where certain types of exit conditions did not generate the ending report. Issue #7: Fixed duplicated printing of messages passed to asserts. Fixed bugs in ``shlib_relToAbsPath()`` in ``shlib``. Deprecated Features ------------------- None. Known Bugs and Issues --------------------- Zsh requires the ``shwordsplit`` option to be set. See the documentation for examples of how to do this. Line numbers in assert messages do not work properly with BASH 2.x. The Bourne shell of Solaris, BASH 2.x, and Zsh 3.0.x do not properly catch the SIGTERM signal. As such, shell interpreter failures due to such things as unbound variables cannot be caught. (See ``shunit_test_misc.sh``) .. vim:fileencoding=latin1:ft=rst:spell:tw=80 git-ftp-1.0.2/tests/shunit2-2.1.6/doc/RELEASE_NOTES-2.1.6.txt000066400000000000000000000045301246645256000223000ustar00rootroot00000000000000Release Notes for shUnit2 2.1.6 =============================== This release contains bug fixes and changes. It is also the first release to support running shunit2 as a standalone program. Please read the Shell Errata section of the documentation for guidance on how to meet these requirements. See the ``CHANGES-2.1.txt`` file for a full list of changes. New Features ------------ Support for running shUnit2 as a standalone program. This makes it possible for users to execute their unit tests in a manner that is not dependent on the location an OS distribution maintainer chose to place shUnit2 in the file system. Added support for functions defined like 'function someFunction()'. Changes and Enhancements ------------------------ Renamed the public ``shunit_tmpDir`` variable to ``SHUNIT_TMPDIR`` to be more consistent with the ``TMPDIR`` variable. Bug Fixes --------- Fixed issue where shunit2 would fail on some distributions when creating a temporary directory because the **od** command was not present. Deprecated Features ------------------- None. Known Bugs and Issues --------------------- Zsh requires the ``shwordsplit`` option to be set. See the documentation for examples of how to do this. Line numbers in assert messages do not work properly with BASH 2.x. The Bourne shell of Solaris, BASH 2.x, and Zsh 3.0.x do not properly catch the SIGTERM signal. As such, shell interpreter failures due to such things as unbound variables cannot be caught. (See ``shunit_test_misc.sh``) Tested Platforms ---------------- Cygwin 1.7.9 (Windows XP SP2) - bash 4.1.10(4) - dash 0.5.6.1 - ksh (sym-link to pdksh) - pdksh 5.2.14 - zsh 4.3.11 Linux (Ubuntu Dapper 6.06.2 LTS) - bash 3.1.17(1) - dash 0.5.3 - ksh (sym-link to pdksh) - pdksh 5.2.14-99/07/13.2 - zsh 4.2.5 Linux (Ubuntu Hardy 8.04.4 LTS) - bash 3.2.39(1) - dash 0.5.4 - ksh M-1993-12-28 - pdksh 5.2.14-99/07/13.2 - zsh 4.3.4 Linux (Ubuntu Lucid 10.04.2 LTS) - bash 4.1.5(1) - dash 0.5.5.1 - ksh JM-93t+-2009-05-01 - pdksh 5.2.14-99/07/13.2 - zsh 4.3.10 Mac OS X 10.6.7 - bash 3.2.48(1) - ksh M-1993-12-28 - zsh 4.3.9 Solaris 8 U7 x86 - /bin/sh - bash 2.03.0(1) - ksh M-11/16/88i - zsh 3.0.6 Solaris 9 U6 x86 - /bin/sh - bash 2.05.0(1) - ksh M-11/16/88i - zsh 3.0.8 OpenSolaris 2009.06(snv_111b) x86 - /bin/sh - bash 3.2.25(1) - ksh 2008-11-04 .. vim:fileencoding=latin1:ft=rst:spell:tw=80 git-ftp-1.0.2/tests/shunit2-2.1.6/doc/TODO.txt000066400000000000000000000007541246645256000203570ustar00rootroot00000000000000Make it possible to execute a single test by passing the name of the test on the command line Add support for '--randomize-order' so that the test order is randomized to check for dependencies (which shouldn't be there) between tests. --debug option to display point in source code (line number and such) where the problem showed up. assertTrue() just gives 'ASSERT:', nothing else :-(. others too? upd: assertNull() will give message passed, but nothing else useful :-( $Revision: 228 $ git-ftp-1.0.2/tests/shunit2-2.1.6/doc/coding_standards.txt000066400000000000000000000064211246645256000231150ustar00rootroot00000000000000Coding Standards ================ Variable and Function Names --------------------------- All shUnit2 specific constants, variables, and functions will be prefixed appropriately with 'shunit'. This is to distinguish usage in the shUnit2 code from users own scripts so that the shell name space remains predictable to users. The exceptions here are the standard ``assertEquals``, etc. functions. All non-builtin constants and variables will be surrouned with squiggle brackets, e.g. '${shunit_someVariable}' to improve code readability. Due to some shells not supporting local variables in functions, care in the naming and use of variables, both public and private, is very important. Accidental overriding of the variables can occur easily if care is not taken as all variables are technically global variables in some shells. +----------------------------------+---------------------------+ | *type* | *sample* | +==================================+===========================+ | global public constant | ``SHUNIT_TRUE`` | +----------------------------------+---------------------------+ | global private constant | ``__SHUNIT_SHELL_FLAGS`` | +----------------------------------+---------------------------+ | global public variable | not used | +----------------------------------+---------------------------+ | global private variable | ``__shunit_someVariable`` | +----------------------------------+---------------------------+ | global macro | ``_SHUNIT_SOME_MACRO_`` | +----------------------------------+---------------------------+ | public function | ``assertEquals`` | +----------------------------------+---------------------------+ | public function, local variable | ``shunit_someVariable_`` | +----------------------------------+---------------------------+ | private function | ``_shunit_someFunction`` | +----------------------------------+---------------------------+ | private function, local variable | ``_shunit_someVariable_`` | +----------------------------------+---------------------------+ Where it makes sense, variables can have the first letter of the second and later words capitalized. For example, the local variable name for the total number of test cases seen might be ``shunit_totalTestsSeen_``. Local Variable Cleanup ---------------------- As many shells do not support local variables, no support for cleanup of variables is present either. As such, all variables local to a function must be cleared up with the ``unset`` command at the end of each function. Indentation ----------- Code block indentation is two (2) spaces, and tabs may not be used. :: if [ -z 'some string' ]; then someFunction fi Lines of code should be no longer than 80 characters unless absolutely necessary. When lines are wrapped using the backslash character '\', subsequent lines should be indented with four (4) spaces so as to differentiate from the standard spacing of two characters. Tabs may *not* be used. :: for x in some set of very long set of arguments that make for a very long \ that extends much too long for one line do echo ${x} done .. vim:fileencoding=latin1:ft=rst:spell:tw=80 .. $Revision: 301 $ git-ftp-1.0.2/tests/shunit2-2.1.6/doc/contributors.txt000066400000000000000000000004351246645256000223430ustar00rootroot00000000000000The original author of shunit2 is Kate Ward. The following people have contributed in some way or another to shunit2. Bryan Larsen Kevin Van Horn Maciej Bliziński Mario Sparada Mathias Goldau Richard Jensen Rob Holland Rocky Bernstein wood4321 (of code.google.com) $Revision: 313 $ git-ftp-1.0.2/tests/shunit2-2.1.6/doc/design_doc.txt000066400000000000000000000026621246645256000217100ustar00rootroot00000000000000Design Doc for shUnit shUnit is based upon JUnit. The initial ideas for the script came from the book "Pragmatic Unit Testing - In Java with JUnit" by Andrew Hunt and David Thomas. The script was written to perform unit testing for log4sh. log4sh had grown enough that it was becoming difficult to easily test and and verify that the tests passed for the many different operating systems on which it was being used. The functions in shUnit are meant to match those in JUnit as much as possible where shell allows. In the initial version, there will be no concept of exceptions (as normal POSIX shell has no concept of them) but attempts to trap problems will be done. Programatic Standards: * SHUNIT_TRUE - public global constant * __SHUNIT_SHELL_FLAGS - private global constant * __shunit_oldShellFlags - private global variable * assertEquals - public unit test function * shunit_publicFunc - public shUnit function; can be called from parent unit test script * _shunit_privateFunc - private shUnit function; should not be called from parent script. meant for internal use by shUnit * _su_myVar - variable inside a public function. prefixing with '_su_' to reduce the chances that a variable outside of shUnit will be overridden. * _su__myVar - variable inside a private function. prefixing with '_su__' to reduce the chances that a variable in a shUnit public function, or a variable outside of shUnit will be overridden. $Revision: 4 $ git-ftp-1.0.2/tests/shunit2-2.1.6/doc/rst2html.css000066400000000000000000000132771246645256000213460ustar00rootroot00000000000000/* :Author: David Goodger :Contact: goodger@users.sourceforge.net :Date: $Date: 2007-04-11 11:48:16 +0100 (Wed, 11 Apr 2007) $ :Revision: $Revision: 2791 $ :Copyright: This stylesheet has been placed in the public domain. :Modified by: Kate Ward Default cascading style sheet for the HTML output of Docutils. See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to customize this style sheet. */ /* used to remove borders from tables and images */ .borderless, table.borderless td, table.borderless th { border: 0 } table.borderless td, table.borderless th { /* Override padding for "table.docutils td" with "! important". The right padding separates the table cells. */ padding: 0 0.5em 0 0 ! important } .first { /* Override more specific margin styles with "! important". */ margin-top: 0 ! important } .last, .with-subtitle { margin-bottom: 0 ! important } .hidden { display: none } a.toc-backref { text-decoration: none ; color: black } blockquote.epigraph { margin: 2em 5em ; } dl.docutils dd { margin-bottom: 0.5em } /* Uncomment (and remove this text!) to get bold-faced definition list terms dl.docutils dt { font-weight: bold } */ div.abstract { margin: 2em 5em } div.abstract p.topic-title { font-weight: bold ; text-align: center } div.admonition, div.attention, div.caution, div.danger, div.error, div.hint, div.important, div.note, div.tip, div.warning { margin: 2em ; border: medium outset ; padding: 1em } div.admonition p.admonition-title, div.hint p.admonition-title, div.important p.admonition-title, div.note p.admonition-title, div.tip p.admonition-title { font-weight: bold ; font-family: sans-serif } div.attention p.admonition-title, div.caution p.admonition-title, div.danger p.admonition-title, div.error p.admonition-title, div.warning p.admonition-title { color: red ; font-weight: bold ; font-family: sans-serif } /* Uncomment (and remove this text!) to get reduced vertical space in compound paragraphs. div.compound .compound-first, div.compound .compound-middle { margin-bottom: 0.5em } div.compound .compound-last, div.compound .compound-middle { margin-top: 0.5em } */ div.dedication { margin: 2em 5em ; text-align: center ; font-style: italic } div.dedication p.topic-title { font-weight: bold ; font-style: normal } div.figure { margin-left: 2em ; margin-right: 2em } div.footer, div.header { clear: both; font-size: smaller } div.line-block { display: block ; margin-top: 1em ; margin-bottom: 1em } div.line-block div.line-block { margin-top: 0 ; margin-bottom: 0 ; margin-left: 1.5em } div.sidebar { margin-left: 1em ; border: medium outset ; padding: 1em ; background-color: #ffffee ; width: 40% ; float: right ; clear: right } div.sidebar p.rubric { font-family: sans-serif ; font-size: medium } div.system-messages { margin: 5em } div.system-messages h1 { color: red } div.system-message { border: medium outset ; padding: 1em } div.system-message p.system-message-title { color: red ; font-weight: bold } div.topic { margin: 2em } h1.section-subtitle, h2.section-subtitle, h3.section-subtitle, h4.section-subtitle, h5.section-subtitle, h6.section-subtitle { margin-top: 0.4em } h1.title { text-align: center } h2.subtitle { text-align: center } hr.docutils { width: 75% } img.align-left { clear: left } img.align-right { clear: right } ol.simple, ul.simple { margin-bottom: 1em } ol.arabic { list-style: decimal } ol.loweralpha { list-style: lower-alpha } ol.upperalpha { list-style: upper-alpha } ol.lowerroman { list-style: lower-roman } ol.upperroman { list-style: upper-roman } p.attribution { text-align: right ; margin-left: 50% } p.caption { font-style: italic } p.credits { font-style: italic ; font-size: smaller } p.label { white-space: nowrap } p.rubric { font-weight: bold ; font-size: larger ; color: maroon ; text-align: center } p.sidebar-title { font-family: sans-serif ; font-weight: bold ; font-size: larger } p.sidebar-subtitle { font-family: sans-serif ; font-weight: bold } p.topic-title { font-weight: bold } pre.address { margin-bottom: 0 ; margin-top: 0 ; font-family: serif ; font-size: 100% } pre.literal-block, pre.doctest-block { margin-left: 2em ; margin-right: 2em ; background-color: #eeeeee } span.classifier { font-family: sans-serif ; font-style: oblique } span.classifier-delimiter { font-family: sans-serif ; font-weight: bold } span.interpreted { font-family: sans-serif } span.option { white-space: nowrap } span.pre { white-space: pre } span.problematic { color: red } span.section-subtitle { /* font-size relative to parent (h1..h6 element) */ font-size: 80% } table.citation { border-left: solid 1px gray; margin-left: 1px } table.docinfo { margin: 2em 4em } /* table.docutils { margin-top: 0.5em ; margin-bottom: 0.5em } */ table.footnote { border-left: solid 1px black; margin-left: 1px ; font-size: 80% } } table.docutils td, table.docutils th, table.docinfo td, table.docinfo th { padding-left: 0.5em ; padding-right: 0.5em ; vertical-align: top } table.docutils th.field-name, table.docinfo th.docinfo-name { font-weight: bold ; text-align: left ; white-space: nowrap ; padding-left: 0 } h1 tt.docutils, h2 tt.docutils, h3 tt.docutils, h4 tt.docutils, h5 tt.docutils, h6 tt.docutils { font-size: 100% } /* tt.docutils { background-color: #eeeeee } */ ul.auto-toc { list-style-type: none } /* customizations by kward */ h1 { font-size: 133%; border-top:1px solid #CCCCFF; } h1.title { font-size: 150%; border-top:0px; padding-top: 1em; } /* div.document { font-size: 90% } */ git-ftp-1.0.2/tests/shunit2-2.1.6/doc/shunit2.html000066400000000000000000001050501246645256000213260ustar00rootroot00000000000000 shUnit2 2.1.x Documentation

shUnit2 2.1.x Documentation

Abstract

shUnit2 is a xUnit unit test framework for Bourne based shell scripts, and it is designed to work in a similar manner to JUnit, PyUnit, etc.. If you have ever had the desire to write a unit test for a shell script, shUnit2 can do the job.

Introduction

shUnit2 was originally developed to provide a consistent testing solution for log4sh, a shell based logging framework similar to log4j. During the development of that product, a repeated problem of having things work just fine under one shell (/bin/bash on Linux to be specific), and then not working under another shell (/bin/sh on Solaris) kept coming up. Although several simple tests were run, they were not adequate and did not catch some corner cases. The decision was finally made to write a proper unit test framework after multiple brown-bag releases were made. Research was done to look for an existing product that met the testing requirements, but no adequate product was found.

Tested Operating Systems (varies over time)

  • Cygwin
  • FreeBSD (user supported)
  • Linux (Gentoo, Ubuntu)
  • Mac OS X
  • Solaris 8, 9, 10 (inc. OpenSolaris)

Tested Shells

  • Bourne Shell (sh)
  • BASH - GNU Bourne Again SHell (bash)
  • DASH (dash)
  • Korn Shell (ksh)
  • pdksh - Public Domain Korn Shell (pdksh)
  • zsh - Zsh (zsh) (since 2.1.2) please see the Zsh shell errata for more information

See the appropriate Release Notes for this release (doc/RELEASE_NOTES-X.X.X.txt) for the list of actual versions tested.

Credits / Contributors

A list of contributors to shUnit2 can be found in the source archive in doc/contributors.txt. Many thanks go out to all those who have contributed to make this a better tool.

shUnit2 is the original product of many hours of work by Kate Ward, the primary author of the code. For other products by her, look up log4sh or shFlags, or visit her website at http://forestent.com/.

Feedback

Feedback is most certainly welcome for this document. Send your additions, comments and criticisms to the shunit2-users@google.com mailing list.

Quickstart

This section will give a very quick start to running unit tests with shUnit2. More information is located in later sections.

Here is a quick sample script to show how easy it is to write a unit test in shell. Note: the script as it stands expects that you are running it from the ``examples`` directory.

#! /bin/sh
# file: examples/equality_test.sh

testEquality()
{
  assertEquals 1 1
}

# load shunit2
. ../src/shell/shunit2

Running the unit test should give results similar to the following.

testEquality

Ran 1 test.

OK

W00t! You've just run your first successful unit test. So, what just happened? Quite a bit really, and it all happened simply by sourcing the shunit2 library. The basic functionality for the script above goes like this:

  • When shUnit2 is sourced, it will walk through any functions defined whose namestart with the string test and add those to an internal list of tests to execute. Once a list of test functions to be run has been determined, shunit2 will go to work.
  • Before any tests are executed, shUnit2 again looks for a function, this time one named oneTimeSetUp(). If it exists, it will be run. This function is normally used to setup the environment for all tests to be run. Things like creating directories for output or setting environment variables are good to place here. Just so you know, you can also declare a corresponding function named oneTimeTearDown() function that does the same thing, but once all the tests have been completed. It is good for removing temporary directories, etc.
  • shUnit2 is now ready to run tests. Before doing so though, it again looks for another function that might be declared, one named setUp(). If the function exists, it will be run before each test. It is good for resetting the environment so that each test starts with a clean slate. At this stage, the first test is finally run. The success of the test is recorded for a report that will be generated later. After the test is run, shUnit2 looks for a final function that might be declared, one named tearDown(). If it exists, it will be run after each test. It is a good place for cleaning up after each test, maybe doing things like removing files that were created, or removing directories. This set of steps, setUp() > test() > tearDown(), is repeated for all of the available tests.
  • Once all the work is done, shUnit2 will generate the nice report you saw above. A summary of all the successes and failures will be given so that you know how well your code is doing.

We should now try adding a test that fails. Change your unit test to look like this.

#! /bin/sh
# file: examples/party_test.sh

testEquality()
{
  assertEquals 1 1
}

testPartyLikeItIs1999()
{
  year=`date '+%Y'`
  assertEquals "It's not 1999 :-(" \
      '1999' "${year}"
}

# load shunit2
. ../src/shell/shunit2

So, what did you get? I guess it told you that this isn't 1999. Bummer, eh? Hopefully, you noticed a couple of things that were different about the second test. First, we added an optional message that the user will see if the assert fails. Second, we did comparisons of strings instead of integers as in the first test. It doesn't matter whether you are testing for equality of strings or integers. Both work equally well with shUnit2.

Hopefully, this is enough to get you started with unit testing. If you want a ton more examples, take a look at the tests provided with log4sh or shFlags. Both provide excellent examples of more advanced usage. shUnit2 was after all written to help with the unit testing problems that log4sh had.

Function Reference

General Info

Any string values passed should be properly quoted -- they should must be surrounded by single-quote (') or double-quote (") characters -- so that the shell will properly parse them.

Asserts

assertEquals [message] expected actual
Asserts that expected and actual are equal to one another. The expected and actual values can be either strings or integer values as both will be treated as strings. The message is optional, and must be quoted.
assertNotEquals [message] expected actual
Asserts that unexpected and actual are not equal to one another. The unexpected and actual values can be either strings or integer values as both will be treaded as strings. The message is optional, and must be quoted.
assertSame [message] expected actual
This function is functionally equivalent to assertEquals.
assertNotSame [message] unexpected actual
This function is functionally equivalent to assertNotEquals.
assertNull [message] value
Asserts that value is null, or in shell terms, a zero-length string. The value must be a string as an integer value does not translate into a zero-length string. The message is optional, and must be quoted.
assertNotNull [message] value
Asserts that value is not null, or in shell terms, a non-empty string. The value may be a string or an integer as the later will be parsed as a non-empty string value. The message is optional, and must be quoted.
assertTrue [message] condition

Asserts that a given shell test condition is true. The condition can be as simple as a shell true value (the value 0 -- equivalent to ${SHUNIT_TRUE}), or a more sophisticated shell conditional expression. The message is optional, and must be quoted.

A sophisticated shell conditional expression is equivalent to what the if or while shell built-ins would use (more specifically, what the test command would use). Testing for example whether some value is greater than another value can be done this way.

assertTrue "[ 34 -gt 23 ]"

Testing for the ability to read a file can also be done. This particular test will fail.

assertTrue 'test failed' "[ -r /some/non-existant/file' ]"

As the expressions are standard shell test expressions, it is possible to string multiple expressions together with -a and -o in the standard fashion. This test will succeed as the entire expression evaluates to true.

assertTrue 'test failed' '[ 1 -eq 1 -a 2 -eq 2 ]'

One word of warning: be very careful with your quoting as shell is not the most forgiving of bad quoting, and things will fail in strange ways.

assertFalse [message] condition

Asserts that a given shell test condition is false. The condition can be as simple as a shell false value (the value 1 -- equivalent to ${SHUNIT_FALSE}), or a more sophisticated shell conditional expression. The message is optional, and must be quoted.

For examples of more sophisticated expressions, see ``assertTrue``.

Failures

Just to clarify, failures do not test the various arguments against one another. Failures simply fail, optionally with a message, and that is all they do. If you need to test arguments against one another, use asserts.

If all failures do is fail, why might one use them? There are times when you may have some very complicated logic that you need to test, and the simple asserts provided are simply not adequate. You can do your own validation of the code, use an assertTrue ${SHUNIT_TRUE} if your own tests succeeded, and use a failure to record a failure.

fail [message]
Fails the test immediately. The message is optional, and must be quoted.
failNotEquals [message] unexpected actual

Fails the test immediately, reporting that the unexpected and actual values are not equal to one another. The message is optional, and must be quoted.

Note: no actual comparison of unexpected and actual is done.

failSame [message] expected actual

Fails the test immediately, reporting that the expected and actual values are the same. The message is optional, and must be quoted.

Note: no actual comparison of expected and actual is done.

failNotSame [message] expected actual

Fails the test immediately, reporting that the expected and actual values are not the same. The message is optional, and must be quoted.

Note: no actual comparison of expected and actual is done.

Setup/Teardown

oneTimeSetUp

This function can be be optionally overridden by the user in their test suite.

If this function exists, it will be called once before any tests are run. It is useful to prepare a common environment for all tests.

oneTimeTearDown

This function can be be optionally overridden by the user in their test suite.

If this function exists, it will be called once after all tests are completed. It is useful to clean up the environment after all tests.

setUp

This function can be be optionally overridden by the user in their test suite.

If this function exists, it will be called before each test is run. It is useful to reset the environment before each test.

tearDown

This function can be be optionally overridden by the user in their test suite.

If this function exists, it will be called after each test completes. It is useful to clean up the environment after each test.

Skipping

startSkipping
This function forces the remaining assert and fail functions to be "skipped", i.e. they will have no effect. Each function skipped will be recorded so that the total of asserts and fails will not be altered.
endSkipping
This function returns calls to the assert and fail functions to their default behavior, i.e. they will be called.
isSkipping
This function returns the current state of skipping. It can be compared against ${SHUNIT_TRUE} or ${SHUNIT_FALSE} if desired.

Suites

The default behavior of shUnit2 is that all tests will be found dynamically. If you have a specific set of tests you want to run, or you don't want to use the standard naming scheme of prefixing your tests with test, these functions are for you. Most users will never use them though.

suite

This function can be optionally overridden by the user in their test suite.

If this function exists, it will be called when shunit2 is sourced. If it does not exist, shUnit2 will search the parent script for all functions beginning with the word test, and they will be added dynamically to the test suite.

suite_addTest name
This function adds a function named name to the list of tests scheduled for execution as part of this test suite. This function should only be called from within the suite() function.

Advanced Usage

This section covers several advanced usage topics.

Some constants you can use

There are several constants provided by shUnit2 as variables that might be of use to you.

Predefined

SHUNIT_VERSION The version of shUnit2 you are running.
SHUNIT_TRUE Standard shell true value (the integer value 0).
SHUNIT_FALSE Standard shell false value (the integer value 1).
SHUNIT_ERROR The integer value 2.
SHUNIT_TMPDIR Path to temporary directory that will be automatically cleaned up upon exit of shUnit2.

User defined

SHUNIT_PARENT The filename of the shell script containing the tests. This is needed specifically for Zsh support.

Error handling

The constants values SHUNIT_TRUE, SHUNIT_FALSE, and SHUNIT_ERROR are returned from nearly every function to indicate the success or failure of the function. Additionally the variable flags_error is filled with a detailed error message if any function returns with a SHUNIT_ERROR value.

Including Line Numbers in Asserts (Macros)

If you include lots of assert statements in an individual test function, it can become difficult to determine exactly which assert was thrown unless your messages are unique. To help somewhat, line numbers can be included in the assert messages. To enable this, a special shell "macro" must be used rather than the standard assert calls. Shell doesn't actually have macros; the name is used here as the operation is similar to a standard macro.

For example, to include line numbers for a assertEquals() function call, replace the assertEquals() with ${_ASSERT_EQUALS_}.

Example -- Asserts with and without line numbers

#! /bin/sh
# file: examples/lineno_test.sh

testLineNo()
{
  # this assert will have line numbers included (e.g. "ASSERT:[123] ...")
  echo "ae: ${_ASSERT_EQUALS_}"
  ${_ASSERT_EQUALS_} 'not equal' 1 2

  # this assert will not have line numbers included (e.g. "ASSERT: ...")
  assertEquals 'not equal' 1 2
}

# load shunit2
. ../src/shell/shunit2

Notes:

  1. Due to how shell parses command-line arguments, all strings used with macros should be quoted twice. Namely, single-quotes must be converted to single-double-quotes, and vice-versa. If the string being passed is absolutely for sure not empty, the extra quoting is not necessary.

    Normal assertEquals call.

    assertEquals 'some message' 'x' ''
    

    Macro _ASSERT_EQUALS_ call. Note the extra quoting around the message and the null value.

    _ASSERT_EQUALS_ '"some message"' 'x' '""'
    
  2. Line numbers are not supported in all shells. If a shell does not support them, no errors will be thrown. Supported shells include: bash (>=3.0), ksh, pdksh, and zsh.

Test Skipping

There are times where the test code you have written is just not applicable to the system you are running on. This section describes how to skip these tests but maintain the total test count.

Probably the easiest example would be shell code that is meant to run under the bash shell, but the unit test is running under the Bourne shell. There are things that just won't work. The following test code demonstrates two sample functions, one that will be run under any shell, and the another that will run only under the bash shell.

Example -- math include

# available as examples/math.inc

add_generic()
{
  num_a=$1
  num_b=$2

  expr $1 + $2
}

add_bash()
{
  num_a=$1
  num_b=$2

  echo $(($1 + $2))
}

And here is a corresponding unit test that correctly skips the add_bash() function when the unit test is not running under the bash shell.

Example -- math unit test

#! /bin/sh
# available as examples/math_test.sh

testAdding()
{
  result=`add_generic 1 2`
  assertEquals \
      "the result of '${result}' was wrong" \
      3 "${result}"

  # disable non-generic tests
  [ -z "${BASH_VERSION:-}" ] && startSkipping

  result=`add_bash 1 2`
  assertEquals \
      "the result of '${result}' was wrong" \
      3 "${result}"
}

oneTimeSetUp()
{
  # load include to test
  . ./math.inc
}

# load and run shUnit2
. ../src/shell/shunit2

Running the above test under the bash shell will result in the following output.

$ /bin/bash math_test.sh
testAdding

Ran 1 test.

OK

But, running the test under any other Unix shell will result in the following output.

$ /bin/ksh math_test.sh
testAdding

Ran 1 test.

OK (skipped=1)

As you can see, the total number of tests has not changed, but the report indicates that some tests were skipped.

Skipping can be controlled with the following functions: startSkipping(), stopSkipping(), and isSkipping(). Once skipping is enabled, it will remain enabled until the end of the current test function call, after which skipping is disabled.

Appendix

Getting help

For help, please send requests to either the shunit2-users@googlegroups.com mailing list (archives available on the web at http://groups.google.com/group/shunit2-users) or directly to Kate Ward <kate dot ward at forestent dot com>.

Zsh

For compatibility with Zsh, there is one requirement that must be met -- the shwordsplit option must be set. There are three ways to accomplish this.

  1. In the unit-test script, add the following shell code snippet before sourcing the shunit2 library.

    setopt shwordsplit
    
  2. When invoking zsh from either the command-line or as a script with #!, add the -y parameter.

    #! /bin/zsh -y
    
  3. When invoking zsh from the command-line, add -o shwordsplit -- as parameters before the script name.

    $ zsh -o shwordsplit -- some_script
    
git-ftp-1.0.2/tests/shunit2-2.1.6/doc/shunit2.txt000066400000000000000000000464311246645256000212100ustar00rootroot00000000000000=========================== shUnit2 2.1.x Documentation =========================== Abstract ======== shUnit2_ is a xUnit_ unit test framework for Bourne based shell scripts, and it is designed to work in a similar manner to JUnit_, PyUnit_, etc.. If you have ever had the desire to write a unit test for a shell script, shUnit2 can do the job. .. contents:: Table of Contents :depth: 2 Introduction ============ shUnit2 was originally developed to provide a consistent testing solution for log4sh_, a shell based logging framework similar to log4j_. During the development of that product, a repeated problem of having things work just fine under one shell (``/bin/bash`` on Linux to be specific), and then not working under another shell (``/bin/sh`` on Solaris) kept coming up. Although several simple tests were run, they were not adequate and did not catch some corner cases. The decision was finally made to write a proper unit test framework after multiple brown-bag releases were made. *Research was done to look for an existing product that met the testing requirements, but no adequate product was found.* Tested Operating Systems (varies over time) - Cygwin - FreeBSD (user supported) - Linux (Gentoo, Ubuntu) - Mac OS X - Solaris 8, 9, 10 (inc. OpenSolaris) Tested Shells - Bourne Shell (**sh**) - BASH - GNU Bourne Again SHell (**bash**) - DASH (**dash**) - Korn Shell (**ksh**) - pdksh - Public Domain Korn Shell (**pdksh**) - zsh - Zsh (**zsh**) (since 2.1.2) *please see the Zsh shell errata for more information* See the appropriate Release Notes for this release (``doc/RELEASE_NOTES-X.X.X.txt``) for the list of actual versions tested. Credits / Contributors ---------------------- A list of contributors to shUnit2 can be found in the source archive in ``doc/contributors.txt``. Many thanks go out to all those who have contributed to make this a better tool. shUnit2 is the original product of many hours of work by Kate Ward, the primary author of the code. For other products by her, look up log4sh_ or shFlags_, or visit her website at http://forestent.com/. Feedback -------- Feedback is most certainly welcome for this document. Send your additions, comments and criticisms to the shunit2-users@google.com mailing list. Quickstart ========== This section will give a very quick start to running unit tests with shUnit2. More information is located in later sections. Here is a quick sample script to show how easy it is to write a unit test in shell. *Note: the script as it stands expects that you are running it from the ``examples`` directory.* :: #! /bin/sh # file: examples/equality_test.sh testEquality() { assertEquals 1 1 } # load shunit2 . ../src/shell/shunit2 Running the unit test should give results similar to the following. :: testEquality Ran 1 test. OK W00t! You've just run your first successful unit test. So, what just happened? Quite a bit really, and it all happened simply by sourcing the ``shunit2`` library. The basic functionality for the script above goes like this: - When shUnit2 is sourced, it will walk through any functions defined whose namestart with the string ``test`` and add those to an internal list of tests to execute. Once a list of test functions to be run has been determined, shunit2 will go to work. - Before any tests are executed, shUnit2 again looks for a function, this time one named ``oneTimeSetUp()``. If it exists, it will be run. This function is normally used to setup the environment for all tests to be run. Things like creating directories for output or setting environment variables are good to place here. Just so you know, you can also declare a corresponding function named ``oneTimeTearDown()`` function that does the same thing, but once all the tests have been completed. It is good for removing temporary directories, etc. - shUnit2 is now ready to run tests. Before doing so though, it again looks for another function that might be declared, one named ``setUp()``. If the function exists, it will be run before each test. It is good for resetting the environment so that each test starts with a clean slate. At this stage, the first test is finally run. The success of the test is recorded for a report that will be generated later. After the test is run, shUnit2 looks for a final function that might be declared, one named ``tearDown()``. If it exists, it will be run after each test. It is a good place for cleaning up after each test, maybe doing things like removing files that were created, or removing directories. This set of steps, ``setUp()`` > ``test()`` > ``tearDown()``, is repeated for all of the available tests. - Once all the work is done, shUnit2 will generate the nice report you saw above. A summary of all the successes and failures will be given so that you know how well your code is doing. We should now try adding a test that fails. Change your unit test to look like this. :: #! /bin/sh # file: examples/party_test.sh testEquality() { assertEquals 1 1 } testPartyLikeItIs1999() { year=`date '+%Y'` assertEquals "It's not 1999 :-(" \ '1999' "${year}" } # load shunit2 . ../src/shell/shunit2 So, what did you get? I guess it told you that this isn't 1999. Bummer, eh? Hopefully, you noticed a couple of things that were different about the second test. First, we added an optional message that the user will see if the assert fails. Second, we did comparisons of strings instead of integers as in the first test. It doesn't matter whether you are testing for equality of strings or integers. Both work equally well with shUnit2. Hopefully, this is enough to get you started with unit testing. If you want a ton more examples, take a look at the tests provided with log4sh_ or shFlags_. Both provide excellent examples of more advanced usage. shUnit2 was after all written to help with the unit testing problems that log4sh_ had. Function Reference ================== General Info ------------ Any string values passed should be properly quoted -- they should must be surrounded by single-quote (') or double-quote (") characters -- so that the shell will properly parse them. Asserts ------- ``assertEquals [message] expected actual`` Asserts that *expected* and *actual* are equal to one another. The *expected* and *actual* values can be either strings or integer values as both will be treated as strings. The *message* is optional, and must be quoted. ``assertNotEquals [message] expected actual`` Asserts that *unexpected* and *actual* are not equal to one another. The *unexpected* and *actual* values can be either strings or integer values as both will be treaded as strings. The *message* is optional, and must be quoted. ``assertSame [message] expected actual`` This function is functionally equivalent to ``assertEquals``. ``assertNotSame [message] unexpected actual`` This function is functionally equivalent to ``assertNotEquals``. ``assertNull [message] value`` Asserts that *value* is *null*, or in shell terms, a zero-length string. The *value* must be a string as an integer value does not translate into a zero-length string. The *message* is optional, and must be quoted. ``assertNotNull [message] value`` Asserts that *value* is *not null*, or in shell terms, a non-empty string. The *value* may be a string or an integer as the later will be parsed as a non-empty string value. The *message* is optional, and must be quoted. ``assertTrue [message] condition`` Asserts that a given shell test *condition* is *true*. The condition can be as simple as a shell *true* value (the value ``0`` -- equivalent to ``${SHUNIT_TRUE}``), or a more sophisticated shell conditional expression. The *message* is optional, and must be quoted. A sophisticated shell conditional expression is equivalent to what the **if** or **while** shell built-ins would use (more specifically, what the **test** command would use). Testing for example whether some value is greater than another value can be done this way. :: assertTrue "[ 34 -gt 23 ]" Testing for the ability to read a file can also be done. This particular test will fail. :: assertTrue 'test failed' "[ -r /some/non-existant/file' ]" As the expressions are standard shell **test** expressions, it is possible to string multiple expressions together with ``-a`` and ``-o`` in the standard fashion. This test will succeed as the entire expression evaluates to *true*. :: assertTrue 'test failed' '[ 1 -eq 1 -a 2 -eq 2 ]' *One word of warning: be very careful with your quoting as shell is not the most forgiving of bad quoting, and things will fail in strange ways.* ``assertFalse [message] condition`` Asserts that a given shell test *condition* is *false*. The condition can be as simple as a shell *false* value (the value ``1`` -- equivalent to ``${SHUNIT_FALSE}``), or a more sophisticated shell conditional expression. The *message* is optional, and must be quoted. *For examples of more sophisticated expressions, see ``assertTrue``.* Failures -------- Just to clarify, failures **do not** test the various arguments against one another. Failures simply fail, optionally with a message, and that is all they do. If you need to test arguments against one another, use asserts. If all failures do is fail, why might one use them? There are times when you may have some very complicated logic that you need to test, and the simple asserts provided are simply not adequate. You can do your own validation of the code, use an ``assertTrue ${SHUNIT_TRUE}`` if your own tests succeeded, and use a failure to record a failure. ``fail [message]`` Fails the test immediately. The *message* is optional, and must be quoted. ``failNotEquals [message] unexpected actual`` Fails the test immediately, reporting that the *unexpected* and *actual* values are not equal to one another. The *message* is optional, and must be quoted. *Note: no actual comparison of unexpected and actual is done.* ``failSame [message] expected actual`` Fails the test immediately, reporting that the *expected* and *actual* values are the same. The *message* is optional, and must be quoted. *Note: no actual comparison of expected and actual is done.* ``failNotSame [message] expected actual`` Fails the test immediately, reporting that the *expected* and *actual* values are not the same. The *message* is optional, and must be quoted. *Note: no actual comparison of expected and actual is done.* Setup/Teardown -------------- ``oneTimeSetUp`` This function can be be optionally overridden by the user in their test suite. If this function exists, it will be called once before any tests are run. It is useful to prepare a common environment for all tests. ``oneTimeTearDown`` This function can be be optionally overridden by the user in their test suite. If this function exists, it will be called once after all tests are completed. It is useful to clean up the environment after all tests. ``setUp`` This function can be be optionally overridden by the user in their test suite. If this function exists, it will be called before each test is run. It is useful to reset the environment before each test. ``tearDown`` This function can be be optionally overridden by the user in their test suite. If this function exists, it will be called after each test completes. It is useful to clean up the environment after each test. Skipping -------- ``startSkipping`` This function forces the remaining *assert* and *fail* functions to be "skipped", i.e. they will have no effect. Each function skipped will be recorded so that the total of asserts and fails will not be altered. ``endSkipping`` This function returns calls to the *assert* and *fail* functions to their default behavior, i.e. they will be called. ``isSkipping`` This function returns the current state of skipping. It can be compared against ``${SHUNIT_TRUE}`` or ``${SHUNIT_FALSE}`` if desired. Suites ------ The default behavior of shUnit2 is that all tests will be found dynamically. If you have a specific set of tests you want to run, or you don't want to use the standard naming scheme of prefixing your tests with ``test``, these functions are for you. Most users will never use them though. ``suite`` This function can be optionally overridden by the user in their test suite. If this function exists, it will be called when ``shunit2`` is sourced. If it does not exist, shUnit2 will search the parent script for all functions beginning with the word ``test``, and they will be added dynamically to the test suite. ``suite_addTest name`` This function adds a function named *name* to the list of tests scheduled for execution as part of this test suite. This function should only be called from within the ``suite()`` function. Advanced Usage ============== This section covers several advanced usage topics. Some constants you can use -------------------------- There are several constants provided by shUnit2 as variables that might be of use to you. Predefined ================== =========================================================== ``SHUNIT_VERSION`` The version of shUnit2 you are running. ``SHUNIT_TRUE`` Standard shell *true* value (the integer value 0). ``SHUNIT_FALSE`` Standard shell *false* value (the integer value 1). ``SHUNIT_ERROR`` The integer value 2. ``SHUNIT_TMPDIR`` Path to temporary directory that will be automatically cleaned up upon exit of shUnit2. ================== =========================================================== User defined ================== =========================================================== ``SHUNIT_PARENT`` The filename of the shell script containing the tests. This is needed specifically for Zsh support. ================== =========================================================== Error handling -------------- The constants values ``SHUNIT_TRUE``, ``SHUNIT_FALSE``, and ``SHUNIT_ERROR`` are returned from nearly every function to indicate the success or failure of the function. Additionally the variable ``flags_error`` is filled with a detailed error message if any function returns with a ``SHUNIT_ERROR`` value. Including Line Numbers in Asserts (Macros) ------------------------------------------ If you include lots of assert statements in an individual test function, it can become difficult to determine exactly which assert was thrown unless your messages are unique. To help somewhat, line numbers can be included in the assert messages. To enable this, a special shell "macro" must be used rather than the standard assert calls. *Shell doesn't actually have macros; the name is used here as the operation is similar to a standard macro.* For example, to include line numbers for a ``assertEquals()`` function call, replace the ``assertEquals()`` with ``${_ASSERT_EQUALS_}``. Example--Asserts with and without line numbers :: #! /bin/sh # file: examples/lineno_test.sh testLineNo() { # this assert will have line numbers included (e.g. "ASSERT:[123] ...") echo "ae: ${_ASSERT_EQUALS_}" ${_ASSERT_EQUALS_} 'not equal' 1 2 # this assert will not have line numbers included (e.g. "ASSERT: ...") assertEquals 'not equal' 1 2 } # load shunit2 . ../src/shell/shunit2 Notes: #. Due to how shell parses command-line arguments, all strings used with macros should be quoted twice. Namely, single-quotes must be converted to single-double-quotes, and vice-versa. If the string being passed is absolutely for sure not empty, the extra quoting is not necessary. Normal ``assertEquals`` call. :: assertEquals 'some message' 'x' '' Macro ``_ASSERT_EQUALS_`` call. Note the extra quoting around the *message* and the *null* value. :: _ASSERT_EQUALS_ '"some message"' 'x' '""' #. Line numbers are not supported in all shells. If a shell does not support them, no errors will be thrown. Supported shells include: **bash** (>=3.0), **ksh**, **pdksh**, and **zsh**. Test Skipping ------------- There are times where the test code you have written is just not applicable to the system you are running on. This section describes how to skip these tests but maintain the total test count. Probably the easiest example would be shell code that is meant to run under the **bash** shell, but the unit test is running under the Bourne shell. There are things that just won't work. The following test code demonstrates two sample functions, one that will be run under any shell, and the another that will run only under the **bash** shell. Example-- math include :: # available as examples/math.inc add_generic() { num_a=$1 num_b=$2 expr $1 + $2 } add_bash() { num_a=$1 num_b=$2 echo $(($1 + $2)) } And here is a corresponding unit test that correctly skips the ``add_bash()`` function when the unit test is not running under the **bash** shell. Example-- math unit test :: #! /bin/sh # available as examples/math_test.sh testAdding() { result=`add_generic 1 2` assertEquals \ "the result of '${result}' was wrong" \ 3 "${result}" # disable non-generic tests [ -z "${BASH_VERSION:-}" ] && startSkipping result=`add_bash 1 2` assertEquals \ "the result of '${result}' was wrong" \ 3 "${result}" } oneTimeSetUp() { # load include to test . ./math.inc } # load and run shUnit2 . ../src/shell/shunit2 Running the above test under the **bash** shell will result in the following output. :: $ /bin/bash math_test.sh testAdding Ran 1 test. OK But, running the test under any other Unix shell will result in the following output. :: $ /bin/ksh math_test.sh testAdding Ran 1 test. OK (skipped=1) As you can see, the total number of tests has not changed, but the report indicates that some tests were skipped. Skipping can be controlled with the following functions: ``startSkipping()``, ``stopSkipping()``, and ``isSkipping()``. Once skipping is enabled, it will remain enabled until the end of the current test function call, after which skipping is disabled. Appendix ======== Getting help ------------ For help, please send requests to either the shunit2-users@googlegroups.com mailing list (archives available on the web at http://groups.google.com/group/shunit2-users) or directly to Kate Ward . Zsh --- For compatibility with Zsh, there is one requirement that must be met -- the ``shwordsplit`` option must be set. There are three ways to accomplish this. #. In the unit-test script, add the following shell code snippet before sourcing the ``shunit2`` library. :: setopt shwordsplit #. When invoking **zsh** from either the command-line or as a script with ``#!``, add the ``-y`` parameter. :: #! /bin/zsh -y #. When invoking **zsh** from the command-line, add ``-o shwordsplit --`` as parameters before the script name. :: $ zsh -o shwordsplit -- some_script .. _log4sh: http://log4sh.sourceforge.net/ .. _log4j: http://logging.apache.org/ .. _JUnit: http://www.junit.org/ .. _PyUnit: http://pyunit.sourceforge.net/ .. _shFlags: http://shflags.googlecode.com/ .. _shUnit2: http://shunit2.googlecode.com/ .. _xUnit: http://en.wikipedia.org/wiki/XUnit .. generate HTML using rst2html from Docutils of .. http://docutils.sourceforge.net/ .. .. vim:fileencoding=latin1:ft=rst:spell:sts=2:sw=2:tw=80 .. $Revision: 233 $ git-ftp-1.0.2/tests/shunit2-2.1.6/examples/000077500000000000000000000000001246645256000201145ustar00rootroot00000000000000git-ftp-1.0.2/tests/shunit2-2.1.6/examples/equality_test.sh000077500000000000000000000001651246645256000233510ustar00rootroot00000000000000#! /bin/sh # file: examples/equality_test.sh testEquality() { assertEquals 1 1 } # load shunit2 . ../src/shunit2 git-ftp-1.0.2/tests/shunit2-2.1.6/examples/lineno_test.sh000077500000000000000000000006121246645256000227750ustar00rootroot00000000000000#! /bin/sh # file: examples/lineno_test.sh testLineNo() { # this assert will have line numbers included (e.g. "ASSERT:[123] ...") if # they are supported. echo "_ASSERT_EQUALS_ macro value: ${_ASSERT_EQUALS_}" ${_ASSERT_EQUALS_} 'not equal' 1 2 # this assert will not have line numbers included (e.g. "ASSERT: ...") assertEquals 'not equal' 1 2 } # load shunit2 . ../src/shunit2 git-ftp-1.0.2/tests/shunit2-2.1.6/examples/math.inc000066400000000000000000000002251246645256000215370ustar00rootroot00000000000000# available as examples/math.inc add_generic() { num_a=$1 num_b=$2 expr $1 + $2 } add_bash() { num_a=$1 num_b=$2 echo $(($1 + $2)) } git-ftp-1.0.2/tests/shunit2-2.1.6/examples/math_test.sh000077500000000000000000000007161246645256000224470ustar00rootroot00000000000000#! /bin/sh # available as examples/math_test.sh testAdding() { result=`add_generic 1 2` assertEquals \ "the result of '${result}' was wrong" \ 3 "${result}" # disable non-generic tests [ -z "${BASH_VERSION:-}" ] && startSkipping result=`add_bash 1 2` assertEquals \ "the result of '${result}' was wrong" \ 3 "${result}" } oneTimeSetUp() { # load include to test . ./math.inc } # load and run shUnit2 . ../src/shunit2 git-ftp-1.0.2/tests/shunit2-2.1.6/examples/mkdir_test.sh000077500000000000000000000044371246645256000226300ustar00rootroot00000000000000#!/bin/sh # vim:et:ft=sh:sts=2:sw=2 # # Copyright 2008 Kate Ward. All Rights Reserved. # Released under the LGPL (GNU Lesser General Public License) # # Author: kate.ward@forestent.com (Kate Ward) # # Example unit test for the mkdir command. # # There are times when an existing shell script needs to be tested. In this # example, we will test several aspects of the the mkdir command, but the # techniques could be used for any existing shell script. #----------------------------------------------------------------------------- # suite tests # testMissingDirectoryCreation() { ${mkdirCmd} "${testDir}" >${stdoutF} 2>${stderrF} rtrn=$? th_assertTrueWithNoOutput ${rtrn} "${stdoutF}" "${stderrF}" assertTrue 'directory missing' "[ -d '${testDir}' ]" } testExistingDirectoryCreationFails() { # create a directory to test against ${mkdirCmd} "${testDir}" # test for expected failure while trying to create directory that exists ${mkdirCmd} "${testDir}" >${stdoutF} 2>${stderrF} rtrn=$? assertFalse 'expecting return code of 1 (false)' ${rtrn} assertNull 'unexpected output to stdout' "`cat ${stdoutF}`" assertNotNull 'expected error message to stderr' "`cat ${stderrF}`" assertTrue 'directory missing' "[ -d '${testDir}' ]" } testRecursiveDirectoryCreation() { testDir2="${testDir}/test2" ${mkdirCmd} -p "${testDir2}" >${stdoutF} 2>${stderrF} rtrn=$? th_assertTrueWithNoOutput ${rtrn} "${stdoutF}" "${stderrF}" assertTrue 'first directory missing' "[ -d '${testDir}' ]" assertTrue 'second directory missing' "[ -d '${testDir2}' ]" } #----------------------------------------------------------------------------- # suite functions # th_assertTrueWithNoOutput() { th_return_=$1 th_stdout_=$2 th_stderr_=$3 assertFalse 'unexpected output to STDOUT' "[ -s '${th_stdout_}' ]" assertFalse 'unexpected output to STDERR' "[ -s '${th_stderr_}' ]" unset th_return_ th_stdout_ th_stderr_ } oneTimeSetUp() { outputDir="${SHUNIT_TMPDIR}/output" mkdir "${outputDir}" stdoutF="${outputDir}/stdout" stderrF="${outputDir}/stderr" mkdirCmd='mkdir' # save command name in variable to make future changes easy testDir="${SHUNIT_TMPDIR}/some_test_dir" } tearDown() { rm -fr "${testDir}" } # load and run shUnit2 [ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0 . ../src/shunit2 git-ftp-1.0.2/tests/shunit2-2.1.6/examples/party_test.sh000077500000000000000000000003371246645256000226540ustar00rootroot00000000000000#! /bin/sh # file: examples/party_test.sh testEquality() { assertEquals 1 1 } testPartyLikeItIs1999() { year=`date '+%Y'` assertEquals "It's not 1999 :-(" \ '1999' "${year}" } # load shunit2 . ../src/shunit2 git-ftp-1.0.2/tests/shunit2-2.1.6/lib/000077500000000000000000000000001246645256000170445ustar00rootroot00000000000000git-ftp-1.0.2/tests/shunit2-2.1.6/lib/shflags000066400000000000000000000747461246645256000204400ustar00rootroot00000000000000# $Id: shflags 138 2010-03-18 00:25:34Z kate.ward@forestent.com $ # vim:et:ft=sh:sts=2:sw=2 # # Copyright 2008 Kate Ward. All Rights Reserved. # Released under the LGPL (GNU Lesser General Public License) # # shFlags -- Advanced command-line flag library for Unix shell scripts. # http://code.google.com/p/shflags/ # # Author: kate.ward@forestent.com (Kate Ward) # # This module implements something like the google-gflags library available # from http://code.google.com/p/google-gflags/. # # FLAG TYPES: This is a list of the DEFINE_*'s that you can do. All flags take # a name, default value, help-string, and optional 'short' name (one-letter # name). Some flags have other arguments, which are described with the flag. # # DEFINE_string: takes any input, and intreprets it as a string. # # DEFINE_boolean: typically does not take any argument: say --myflag to set # FLAGS_myflag to true, or --nomyflag to set FLAGS_myflag to false. # Alternately, you can say # --myflag=true or --myflag=t or --myflag=0 or # --myflag=false or --myflag=f or --myflag=1 # Passing an option has the same affect as passing the option once. # # DEFINE_float: takes an input and intreprets it as a floating point number. As # shell does not support floats per-se, the input is merely validated as # being a valid floating point value. # # DEFINE_integer: takes an input and intreprets it as an integer. # # SPECIAL FLAGS: There are a few flags that have special meaning: # --help (or -?) prints a list of all the flags in a human-readable fashion # --flagfile=foo read flags from foo. (not implemented yet) # -- as in getopt(), terminates flag-processing # # EXAMPLE USAGE: # # -- begin hello.sh -- # #! /bin/sh # . ./shflags # DEFINE_string name 'world' "somebody's name" n # FLAGS "$@" || exit $? # eval set -- "${FLAGS_ARGV}" # echo "Hello, ${FLAGS_name}." # -- end hello.sh -- # # $ ./hello.sh -n Kate # Hello, Kate. # # NOTE: Not all systems include a getopt version that supports long flags. On # these systems, only short flags are recognized. #============================================================================== # shFlags # # Shared attributes: # flags_error: last error message # flags_return: last return value # # __flags_longNames: list of long names for all flags # __flags_shortNames: list of short names for all flags # __flags_boolNames: list of boolean flag names # # __flags_opts: options parsed by getopt # # Per-flag attributes: # FLAGS_: contains value of flag named 'flag_name' # __flags__default: the default flag value # __flags__help: the flag help string # __flags__short: the flag short name # __flags__type: the flag type # # Notes: # - lists of strings are space separated, and a null value is the '~' char. # return if FLAGS already loaded [ -n "${FLAGS_VERSION:-}" ] && return 0 FLAGS_VERSION='1.0.4pre' # return values FLAGS_TRUE=0 FLAGS_FALSE=1 FLAGS_ERROR=2 # reserved flag names FLAGS_RESERVED='ARGC ARGV ERROR FALSE HELP PARENT RESERVED TRUE VERSION' _flags_debug() { echo "flags:DEBUG $@" >&2; } _flags_warn() { echo "flags:WARN $@" >&2; } _flags_error() { echo "flags:ERROR $@" >&2; } _flags_fatal() { echo "flags:FATAL $@" >&2; } # specific shell checks if [ -n "${ZSH_VERSION:-}" ]; then setopt |grep "^shwordsplit$" >/dev/null if [ $? -ne ${FLAGS_TRUE} ]; then _flags_fatal 'zsh shwordsplit option is required for proper zsh operation' exit ${FLAGS_ERROR} fi if [ -z "${FLAGS_PARENT:-}" ]; then _flags_fatal "zsh does not pass \$0 through properly. please declare' \ \"FLAGS_PARENT=\$0\" before calling shFlags" exit ${FLAGS_ERROR} fi fi # # constants # # getopt version __FLAGS_GETOPT_VERS_STD=0 __FLAGS_GETOPT_VERS_ENH=1 __FLAGS_GETOPT_VERS_BSD=2 getopt >/dev/null 2>&1 case $? in 0) __FLAGS_GETOPT_VERS=${__FLAGS_GETOPT_VERS_STD} ;; # bsd getopt 2) # TODO(kward): look into '-T' option to test the internal getopt() version if [ "`getopt --version`" = '-- ' ]; then __FLAGS_GETOPT_VERS=${__FLAGS_GETOPT_VERS_STD} else __FLAGS_GETOPT_VERS=${__FLAGS_GETOPT_VERS_ENH} fi ;; *) _flags_fatal 'unable to determine getopt version' exit ${FLAGS_ERROR} ;; esac # getopt optstring lengths __FLAGS_OPTSTR_SHORT=0 __FLAGS_OPTSTR_LONG=1 __FLAGS_NULL='~' # flag info strings __FLAGS_INFO_DEFAULT='default' __FLAGS_INFO_HELP='help' __FLAGS_INFO_SHORT='short' __FLAGS_INFO_TYPE='type' # flag lengths __FLAGS_LEN_SHORT=0 __FLAGS_LEN_LONG=1 # flag types __FLAGS_TYPE_NONE=0 __FLAGS_TYPE_BOOLEAN=1 __FLAGS_TYPE_FLOAT=2 __FLAGS_TYPE_INTEGER=3 __FLAGS_TYPE_STRING=4 # set the constants readonly __flags_constants=`set |awk -F= '/^FLAGS_/ || /^__FLAGS_/ {print $1}'` for __flags_const in ${__flags_constants}; do # skip certain flags case ${__flags_const} in FLAGS_HELP) continue ;; FLAGS_PARENT) continue ;; esac # set flag readonly if [ -z "${ZSH_VERSION:-}" ]; then readonly ${__flags_const} else # handle zsh case ${ZSH_VERSION} in [123].*) readonly ${__flags_const} ;; *) readonly -g ${__flags_const} ;; # declare readonly constants globally esac fi done unset __flags_const __flags_constants # # internal variables # __flags_boolNames=' ' # space separated list of boolean flag names __flags_longNames=' ' # space separated list of long flag names __flags_shortNames=' ' # space separated list of short flag names __flags_columns='' # screen width in columns __flags_opts='' # temporary storage for parsed getopt flags #------------------------------------------------------------------------------ # private functions # # Define a flag. # # Calling this function will define the following info variables for the # specified flag: # FLAGS_flagname - the name for this flag (based upon the long flag name) # __flags__default - the default value # __flags_flagname_help - the help string # __flags_flagname_short - the single letter alias # __flags_flagname_type - the type of flag (one of __FLAGS_TYPE_*) # # Args: # _flags__type: integer: internal type of flag (__FLAGS_TYPE_*) # _flags__name: string: long flag name # _flags__default: default flag value # _flags__help: string: help string # _flags__short: string: (optional) short flag name # Returns: # integer: success of operation, or error _flags_define() { if [ $# -lt 4 ]; then flags_error='DEFINE error: too few arguments' flags_return=${FLAGS_ERROR} _flags_error "${flags_error}" return ${flags_return} fi _flags_type_=$1 _flags_name_=$2 _flags_default_=$3 _flags_help_=$4 _flags_short_=${5:-${__FLAGS_NULL}} _flags_return_=${FLAGS_TRUE} # TODO(kward): check for validity of the flag name (e.g. dashes) # check whether the flag name is reserved echo " ${FLAGS_RESERVED} " |grep " ${_flags_name_} " >/dev/null if [ $? -eq 0 ]; then flags_error="flag name (${_flags_name_}) is reserved" _flags_return_=${FLAGS_ERROR} fi # require short option for getopt that don't support long options if [ ${_flags_return_} -eq ${FLAGS_TRUE} \ -a ${__FLAGS_GETOPT_VERS} -ne ${__FLAGS_GETOPT_VERS_ENH} \ -a "${_flags_short_}" = "${__FLAGS_NULL}" ] then flags_error="short flag required for (${_flags_name_}) on this platform" _flags_return_=${FLAGS_ERROR} fi # check for existing long name definition if [ ${_flags_return_} -eq ${FLAGS_TRUE} ]; then if _flags_itemInList "${_flags_name_}" \ ${__flags_longNames} ${__flags_boolNames} then flags_error="flag name ([no]${_flags_name_}) already defined" _flags_warn "${flags_error}" _flags_return_=${FLAGS_FALSE} fi fi # check for existing short name definition if [ ${_flags_return_} -eq ${FLAGS_TRUE} \ -a "${_flags_short_}" != "${__FLAGS_NULL}" ] then if _flags_itemInList "${_flags_short_}" ${__flags_shortNames}; then flags_error="flag short name (${_flags_short_}) already defined" _flags_warn "${flags_error}" _flags_return_=${FLAGS_FALSE} fi fi # handle default value. note, on several occasions the 'if' portion of an # if/then/else contains just a ':' which does nothing. a binary reversal via # '!' is not done because it does not work on all shells. if [ ${_flags_return_} -eq ${FLAGS_TRUE} ]; then case ${_flags_type_} in ${__FLAGS_TYPE_BOOLEAN}) if _flags_validateBoolean "${_flags_default_}"; then case ${_flags_default_} in true|t|0) _flags_default_=${FLAGS_TRUE} ;; false|f|1) _flags_default_=${FLAGS_FALSE} ;; esac else flags_error="invalid default flag value '${_flags_default_}'" _flags_return_=${FLAGS_ERROR} fi ;; ${__FLAGS_TYPE_FLOAT}) if _flags_validateFloat "${_flags_default_}"; then : else flags_error="invalid default flag value '${_flags_default_}'" _flags_return_=${FLAGS_ERROR} fi ;; ${__FLAGS_TYPE_INTEGER}) if _flags_validateInteger "${_flags_default_}"; then : else flags_error="invalid default flag value '${_flags_default_}'" _flags_return_=${FLAGS_ERROR} fi ;; ${__FLAGS_TYPE_STRING}) ;; # everything in shell is a valid string *) flags_error="unrecognized flag type '${_flags_type_}'" _flags_return_=${FLAGS_ERROR} ;; esac fi if [ ${_flags_return_} -eq ${FLAGS_TRUE} ]; then # store flag information eval "FLAGS_${_flags_name_}='${_flags_default_}'" eval "__flags_${_flags_name_}_${__FLAGS_INFO_TYPE}=${_flags_type_}" eval "__flags_${_flags_name_}_${__FLAGS_INFO_DEFAULT}=\ \"${_flags_default_}\"" eval "__flags_${_flags_name_}_${__FLAGS_INFO_HELP}=\"${_flags_help_}\"" eval "__flags_${_flags_name_}_${__FLAGS_INFO_SHORT}='${_flags_short_}'" # append flag name(s) to list of names __flags_longNames="${__flags_longNames}${_flags_name_} " __flags_shortNames="${__flags_shortNames}${_flags_short_} " [ ${_flags_type_} -eq ${__FLAGS_TYPE_BOOLEAN} ] && \ __flags_boolNames="${__flags_boolNames}no${_flags_name_} " fi flags_return=${_flags_return_} unset _flags_default_ _flags_help_ _flags_name_ _flags_return_ _flags_short_ \ _flags_type_ [ ${flags_return} -eq ${FLAGS_ERROR} ] && _flags_error "${flags_error}" return ${flags_return} } # Return valid getopt options using currently defined list of long options. # # This function builds a proper getopt option string for short (and long) # options, using the current list of long options for reference. # # Args: # _flags_optStr: integer: option string type (__FLAGS_OPTSTR_*) # Output: # string: generated option string for getopt # Returns: # boolean: success of operation (always returns True) _flags_genOptStr() { _flags_optStrType_=$1 _flags_opts_='' for _flags_flag_ in ${__flags_longNames}; do _flags_type_=`_flags_getFlagInfo ${_flags_flag_} ${__FLAGS_INFO_TYPE}` case ${_flags_optStrType_} in ${__FLAGS_OPTSTR_SHORT}) _flags_shortName_=`_flags_getFlagInfo \ ${_flags_flag_} ${__FLAGS_INFO_SHORT}` if [ "${_flags_shortName_}" != "${__FLAGS_NULL}" ]; then _flags_opts_="${_flags_opts_}${_flags_shortName_}" # getopt needs a trailing ':' to indicate a required argument [ ${_flags_type_} -ne ${__FLAGS_TYPE_BOOLEAN} ] && \ _flags_opts_="${_flags_opts_}:" fi ;; ${__FLAGS_OPTSTR_LONG}) _flags_opts_="${_flags_opts_:+${_flags_opts_},}${_flags_flag_}" # getopt needs a trailing ':' to indicate a required argument [ ${_flags_type_} -ne ${__FLAGS_TYPE_BOOLEAN} ] && \ _flags_opts_="${_flags_opts_}:" ;; esac done echo "${_flags_opts_}" unset _flags_flag_ _flags_opts_ _flags_optStrType_ _flags_shortName_ \ _flags_type_ return ${FLAGS_TRUE} } # Returns flag details based on a flag name and flag info. # # Args: # string: long flag name # string: flag info (see the _flags_define function for valid info types) # Output: # string: value of dereferenced flag variable # Returns: # integer: one of FLAGS_{TRUE|FALSE|ERROR} _flags_getFlagInfo() { _flags_name_=$1 _flags_info_=$2 _flags_nameVar_="__flags_${_flags_name_}_${_flags_info_}" _flags_strToEval_="_flags_value_=\"\${${_flags_nameVar_}:-}\"" eval "${_flags_strToEval_}" if [ -n "${_flags_value_}" ]; then flags_return=${FLAGS_TRUE} else # see if the _flags_name_ variable is a string as strings can be empty... # note: the DRY principle would say to have this function call itself for # the next three lines, but doing so results in an infinite loop as an # invalid _flags_name_ will also not have the associated _type variable. # Because it doesn't (it will evaluate to an empty string) the logic will # try to find the _type variable of the _type variable, and so on. Not so # good ;-) _flags_typeVar_="__flags_${_flags_name_}_${__FLAGS_INFO_TYPE}" _flags_strToEval_="_flags_type_=\"\${${_flags_typeVar_}:-}\"" eval "${_flags_strToEval_}" if [ "${_flags_type_}" = "${__FLAGS_TYPE_STRING}" ]; then flags_return=${FLAGS_TRUE} else flags_return=${FLAGS_ERROR} flags_error="invalid flag name (${_flags_nameVar_})" fi fi echo "${_flags_value_}" unset _flags_info_ _flags_name_ _flags_strToEval_ _flags_type_ _flags_value_ \ _flags_nameVar_ _flags_typeVar_ [ ${flags_return} -eq ${FLAGS_ERROR} ] && _flags_error "${flags_error}" return ${flags_return} } # check for presense of item in a list. passed a string (e.g. 'abc'), this # function will determine if the string is present in the list of strings (e.g. # ' foo bar abc '). # # Args: # _flags__str: string: string to search for in a list of strings # unnamed: list: list of strings # Returns: # boolean: true if item is in the list _flags_itemInList() { _flags_str_=$1 shift echo " ${*:-} " |grep " ${_flags_str_} " >/dev/null if [ $? -eq 0 ]; then flags_return=${FLAGS_TRUE} else flags_return=${FLAGS_FALSE} fi unset _flags_str_ return ${flags_return} } # Returns the width of the current screen. # # Output: # integer: width in columns of the current screen. _flags_columns() { if [ -z "${__flags_columns}" ]; then # determine the value and store it if eval stty size >/dev/null 2>&1; then # stty size worked :-) set -- `stty size` __flags_columns=$2 elif eval tput cols >/dev/null 2>&1; then set -- `tput cols` __flags_columns=$1 else __flags_columns=80 # default terminal width fi fi echo ${__flags_columns} } # Validate a boolean. # # Args: # _flags__bool: boolean: value to validate # Returns: # bool: true if the value is a valid boolean _flags_validateBoolean() { _flags_bool_=$1 flags_return=${FLAGS_TRUE} case "${_flags_bool_}" in true|t|0) ;; false|f|1) ;; *) flags_return=${FLAGS_FALSE} ;; esac unset _flags_bool_ return ${flags_return} } # Validate a float. # # Args: # _flags__float: float: value to validate # Returns: # bool: true if the value is a valid float _flags_validateFloat() { _flags_float_=$1 if _flags_validateInteger ${_flags_float_}; then flags_return=${FLAGS_TRUE} else flags_return=${FLAGS_TRUE} case ${_flags_float_} in -*) # negative floats _flags_test_=`expr -- "${_flags_float_}" :\ '\(-[0-9][0-9]*\.[0-9][0-9]*\)'` ;; *) # positive floats _flags_test_=`expr -- "${_flags_float_}" :\ '\([0-9][0-9]*\.[0-9][0-9]*\)'` ;; esac [ "${_flags_test_}" != "${_flags_float_}" ] && flags_return=${FLAGS_FALSE} fi unset _flags_float_ _flags_test_ return ${flags_return} } # Validate an integer. # # Args: # _flags__integer: interger: value to validate # Returns: # bool: true if the value is a valid integer _flags_validateInteger() { _flags_int_=$1 flags_return=${FLAGS_TRUE} case ${_flags_int_} in -*) # negative ints _flags_test_=`expr -- "${_flags_int_}" : '\(-[0-9][0-9]*\)'` ;; *) # positive ints _flags_test_=`expr -- "${_flags_int_}" : '\([0-9][0-9]*\)'` ;; esac [ "${_flags_test_}" != "${_flags_int_}" ] && flags_return=${FLAGS_FALSE} unset _flags_int_ _flags_test_ return ${flags_return} } # Parse command-line options using the standard getopt. # # Note: the flag options are passed around in the global __flags_opts so that # the formatting is not lost due to shell parsing and such. # # Args: # @: varies: command-line options to parse # Returns: # integer: a FLAGS success condition _flags_getoptStandard() { flags_return=${FLAGS_TRUE} _flags_shortOpts_=`_flags_genOptStr ${__FLAGS_OPTSTR_SHORT}` # check for spaces in passed options for _flags_opt_ in "$@"; do # note: the silliness with the x's is purely for ksh93 on Ubuntu 6.06 _flags_match_=`echo "x${_flags_opt_}x" |sed 's/ //g'` if [ "${_flags_match_}" != "x${_flags_opt_}x" ]; then flags_error='the available getopt does not support spaces in options' flags_return=${FLAGS_ERROR} break fi done if [ ${flags_return} -eq ${FLAGS_TRUE} ]; then __flags_opts=`getopt ${_flags_shortOpts_} $@ 2>&1` _flags_rtrn_=$? if [ ${_flags_rtrn_} -ne ${FLAGS_TRUE} ]; then _flags_warn "${__flags_opts}" flags_error='unable to parse provided options with getopt.' flags_return=${FLAGS_ERROR} fi fi unset _flags_match_ _flags_opt_ _flags_rtrn_ _flags_shortOpts_ return ${flags_return} } # Parse command-line options using the enhanced getopt. # # Note: the flag options are passed around in the global __flags_opts so that # the formatting is not lost due to shell parsing and such. # # Args: # @: varies: command-line options to parse # Returns: # integer: a FLAGS success condition _flags_getoptEnhanced() { flags_return=${FLAGS_TRUE} _flags_shortOpts_=`_flags_genOptStr ${__FLAGS_OPTSTR_SHORT}` _flags_boolOpts_=`echo "${__flags_boolNames}" \ |sed 's/^ *//;s/ *$//;s/ /,/g'` _flags_longOpts_=`_flags_genOptStr ${__FLAGS_OPTSTR_LONG}` __flags_opts=`getopt \ -o ${_flags_shortOpts_} \ -l "${_flags_longOpts_},${_flags_boolOpts_}" \ -- "$@" 2>&1` _flags_rtrn_=$? if [ ${_flags_rtrn_} -ne ${FLAGS_TRUE} ]; then _flags_warn "${__flags_opts}" flags_error='unable to parse provided options with getopt.' flags_return=${FLAGS_ERROR} fi unset _flags_boolOpts_ _flags_longOpts_ _flags_rtrn_ _flags_shortOpts_ return ${flags_return} } # Dynamically parse a getopt result and set appropriate variables. # # This function does the actual conversion of getopt output and runs it through # the standard case structure for parsing. The case structure is actually quite # dynamic to support any number of flags. # # Args: # argc: int: original command-line argument count # @: varies: output from getopt parsing # Returns: # integer: a FLAGS success condition _flags_parseGetopt() { _flags_argc_=$1 shift flags_return=${FLAGS_TRUE} if [ ${__FLAGS_GETOPT_VERS} -ne ${__FLAGS_GETOPT_VERS_ENH} ]; then set -- $@ else # note the quotes around the `$@' -- they are essential! eval set -- "$@" fi # provide user with number of arguments to shift by later # NOTE: the FLAGS_ARGC variable is obsolete as of 1.0.3 because it does not # properly give user access to non-flag arguments mixed in between flag # arguments. Its usage was replaced by FLAGS_ARGV, and it is being kept only # for backwards compatibility reasons. FLAGS_ARGC=`expr $# - 1 - ${_flags_argc_}` # handle options. note options with values must do an additional shift while true; do _flags_opt_=$1 _flags_arg_=${2:-} _flags_type_=${__FLAGS_TYPE_NONE} _flags_name_='' # determine long flag name case "${_flags_opt_}" in --) shift; break ;; # discontinue option parsing --*) # long option _flags_opt_=`expr -- "${_flags_opt_}" : '--\(.*\)'` _flags_len_=${__FLAGS_LEN_LONG} if _flags_itemInList "${_flags_opt_}" ${__flags_longNames}; then _flags_name_=${_flags_opt_} else # check for negated long boolean version if _flags_itemInList "${_flags_opt_}" ${__flags_boolNames}; then _flags_name_=`expr -- "${_flags_opt_}" : 'no\(.*\)'` _flags_type_=${__FLAGS_TYPE_BOOLEAN} _flags_arg_=${__FLAGS_NULL} fi fi ;; -*) # short option _flags_opt_=`expr -- "${_flags_opt_}" : '-\(.*\)'` _flags_len_=${__FLAGS_LEN_SHORT} if _flags_itemInList "${_flags_opt_}" ${__flags_shortNames}; then # yes. match short name to long name. note purposeful off-by-one # (too high) with awk calculations. _flags_pos_=`echo "${__flags_shortNames}" \ |awk 'BEGIN{RS=" ";rn=0}$0==e{rn=NR}END{print rn}' \ e=${_flags_opt_}` _flags_name_=`echo "${__flags_longNames}" \ |awk 'BEGIN{RS=" "}rn==NR{print $0}' rn="${_flags_pos_}"` fi ;; esac # die if the flag was unrecognized if [ -z "${_flags_name_}" ]; then flags_error="unrecognized option (${_flags_opt_})" flags_return=${FLAGS_ERROR} break fi # set new flag value [ ${_flags_type_} -eq ${__FLAGS_TYPE_NONE} ] && \ _flags_type_=`_flags_getFlagInfo \ "${_flags_name_}" ${__FLAGS_INFO_TYPE}` case ${_flags_type_} in ${__FLAGS_TYPE_BOOLEAN}) if [ ${_flags_len_} -eq ${__FLAGS_LEN_LONG} ]; then if [ "${_flags_arg_}" != "${__FLAGS_NULL}" ]; then eval "FLAGS_${_flags_name_}=${FLAGS_TRUE}" else eval "FLAGS_${_flags_name_}=${FLAGS_FALSE}" fi else _flags_strToEval_="_flags_val_=\ \${__flags_${_flags_name_}_${__FLAGS_INFO_DEFAULT}}" eval "${_flags_strToEval_}" if [ ${_flags_val_} -eq ${FLAGS_FALSE} ]; then eval "FLAGS_${_flags_name_}=${FLAGS_TRUE}" else eval "FLAGS_${_flags_name_}=${FLAGS_FALSE}" fi fi ;; ${__FLAGS_TYPE_FLOAT}) if _flags_validateFloat "${_flags_arg_}"; then eval "FLAGS_${_flags_name_}='${_flags_arg_}'" else flags_error="invalid float value (${_flags_arg_})" flags_return=${FLAGS_ERROR} break fi ;; ${__FLAGS_TYPE_INTEGER}) if _flags_validateInteger "${_flags_arg_}"; then eval "FLAGS_${_flags_name_}='${_flags_arg_}'" else flags_error="invalid integer value (${_flags_arg_})" flags_return=${FLAGS_ERROR} break fi ;; ${__FLAGS_TYPE_STRING}) eval "FLAGS_${_flags_name_}='${_flags_arg_}'" ;; esac # handle special case help flag if [ "${_flags_name_}" = 'help' ]; then if [ ${FLAGS_help} -eq ${FLAGS_TRUE} ]; then flags_help flags_error='help requested' flags_return=${FLAGS_FALSE} break fi fi # shift the option and non-boolean arguements out. shift [ ${_flags_type_} != ${__FLAGS_TYPE_BOOLEAN} ] && shift done # give user back non-flag arguments FLAGS_ARGV='' while [ $# -gt 0 ]; do FLAGS_ARGV="${FLAGS_ARGV:+${FLAGS_ARGV} }'$1'" shift done unset _flags_arg_ _flags_len_ _flags_name_ _flags_opt_ _flags_pos_ \ _flags_strToEval_ _flags_type_ _flags_val_ return ${flags_return} } #------------------------------------------------------------------------------ # public functions # # A basic boolean flag. Boolean flags do not take any arguments, and their # value is either 1 (false) or 0 (true). For long flags, the false value is # specified on the command line by prepending the word 'no'. With short flags, # the presense of the flag toggles the current value between true and false. # Specifying a short boolean flag twice on the command results in returning the # value back to the default value. # # A default value is required for boolean flags. # # For example, lets say a Boolean flag was created whose long name was 'update' # and whose short name was 'x', and the default value was 'false'. This flag # could be explicitly set to 'true' with '--update' or by '-x', and it could be # explicitly set to 'false' with '--noupdate'. DEFINE_boolean() { _flags_define ${__FLAGS_TYPE_BOOLEAN} "$@"; } # Other basic flags. DEFINE_float() { _flags_define ${__FLAGS_TYPE_FLOAT} "$@"; } DEFINE_integer() { _flags_define ${__FLAGS_TYPE_INTEGER} "$@"; } DEFINE_string() { _flags_define ${__FLAGS_TYPE_STRING} "$@"; } # Parse the flags. # # Args: # unnamed: list: command-line flags to parse # Returns: # integer: success of operation, or error FLAGS() { # define a standard 'help' flag if one isn't already defined [ -z "${__flags_help_type:-}" ] && \ DEFINE_boolean 'help' false 'show this help' 'h' # parse options if [ $# -gt 0 ]; then if [ ${__FLAGS_GETOPT_VERS} -ne ${__FLAGS_GETOPT_VERS_ENH} ]; then _flags_getoptStandard "$@" else _flags_getoptEnhanced "$@" fi flags_return=$? else # nothing passed; won't bother running getopt __flags_opts='--' flags_return=${FLAGS_TRUE} fi if [ ${flags_return} -eq ${FLAGS_TRUE} ]; then _flags_parseGetopt $# "${__flags_opts}" flags_return=$? fi [ ${flags_return} -eq ${FLAGS_ERROR} ] && _flags_fatal "${flags_error}" return ${flags_return} } # This is a helper function for determining the `getopt` version for platforms # where the detection isn't working. It simply outputs debug information that # can be included in a bug report. # # Args: # none # Output: # debug info that can be included in a bug report # Returns: # nothing flags_getoptInfo() { # platform info _flags_debug "uname -a: `uname -a`" _flags_debug "PATH: ${PATH}" # shell info if [ -n "${BASH_VERSION:-}" ]; then _flags_debug 'shell: bash' _flags_debug "BASH_VERSION: ${BASH_VERSION}" elif [ -n "${ZSH_VERSION:-}" ]; then _flags_debug 'shell: zsh' _flags_debug "ZSH_VERSION: ${ZSH_VERSION}" fi # getopt info getopt >/dev/null _flags_getoptReturn=$? _flags_debug "getopt return: ${_flags_getoptReturn}" _flags_debug "getopt --version: `getopt --version 2>&1`" unset _flags_getoptReturn } # Returns whether the detected getopt version is the enhanced version. # # Args: # none # Output: # none # Returns: # bool: true if getopt is the enhanced version flags_getoptIsEnh() { test ${__FLAGS_GETOPT_VERS} -eq ${__FLAGS_GETOPT_VERS_ENH} } # Returns whether the detected getopt version is the standard version. # # Args: # none # Returns: # bool: true if getopt is the standard version flags_getoptIsStd() { test ${__FLAGS_GETOPT_VERS} -eq ${__FLAGS_GETOPT_VERS_STD} } # This is effectively a 'usage()' function. It prints usage information and # exits the program with ${FLAGS_FALSE} if it is ever found in the command line # arguments. Note this function can be overridden so other apps can define # their own --help flag, replacing this one, if they want. # # Args: # none # Returns: # integer: success of operation (always returns true) flags_help() { if [ -n "${FLAGS_HELP:-}" ]; then echo "${FLAGS_HELP}" >&2 else echo "USAGE: ${FLAGS_PARENT:-$0} [flags] args" >&2 fi if [ -n "${__flags_longNames}" ]; then echo 'flags:' >&2 for flags_name_ in ${__flags_longNames}; do flags_flagStr_='' flags_boolStr_='' flags_default_=`_flags_getFlagInfo \ "${flags_name_}" ${__FLAGS_INFO_DEFAULT}` flags_help_=`_flags_getFlagInfo \ "${flags_name_}" ${__FLAGS_INFO_HELP}` flags_short_=`_flags_getFlagInfo \ "${flags_name_}" ${__FLAGS_INFO_SHORT}` flags_type_=`_flags_getFlagInfo \ "${flags_name_}" ${__FLAGS_INFO_TYPE}` [ "${flags_short_}" != "${__FLAGS_NULL}" ] \ && flags_flagStr_="-${flags_short_}" if [ ${__FLAGS_GETOPT_VERS} -eq ${__FLAGS_GETOPT_VERS_ENH} ]; then [ "${flags_short_}" != "${__FLAGS_NULL}" ] \ && flags_flagStr_="${flags_flagStr_}," [ ${flags_type_} -eq ${__FLAGS_TYPE_BOOLEAN} ] \ && flags_boolStr_='[no]' flags_flagStr_="${flags_flagStr_}--${flags_boolStr_}${flags_name_}:" fi case ${flags_type_} in ${__FLAGS_TYPE_BOOLEAN}) if [ ${flags_default_} -eq ${FLAGS_TRUE} ]; then flags_defaultStr_='true' else flags_defaultStr_='false' fi ;; ${__FLAGS_TYPE_FLOAT}|${__FLAGS_TYPE_INTEGER}) flags_defaultStr_=${flags_default_} ;; ${__FLAGS_TYPE_STRING}) flags_defaultStr_="'${flags_default_}'" ;; esac flags_defaultStr_="(default: ${flags_defaultStr_})" flags_helpStr_=" ${flags_flagStr_} ${flags_help_} ${flags_defaultStr_}" flags_helpStrLen_=`expr -- "${flags_helpStr_}" : '.*'` flags_columns_=`_flags_columns` if [ ${flags_helpStrLen_} -lt ${flags_columns_} ]; then echo "${flags_helpStr_}" >&2 else echo " ${flags_flagStr_} ${flags_help_}" >&2 # note: the silliness with the x's is purely for ksh93 on Ubuntu 6.06 # because it doesn't like empty strings when used in this manner. flags_emptyStr_="`echo \"x${flags_flagStr_}x\" \ |awk '{printf "%"length($0)-2"s", ""}'`" flags_helpStr_=" ${flags_emptyStr_} ${flags_defaultStr_}" flags_helpStrLen_=`expr -- "${flags_helpStr_}" : '.*'` if [ ${__FLAGS_GETOPT_VERS} -eq ${__FLAGS_GETOPT_VERS_STD} \ -o ${flags_helpStrLen_} -lt ${flags_columns_} ]; then # indented to match help string echo "${flags_helpStr_}" >&2 else # indented four from left to allow for longer defaults as long flag # names might be used too, making things too long echo " ${flags_defaultStr_}" >&2 fi fi done fi unset flags_boolStr_ flags_default_ flags_defaultStr_ flags_emptyStr_ \ flags_flagStr_ flags_help_ flags_helpStr flags_helpStrLen flags_name_ \ flags_columns_ flags_short_ flags_type_ return ${FLAGS_TRUE} } # Reset shflags back to an uninitialized state. # # Args: # none # Returns: # nothing flags_reset() { for flags_name_ in ${__flags_longNames}; do flags_strToEval_="unset FLAGS_${flags_name_}" for flags_type_ in \ ${__FLAGS_INFO_DEFAULT} \ ${__FLAGS_INFO_HELP} \ ${__FLAGS_INFO_SHORT} \ ${__FLAGS_INFO_TYPE} do flags_strToEval_=\ "${flags_strToEval_} __flags_${flags_name_}_${flags_type_}" done eval ${flags_strToEval_} done # reset internal variables __flags_boolNames=' ' __flags_longNames=' ' __flags_shortNames=' ' unset flags_name_ flags_type_ flags_strToEval_ } git-ftp-1.0.2/tests/shunit2-2.1.6/lib/shlib000066400000000000000000000022351246645256000200720ustar00rootroot00000000000000# $Id: shlib 14 2007-02-18 19:43:41Z sfsetse $ # vim:et:ft=sh:sts=2:sw=2 # # Copyright 2008 Kate Ward. All Rights Reserved. # Released under the LGPL (GNU Lesser General Public License). # Author: kate.ward@forestent.com (Kate Ward) # # Library of shell functions. # Convert a relative path into it's absolute equivalent. # # This function will automatically prepend the current working directory if the # path is not already absolute. It then removes all parent references (../) to # reconstruct the proper absolute path. # # Args: # shlib_path_: string: relative path # Outputs: # string: absolute path shlib_relToAbsPath() { shlib_path_=$1 # prepend current directory to relative paths echo "${shlib_path_}" |grep '^/' >/dev/null 2>&1 \ || shlib_path_="`pwd`/${shlib_path_}" # clean up the path. if all seds supported true regular expressions, then # this is what it would be: shlib_old_=${shlib_path_} while true; do shlib_new_=`echo "${shlib_old_}" |sed 's/[^/]*\/\.\.\/*//g;s/\/\.\//\//'` [ "${shlib_old_}" = "${shlib_new_}" ] && break shlib_old_=${shlib_new_} done echo "${shlib_new_}" unset shlib_path_ shlib_old_ shlib_new_ } git-ftp-1.0.2/tests/shunit2-2.1.6/lib/versions000077500000000000000000000133761246645256000206540ustar00rootroot00000000000000#! /bin/sh # $Id: versions 100 2008-11-15 20:24:03Z kate.ward@forestent.com $ # vim:et:ft=sh:sts=2:sw=2 # # Copyright 2008 Kate Ward. All Rights Reserved. # Released under the LGPL (GNU Lesser General Public License) # # Author: kate.ward@forestent.com (Kate Ward) # # This library provides reusable functions that determine actual names and # versions of installed shells and the OS. The library can also be run as a # script if set execuatable. ARGV0=`basename "$0"` LSB_RELEASE='/etc/lsb-release' VERSIONS_SHELLS="/bin/bash /bin/dash /bin/ksh /bin/pdksh /bin/sh /bin/zsh" TRUE=0 FALSE=1 ERROR=2 __versions_haveStrings=${ERROR} #------------------------------------------------------------------------------ # functions # versions_osName() { os_name_='unrecognized' os_system_=`uname -s` case ${os_system_} in CYGWIN_NT-*) os_name_='Cygwin' ;; Darwin) os_name_='Mac OS X' ;; FreeBSD) os_name_='FreeBSD' ;; Linux) os_name_='Linux' ;; SunOS) if grep 'OpenSolaris' /etc/release >/dev/null; then os_name_='OpenSolaris' else os_name_='Solaris' fi ;; esac echo ${os_name_} unset os_name_ os_system_ } versions_osVersion() { os_version_='unrecognized' os_system_=`uname -s` os_release_=`uname -r` case ${os_system_} in CYGWIN_NT-*) os_version_=`expr "${os_release_}" : '\([0-9]*\.[0-9]\.[0-9]*\).*'` ;; Darwin) major_='10' sub_=`echo ${os_release_} |sed 's/^[0-9]*\.\([0-9]*\)\.[0-9]*$/\1/'` case ${os_release_} in 8.*) minor_='4' ;; 9.*) minor_='5' ;; 10.*) minor_='6' ;; *) minor_='X'; sub_='X' ;; esac os_version_="${major_}.${minor_}.${sub_}" ;; FreeBSD) os_version_=`expr "${os_release_}" : '\([0-9]*\.[0-9]*\)-.*'` ;; Linux) if [ -r "${LSB_RELEASE}" ]; then if grep -q 'DISTRIB_ID=Ubuntu' "${LSB_RELEASE}"; then os_version_=`cat "${LSB_RELEASE}" \ |awk -F= '$1~/DISTRIB_DESCRIPTION/{print $2}' \ |sed 's/"//g;s/ /-/g'` fi elif [ -r '/etc/redhat-release' ]; then os_version_=`cat /etc/redhat-release` fi ;; SunOS) if grep 'OpenSolaris' /etc/release >/dev/null; then os_version_=`grep 'OpenSolaris' /etc/release |awk '{print $2"("$3")"}'` else major_=`echo ${os_release_} |sed 's/[0-9]*\.\([0-9]*\)/\1/'` minor_=`grep Solaris /etc/release |sed 's/[^u]*\(u[0-9]*\).*/\1/'` os_version_="${major_}${minor_}" fi ;; esac echo ${os_version_} unset os_name_ os_release_ os_version_ major_ minor_ sub_ } versions_shellVersion() { shell_=$1 if [ ! -x "${shell_}" ]; then echo 'not installed' return fi version_='' case ${shell_} in */sh) # TODO(kward): fix this ## this could be one of any number of shells. try until one fits. #version_=`versions_shell_bash ${shell_}` ## dash cannot be self determined yet #[ -z "${version_}" ] && version_=`versions_shell_ksh ${shell_}` ## pdksh is covered in versions_shell_ksh() #[ -z "${version_}" ] && version_=`versions_shell_zsh ${shell_}` ;; */bash) version_=`versions_shell_bash ${shell_}` ;; */dash) # simply assuming Ubuntu Linux until somebody comes up with a better # test. the following test will return an empty string if dash is not # installed. version_=`versions_shell_dash` ;; */ksh) version_=`versions_shell_ksh ${shell_}` ;; */pdksh) version_=`versions_shell_pdksh ${shell_}` ;; */zsh) version_=`versions_shell_zsh ${shell_}` ;; *) version_='invalid' esac echo ${version_:-unknown} unset shell_ version_ } versions_shell_bash() { $1 --version 2>&1 |grep 'GNU bash' |sed 's/.*version \([^ ]*\).*/\1/' } versions_shell_dash() { eval dpkg >/dev/null 2>&1 [ $? -eq 127 ] && return # return if dpkg not found dpkg -l |grep ' dash ' |awk '{print $3}' } versions_shell_ksh() { versions_shell_=$1 # see if --version gives a result versions_version_=`${versions_shell_} --version 2>&1 \ |sed 's/.*\([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\).*/\1/'` # --version didn't work... look into the binary if [ $? -ne ${TRUE} ]; then _versions_have_strings versions_version_=`strings ${versions_shell_} 2>&1 \ |grep Version \ |sed 's/^.*Version \(.*\)$/\1/;s/ s+ \$$//;s/ /-/g'` [ -z "${versions_version_}" ] \ && versions_version_=`versions_shell_pdksh ${versions_shell_}` fi echo ${versions_version_} unset versions_shell_ versions_version_ } versions_shell_pdksh() { _versions_have_strings strings $1 2>&1 \ |grep 'PD KSH' \ |sed -e 's/.*PD KSH \(.*\)/\1/;s/ /-/g' } versions_shell_zsh() { versions_shell_=$1 versions_version_=`${versions_shell_} --version 2>&1 |awk '{print $2}'` if [ $? -ne ${TRUE} ]; then versions_version_=`echo 'echo ${ZSH_VERSION}' |${versions_shell_}` fi echo ${versions_version_} unset versions_shell_ versions_version_ } # Determine if the 'strings' binary installed. _versions_have_strings() { [ ${__versions_haveStrings} -ne ${ERROR} ] && return eval strings /dev/null >/dev/null 2>&1 if [ $? -eq 0 ]; then __versions_haveStrings=${TRUE} else echo 'WARN: strings not installed. try installing binutils?' >&2 __versions_haveStrings=${FALSE} fi } #------------------------------------------------------------------------------ # main # versions_main() { # treat unset variables as an error set -u os_name=`versions_osName` os_version=`versions_osVersion` echo "os: ${os_name} version: ${os_version}" for shell in ${VERSIONS_SHELLS}; do shell_version=`versions_shellVersion ${shell}` echo "shell: ${shell} version: ${shell_version}" done } if [ "${ARGV0}" = 'versions' ]; then versions_main "$@" fi git-ftp-1.0.2/tests/shunit2-2.1.6/src/000077500000000000000000000000001246645256000170655ustar00rootroot00000000000000git-ftp-1.0.2/tests/shunit2-2.1.6/src/shunit2000077500000000000000000000701011246645256000204060ustar00rootroot00000000000000#! /bin/sh # $Id: shunit2 335 2011-05-01 20:10:33Z kate.ward@forestent.com $ # vim:et:ft=sh:sts=2:sw=2 # # Copyright 2008 Kate Ward. All Rights Reserved. # Released under the LGPL (GNU Lesser General Public License) # # shUnit2 -- Unit testing framework for Unix shell scripts. # http://code.google.com/p/shunit2/ # # Author: kate.ward@forestent.com (Kate Ward) # # shUnit2 is a xUnit based unit test framework for Bourne shell scripts. It is # based on the popular JUnit unit testing framework for Java. # return if shunit already loaded [ -n "${SHUNIT_VERSION:-}" ] && exit 0 SHUNIT_VERSION='2.1.6' SHUNIT_TRUE=0 SHUNIT_FALSE=1 SHUNIT_ERROR=2 # enable strict mode by default SHUNIT_STRICT=${SHUNIT_STRICT:-${SHUNIT_TRUE}} _shunit_warn() { echo "shunit2:WARN $@" >&2; } _shunit_error() { echo "shunit2:ERROR $@" >&2; } _shunit_fatal() { echo "shunit2:FATAL $@" >&2; exit ${SHUNIT_ERROR}; } # specific shell checks if [ -n "${ZSH_VERSION:-}" ]; then setopt |grep "^shwordsplit$" >/dev/null if [ $? -ne ${SHUNIT_TRUE} ]; then _shunit_fatal 'zsh shwordsplit option is required for proper operation' fi if [ -z "${SHUNIT_PARENT:-}" ]; then _shunit_fatal "zsh does not pass \$0 through properly. please declare \ \"SHUNIT_PARENT=\$0\" before calling shUnit2" fi fi # # constants # __SHUNIT_ASSERT_MSG_PREFIX='ASSERT:' __SHUNIT_MODE_SOURCED='sourced' __SHUNIT_MODE_STANDALONE='standalone' __SHUNIT_PARENT=${SHUNIT_PARENT:-$0} # set the constants readonly shunit_constants_=`set |grep '^__SHUNIT_' |cut -d= -f1` echo "${shunit_constants_}" |grep '^Binary file' >/dev/null && \ shunit_constants_=`set |grep -a '^__SHUNIT_' |cut -d= -f1` for shunit_constant_ in ${shunit_constants_}; do shunit_ro_opts_='' case ${ZSH_VERSION:-} in '') ;; # this isn't zsh [123].*) ;; # early versions (1.x, 2.x, 3.x) *) shunit_ro_opts_='-g' ;; # all later versions. declare readonly globally esac readonly ${shunit_ro_opts_} ${shunit_constant_} done unset shunit_constant_ shunit_constants_ shunit_ro_opts_ # variables __shunit_lineno='' # line number of executed test __shunit_mode=${__SHUNIT_MODE_SOURCED} # operating mode __shunit_reportGenerated=${SHUNIT_FALSE} # is report generated __shunit_script='' # filename of unittest script (standalone mode) __shunit_skip=${SHUNIT_FALSE} # is skipping enabled __shunit_suite='' # suite of tests to execute # counts of tests __shunit_testSuccess=${SHUNIT_TRUE} __shunit_testsTotal=0 __shunit_testsPassed=0 __shunit_testsFailed=0 # counts of asserts __shunit_assertsTotal=0 __shunit_assertsPassed=0 __shunit_assertsFailed=0 __shunit_assertsSkipped=0 # macros _SHUNIT_LINENO_='eval __shunit_lineno=""; if [ "${1:-}" = "--lineno" ]; then [ -n "$2" ] && __shunit_lineno="[$2] "; shift 2; fi' #----------------------------------------------------------------------------- # assert functions # # Assert that two values are equal to one another. # # Args: # message: string: failure message [optional] # expected: string: expected value # actual: string: actual value # Returns: # integer: success (TRUE/FALSE/ERROR constant) assertEquals() { ${_SHUNIT_LINENO_} if [ $# -lt 2 -o $# -gt 3 ]; then _shunit_error "assertEquals() requires two or three arguments; $# given" _shunit_error "1: ${1:+$1} 2: ${2:+$2} 3: ${3:+$3}${4:+ 4: $4}" return ${SHUNIT_ERROR} fi _shunit_shouldSkip && return ${SHUNIT_TRUE} shunit_message_=${__shunit_lineno} if [ $# -eq 3 ]; then shunit_message_="${shunit_message_}$1" shift fi shunit_expected_=$1 shunit_actual_=$2 shunit_return=${SHUNIT_TRUE} if [ "${shunit_expected_}" = "${shunit_actual_}" ]; then _shunit_assertPass else failNotEquals "${shunit_message_}" "${shunit_expected_}" "${shunit_actual_}" shunit_return=${SHUNIT_FALSE} fi unset shunit_message_ shunit_expected_ shunit_actual_ return ${shunit_return} } _ASSERT_EQUALS_='eval assertEquals --lineno "${LINENO:-}"' # Assert that two values are not equal to one another. # # Args: # message: string: failure message [optional] # expected: string: expected value # actual: string: actual value # Returns: # integer: success (TRUE/FALSE/ERROR constant) assertNotEquals() { ${_SHUNIT_LINENO_} if [ $# -lt 2 -o $# -gt 3 ]; then _shunit_error "assertNotEquals() requires two or three arguments; $# given" return ${SHUNIT_ERROR} fi _shunit_shouldSkip && return ${SHUNIT_TRUE} shunit_message_=${__shunit_lineno} if [ $# -eq 3 ]; then shunit_message_="${shunit_message_}$1" shift fi shunit_expected_=$1 shunit_actual_=$2 shunit_return=${SHUNIT_TRUE} if [ "${shunit_expected_}" != "${shunit_actual_}" ]; then _shunit_assertPass else failSame "${shunit_message_}" "$@" shunit_return=${SHUNIT_FALSE} fi unset shunit_message_ shunit_expected_ shunit_actual_ return ${shunit_return} } _ASSERT_NOT_EQUALS_='eval assertNotEquals --lineno "${LINENO:-}"' # Assert that a value is null (i.e. an empty string) # # Args: # message: string: failure message [optional] # actual: string: actual value # Returns: # integer: success (TRUE/FALSE/ERROR constant) assertNull() { ${_SHUNIT_LINENO_} if [ $# -lt 1 -o $# -gt 2 ]; then _shunit_error "assertNull() requires one or two arguments; $# given" return ${SHUNIT_ERROR} fi _shunit_shouldSkip && return ${SHUNIT_TRUE} shunit_message_=${__shunit_lineno} if [ $# -eq 2 ]; then shunit_message_="${shunit_message_}$1" shift fi assertTrue "${shunit_message_}" "[ -z '$1' ]" shunit_return=$? unset shunit_message_ return ${shunit_return} } _ASSERT_NULL_='eval assertNull --lineno "${LINENO:-}"' # Assert that a value is not null (i.e. a non-empty string) # # Args: # message: string: failure message [optional] # actual: string: actual value # Returns: # integer: success (TRUE/FALSE/ERROR constant) assertNotNull() { ${_SHUNIT_LINENO_} if [ $# -gt 2 ]; then # allowing 0 arguments as $1 might actually be null _shunit_error "assertNotNull() requires one or two arguments; $# given" return ${SHUNIT_ERROR} fi _shunit_shouldSkip && return ${SHUNIT_TRUE} shunit_message_=${__shunit_lineno} if [ $# -eq 2 ]; then shunit_message_="${shunit_message_}$1" shift fi shunit_actual_=`_shunit_escapeCharactersInString "${1:-}"` test -n "${shunit_actual_}" assertTrue "${shunit_message_}" $? shunit_return=$? unset shunit_actual_ shunit_message_ return ${shunit_return} } _ASSERT_NOT_NULL_='eval assertNotNull --lineno "${LINENO:-}"' # Assert that two values are the same (i.e. equal to one another). # # Args: # message: string: failure message [optional] # expected: string: expected value # actual: string: actual value # Returns: # integer: success (TRUE/FALSE/ERROR constant) assertSame() { ${_SHUNIT_LINENO_} if [ $# -lt 2 -o $# -gt 3 ]; then _shunit_error "assertSame() requires two or three arguments; $# given" return ${SHUNIT_ERROR} fi _shunit_shouldSkip && return ${SHUNIT_TRUE} shunit_message_=${__shunit_lineno} if [ $# -eq 3 ]; then shunit_message_="${shunit_message_}$1" shift fi assertEquals "${shunit_message_}" "$1" "$2" shunit_return=$? unset shunit_message_ return ${shunit_return} } _ASSERT_SAME_='eval assertSame --lineno "${LINENO:-}"' # Assert that two values are not the same (i.e. not equal to one another). # # Args: # message: string: failure message [optional] # expected: string: expected value # actual: string: actual value # Returns: # integer: success (TRUE/FALSE/ERROR constant) assertNotSame() { ${_SHUNIT_LINENO_} if [ $# -lt 2 -o $# -gt 3 ]; then _shunit_error "assertNotSame() requires two or three arguments; $# given" return ${SHUNIT_ERROR} fi _shunit_shouldSkip && return ${SHUNIT_TRUE} shunit_message_=${__shunit_lineno} if [ $# -eq 3 ]; then shunit_message_="${shunit_message_:-}$1" shift fi assertNotEquals "${shunit_message_}" "$1" "$2" shunit_return=$? unset shunit_message_ return ${shunit_return} } _ASSERT_NOT_SAME_='eval assertNotSame --lineno "${LINENO:-}"' # Assert that a value or shell test condition is true. # # In shell, a value of 0 is true and a non-zero value is false. Any integer # value passed can thereby be tested. # # Shell supports much more complicated tests though, and a means to support # them was needed. As such, this function tests that conditions are true or # false through evaluation rather than just looking for a true or false. # # The following test will succeed: # assertTrue 0 # assertTrue "[ 34 -gt 23 ]" # The folloing test will fail with a message: # assertTrue 123 # assertTrue "test failed" "[ -r '/non/existant/file' ]" # # Args: # message: string: failure message [optional] # condition: string: integer value or shell conditional statement # Returns: # integer: success (TRUE/FALSE/ERROR constant) assertTrue() { ${_SHUNIT_LINENO_} if [ $# -gt 2 ]; then _shunit_error "assertTrue() takes one two arguments; $# given" return ${SHUNIT_ERROR} fi _shunit_shouldSkip && return ${SHUNIT_TRUE} shunit_message_=${__shunit_lineno} if [ $# -eq 2 ]; then shunit_message_="${shunit_message_}$1" shift fi shunit_condition_=$1 # see if condition is an integer, i.e. a return value shunit_match_=`expr "${shunit_condition_}" : '\([0-9]*\)'` shunit_return=${SHUNIT_TRUE} if [ -z "${shunit_condition_}" ]; then # null condition shunit_return=${SHUNIT_FALSE} elif [ -n "${shunit_match_}" -a "${shunit_condition_}" = "${shunit_match_}" ] then # possible return value. treating 0 as true, and non-zero as false. [ ${shunit_condition_} -ne 0 ] && shunit_return=${SHUNIT_FALSE} else # (hopefully) a condition ( eval ${shunit_condition_} ) >/dev/null 2>&1 [ $? -ne 0 ] && shunit_return=${SHUNIT_FALSE} fi # record the test if [ ${shunit_return} -eq ${SHUNIT_TRUE} ]; then _shunit_assertPass else _shunit_assertFail "${shunit_message_}" fi unset shunit_message_ shunit_condition_ shunit_match_ return ${shunit_return} } _ASSERT_TRUE_='eval assertTrue --lineno "${LINENO:-}"' # Assert that a value or shell test condition is false. # # In shell, a value of 0 is true and a non-zero value is false. Any integer # value passed can thereby be tested. # # Shell supports much more complicated tests though, and a means to support # them was needed. As such, this function tests that conditions are true or # false through evaluation rather than just looking for a true or false. # # The following test will succeed: # assertFalse 1 # assertFalse "[ 'apples' = 'oranges' ]" # The folloing test will fail with a message: # assertFalse 0 # assertFalse "test failed" "[ 1 -eq 1 -a 2 -eq 2 ]" # # Args: # message: string: failure message [optional] # condition: string: integer value or shell conditional statement # Returns: # integer: success (TRUE/FALSE/ERROR constant) assertFalse() { ${_SHUNIT_LINENO_} if [ $# -lt 1 -o $# -gt 2 ]; then _shunit_error "assertFalse() quires one or two arguments; $# given" return ${SHUNIT_ERROR} fi _shunit_shouldSkip && return ${SHUNIT_TRUE} shunit_message_=${__shunit_lineno} if [ $# -eq 2 ]; then shunit_message_="${shunit_message_}$1" shift fi shunit_condition_=$1 # see if condition is an integer, i.e. a return value shunit_match_=`expr "${shunit_condition_}" : '\([0-9]*\)'` shunit_return=${SHUNIT_TRUE} if [ -z "${shunit_condition_}" ]; then # null condition shunit_return=${SHUNIT_FALSE} elif [ -n "${shunit_match_}" -a "${shunit_condition_}" = "${shunit_match_}" ] then # possible return value. treating 0 as true, and non-zero as false. [ ${shunit_condition_} -eq 0 ] && shunit_return=${SHUNIT_FALSE} else # (hopefully) a condition ( eval ${shunit_condition_} ) >/dev/null 2>&1 [ $? -eq 0 ] && shunit_return=${SHUNIT_FALSE} fi # record the test if [ ${shunit_return} -eq ${SHUNIT_TRUE} ]; then _shunit_assertPass else _shunit_assertFail "${shunit_message_}" fi unset shunit_message_ shunit_condition_ shunit_match_ return ${shunit_return} } _ASSERT_FALSE_='eval assertFalse --lineno "${LINENO:-}"' #----------------------------------------------------------------------------- # failure functions # # Records a test failure. # # Args: # message: string: failure message [optional] # Returns: # integer: success (TRUE/FALSE/ERROR constant) fail() { ${_SHUNIT_LINENO_} if [ $# -gt 1 ]; then _shunit_error "fail() requires zero or one arguments; $# given" return ${SHUNIT_ERROR} fi _shunit_shouldSkip && return ${SHUNIT_TRUE} shunit_message_=${__shunit_lineno} if [ $# -eq 1 ]; then shunit_message_="${shunit_message_}$1" shift fi _shunit_assertFail "${shunit_message_}" unset shunit_message_ return ${SHUNIT_FALSE} } _FAIL_='eval fail --lineno "${LINENO:-}"' # Records a test failure, stating two values were not equal. # # Args: # message: string: failure message [optional] # expected: string: expected value # actual: string: actual value # Returns: # integer: success (TRUE/FALSE/ERROR constant) failNotEquals() { ${_SHUNIT_LINENO_} if [ $# -lt 2 -o $# -gt 3 ]; then _shunit_error "failNotEquals() requires one or two arguments; $# given" return ${SHUNIT_ERROR} fi _shunit_shouldSkip && return ${SHUNIT_TRUE} shunit_message_=${__shunit_lineno} if [ $# -eq 3 ]; then shunit_message_="${shunit_message_}$1" shift fi shunit_expected_=$1 shunit_actual_=$2 _shunit_assertFail "${shunit_message_:+${shunit_message_} }expected:<${shunit_expected_}> but was:<${shunit_actual_}>" unset shunit_message_ shunit_expected_ shunit_actual_ return ${SHUNIT_FALSE} } _FAIL_NOT_EQUALS_='eval failNotEquals --lineno "${LINENO:-}"' # Records a test failure, stating two values should have been the same. # # Args: # message: string: failure message [optional] # expected: string: expected value # actual: string: actual value # Returns: # integer: success (TRUE/FALSE/ERROR constant) failSame() { ${_SHUNIT_LINENO_} if [ $# -lt 2 -o $# -gt 3 ]; then _shunit_error "failSame() requires two or three arguments; $# given" return ${SHUNIT_ERROR} fi _shunit_shouldSkip && return ${SHUNIT_TRUE} shunit_message_=${__shunit_lineno} if [ $# -eq 3 ]; then shunit_message_="${shunit_message_}$1" shift fi _shunit_assertFail "${shunit_message_:+${shunit_message_} }expected not same" unset shunit_message_ return ${SHUNIT_FALSE} } _FAIL_SAME_='eval failSame --lineno "${LINENO:-}"' # Records a test failure, stating two values were not equal. # # This is functionally equivalent to calling failNotEquals(). # # Args: # message: string: failure message [optional] # expected: string: expected value # actual: string: actual value # Returns: # integer: success (TRUE/FALSE/ERROR constant) failNotSame() { ${_SHUNIT_LINENO_} if [ $# -lt 2 -o $# -gt 3 ]; then _shunit_error "failNotEquals() requires one or two arguments; $# given" return ${SHUNIT_ERROR} fi _shunit_shouldSkip && return ${SHUNIT_TRUE} shunit_message_=${__shunit_lineno} if [ $# -eq 3 ]; then shunit_message_="${shunit_message_}$1" shift fi failNotEquals "${shunit_message_}" "$1" "$2" shunit_return=$? unset shunit_message_ return ${shunit_return} } _FAIL_NOT_SAME_='eval failNotSame --lineno "${LINENO:-}"' #----------------------------------------------------------------------------- # skipping functions # # Force remaining assert and fail functions to be "skipped". # # This function forces the remaining assert and fail functions to be "skipped", # i.e. they will have no effect. Each function skipped will be recorded so that # the total of asserts and fails will not be altered. # # Args: # None startSkipping() { __shunit_skip=${SHUNIT_TRUE} } # Resume the normal recording behavior of assert and fail calls. # # Args: # None endSkipping() { __shunit_skip=${SHUNIT_FALSE} } # Returns the state of assert and fail call skipping. # # Args: # None # Returns: # boolean: (TRUE/FALSE constant) isSkipping() { return ${__shunit_skip} } #----------------------------------------------------------------------------- # suite functions # # Stub. This function should contains all unit test calls to be made. # # DEPRECATED (as of 2.1.0) # # This function can be optionally overridden by the user in their test suite. # # If this function exists, it will be called when shunit2 is sourced. If it # does not exist, shunit2 will search the parent script for all functions # beginning with the word 'test', and they will be added dynamically to the # test suite. # # This function should be overridden by the user in their unit test suite. # Note: see _shunit_mktempFunc() for actual implementation # # Args: # None #suite() { :; } # DO NOT UNCOMMENT THIS FUNCTION # Adds a function name to the list of tests schedule for execution. # # This function should only be called from within the suite() function. # # Args: # function: string: name of a function to add to current unit test suite suite_addTest() { shunit_func_=${1:-} __shunit_suite="${__shunit_suite:+${__shunit_suite} }${shunit_func_}" __shunit_testsTotal=`expr ${__shunit_testsTotal} + 1` unset shunit_func_ } # Stub. This function will be called once before any tests are run. # # Common one-time environment preparation tasks shared by all tests can be # defined here. # # This function should be overridden by the user in their unit test suite. # Note: see _shunit_mktempFunc() for actual implementation # # Args: # None #oneTimeSetUp() { :; } # DO NOT UNCOMMENT THIS FUNCTION # Stub. This function will be called once after all tests are finished. # # Common one-time environment cleanup tasks shared by all tests can be defined # here. # # This function should be overridden by the user in their unit test suite. # Note: see _shunit_mktempFunc() for actual implementation # # Args: # None #oneTimeTearDown() { :; } # DO NOT UNCOMMENT THIS FUNCTION # Stub. This function will be called before each test is run. # # Common environment preparation tasks shared by all tests can be defined here. # # This function should be overridden by the user in their unit test suite. # Note: see _shunit_mktempFunc() for actual implementation # # Args: # None #setUp() { :; } # Note: see _shunit_mktempFunc() for actual implementation # Stub. This function will be called after each test is run. # # Common environment cleanup tasks shared by all tests can be defined here. # # This function should be overridden by the user in their unit test suite. # Note: see _shunit_mktempFunc() for actual implementation # # Args: # None #tearDown() { :; } # DO NOT UNCOMMENT THIS FUNCTION #------------------------------------------------------------------------------ # internal shUnit2 functions # # Create a temporary directory to store various run-time files in. # # This function is a cross-platform temporary directory creation tool. Not all # OSes have the mktemp function, so one is included here. # # Args: # None # Outputs: # string: the temporary directory that was created _shunit_mktempDir() { # try the standard mktemp function ( exec mktemp -dqt shunit.XXXXXX 2>/dev/null ) && return # the standard mktemp didn't work. doing our own. if [ -r '/dev/urandom' -a -x '/usr/bin/od' ]; then _shunit_random_=`/usr/bin/od -vAn -N4 -tx4 "${_shunit_file_}" #! /bin/sh exit ${SHUNIT_TRUE} EOF chmod +x "${_shunit_file_}" done unset _shunit_file_ } # Final cleanup function to leave things as we found them. # # Besides removing the temporary directory, this function is in charge of the # final exit code of the unit test. The exit code is based on how the script # was ended (e.g. normal exit, or via Ctrl-C). # # Args: # name: string: name of the trap called (specified when trap defined) _shunit_cleanup() { _shunit_name_=$1 case ${_shunit_name_} in EXIT) _shunit_signal_=0 ;; INT) _shunit_signal_=2 ;; TERM) _shunit_signal_=15 ;; *) _shunit_warn "unrecognized trap value (${_shunit_name_})" _shunit_signal_=0 ;; esac # do our work rm -fr "${__shunit_tmpDir}" # exit for all non-EXIT signals if [ ${_shunit_name_} != 'EXIT' ]; then _shunit_warn "trapped and now handling the (${_shunit_name_}) signal" # disable EXIT trap trap 0 # add 128 to signal and exit exit `expr ${_shunit_signal_} + 128` elif [ ${__shunit_reportGenerated} -eq ${SHUNIT_FALSE} ] ; then _shunit_assertFail 'Unknown failure encountered running a test' _shunit_generateReport exit ${SHUNIT_ERROR} fi unset _shunit_name_ _shunit_signal_ } # The actual running of the tests happens here. # # Args: # None _shunit_execSuite() { for _shunit_test_ in ${__shunit_suite}; do __shunit_testSuccess=${SHUNIT_TRUE} # disable skipping endSkipping # execute the per-test setup function setUp # execute the test echo "${_shunit_test_}" eval ${_shunit_test_} # execute the per-test tear-down function tearDown # update stats if [ ${__shunit_testSuccess} -eq ${SHUNIT_TRUE} ]; then __shunit_testsPassed=`expr ${__shunit_testsPassed} + 1` else __shunit_testsFailed=`expr ${__shunit_testsFailed} + 1` fi done unset _shunit_test_ } # Generates the user friendly report with appropriate OK/FAILED message. # # Args: # None # Output: # string: the report of successful and failed tests, as well as totals. _shunit_generateReport() { _shunit_ok_=${SHUNIT_TRUE} # if no exit code was provided one, determine an appropriate one [ ${__shunit_testsFailed} -gt 0 \ -o ${__shunit_testSuccess} -eq ${SHUNIT_FALSE} ] \ && _shunit_ok_=${SHUNIT_FALSE} echo if [ ${__shunit_testsTotal} -eq 1 ]; then echo "Ran ${__shunit_testsTotal} test." else echo "Ran ${__shunit_testsTotal} tests." fi _shunit_failures_='' _shunit_skipped_='' [ ${__shunit_assertsFailed} -gt 0 ] \ && _shunit_failures_="failures=${__shunit_assertsFailed}" [ ${__shunit_assertsSkipped} -gt 0 ] \ && _shunit_skipped_="skipped=${__shunit_assertsSkipped}" if [ ${_shunit_ok_} -eq ${SHUNIT_TRUE} ]; then _shunit_msg_='OK' [ -n "${_shunit_skipped_}" ] \ && _shunit_msg_="${_shunit_msg_} (${_shunit_skipped_})" else _shunit_msg_="FAILED (${_shunit_failures_}" [ -n "${_shunit_skipped_}" ] \ && _shunit_msg_="${_shunit_msg_},${_shunit_skipped_}" _shunit_msg_="${_shunit_msg_})" fi echo echo ${_shunit_msg_} __shunit_reportGenerated=${SHUNIT_TRUE} unset _shunit_failures_ _shunit_msg_ _shunit_ok_ _shunit_skipped_ } # Test for whether a function should be skipped. # # Args: # None # Returns: # boolean: whether the test should be skipped (TRUE/FALSE constant) _shunit_shouldSkip() { [ ${__shunit_skip} -eq ${SHUNIT_FALSE} ] && return ${SHUNIT_FALSE} _shunit_assertSkip } # Records a successful test. # # Args: # None _shunit_assertPass() { __shunit_assertsPassed=`expr ${__shunit_assertsPassed} + 1` __shunit_assertsTotal=`expr ${__shunit_assertsTotal} + 1` } # Records a test failure. # # Args: # message: string: failure message to provide user _shunit_assertFail() { _shunit_msg_=$1 __shunit_testSuccess=${SHUNIT_FALSE} __shunit_assertsFailed=`expr ${__shunit_assertsFailed} + 1` __shunit_assertsTotal=`expr ${__shunit_assertsTotal} + 1` echo "${__SHUNIT_ASSERT_MSG_PREFIX}${_shunit_msg_}" unset _shunit_msg_ } # Records a skipped test. # # Args: # None _shunit_assertSkip() { __shunit_assertsSkipped=`expr ${__shunit_assertsSkipped} + 1` __shunit_assertsTotal=`expr ${__shunit_assertsTotal} + 1` } # Prepare a script filename for sourcing. # # Args: # script: string: path to a script to source # Returns: # string: filename prefixed with ./ (if necessary) _shunit_prepForSourcing() { _shunit_script_=$1 case "${_shunit_script_}" in /*|./*) echo "${_shunit_script_}" ;; *) echo "./${_shunit_script_}" ;; esac unset _shunit_script_ } # Escape a character in a string. # # Args: # c: string: unescaped character # s: string: to escape character in # Returns: # string: with escaped character(s) _shunit_escapeCharInStr() { [ -n "$2" ] || return # no point in doing work on an empty string # Note: using shorter variable names to prevent conflicts with # _shunit_escapeCharactersInString(). _shunit_c_=$1 _shunit_s_=$2 # escape the character echo ''${_shunit_s_}'' |sed 's/\'${_shunit_c_}'/\\\'${_shunit_c_}'/g' unset _shunit_c_ _shunit_s_ } # Escape a character in a string. # # Args: # str: string: to escape characters in # Returns: # string: with escaped character(s) _shunit_escapeCharactersInString() { [ -n "$1" ] || return # no point in doing work on an empty string _shunit_str_=$1 # Note: using longer variable names to prevent conflicts with # _shunit_escapeCharInStr(). for _shunit_char_ in '"' '$' "'" '`'; do _shunit_str_=`_shunit_escapeCharInStr "${_shunit_char_}" "${_shunit_str_}"` done echo "${_shunit_str_}" unset _shunit_char_ _shunit_str_ } # Extract list of functions to run tests against. # # Args: # script: string: name of script to extract functions from # Returns: # string: of function names _shunit_extractTestFunctions() { _shunit_script_=$1 # extract the lines with test function names, strip of anything besides the # function name, and output everything on a single line. _shunit_regex_='^[ ]*(function )*test[A-Za-z0-9_]* *\(\)' egrep "${_shunit_regex_}" "${_shunit_script_}" \ |sed 's/^[^A-Za-z0-9_]*//;s/^function //;s/\([A-Za-z0-9_]*\).*/\1/g' \ |xargs unset _shunit_regex_ _shunit_script_ } #------------------------------------------------------------------------------ # main # # determine the operating mode if [ $# -eq 0 ]; then __shunit_script=${__SHUNIT_PARENT} __shunit_mode=${__SHUNIT_MODE_SOURCED} else __shunit_script=$1 [ -r "${__shunit_script}" ] || \ _shunit_fatal "unable to read from ${__shunit_script}" __shunit_mode=${__SHUNIT_MODE_STANDALONE} fi # create a temporary storage location __shunit_tmpDir=`_shunit_mktempDir` # provide a public temporary directory for unit test scripts # TODO(kward): document this SHUNIT_TMPDIR="${__shunit_tmpDir}/tmp" mkdir "${SHUNIT_TMPDIR}" # setup traps to clean up after ourselves trap '_shunit_cleanup EXIT' 0 trap '_shunit_cleanup INT' 2 trap '_shunit_cleanup TERM' 15 # create phantom functions to work around issues with Cygwin _shunit_mktempFunc PATH="${__shunit_tmpDir}:${PATH}" # make sure phantom functions are executable. this will bite if /tmp (or the # current $TMPDIR) points to a path on a partition that was mounted with the # 'noexec' option. the noexec command was created with _shunit_mktempFunc(). noexec 2>/dev/null || _shunit_fatal \ 'please declare TMPDIR with path on partition with exec permission' # we must manually source the tests in standalone mode if [ "${__shunit_mode}" = "${__SHUNIT_MODE_STANDALONE}" ]; then . "`_shunit_prepForSourcing \"${__shunit_script}\"`" fi # execute the oneTimeSetUp function (if it exists) oneTimeSetUp # execute the suite function defined in the parent test script # deprecated as of 2.1.0 suite # if no suite function was defined, dynamically build a list of functions if [ -z "${__shunit_suite}" ]; then shunit_funcs_=`_shunit_extractTestFunctions "${__shunit_script}"` for shunit_func_ in ${shunit_funcs_}; do suite_addTest ${shunit_func_} done fi unset shunit_func_ shunit_funcs_ # execute the tests _shunit_execSuite # execute the oneTimeTearDown function (if it exists) oneTimeTearDown # generate the report _shunit_generateReport # that's it folks [ ${__shunit_testsFailed} -eq 0 ] exit $? git-ftp-1.0.2/tests/shunit2-2.1.6/src/shunit2_test.sh000077500000000000000000000051371246645256000220650ustar00rootroot00000000000000#! /bin/sh # $Id: shunit2_test.sh 322 2011-04-24 00:09:45Z kate.ward@forestent.com $ # vim:et:ft=sh:sts=2:sw=2 # # Copyright 2008 Kate Ward. All Rights Reserved. # Released under the LGPL (GNU Lesser General Public License) # Author: kate.ward@forestent.com (Kate Ward) # # shUnit2 unit test suite runner. # # This script runs all the unit tests that can be found, and generates a nice # report of the tests. MY_NAME=`basename $0` MY_PATH=`dirname $0` PREFIX='shunit2_test_' SHELLS='/bin/sh /bin/bash /bin/dash /bin/ksh /bin/pdksh /bin/zsh' TESTS='' for test in ${PREFIX}[a-z]*.sh; do TESTS="${TESTS} ${test}" done # load common unit test functions . ../lib/versions . ./shunit2_test_helpers usage() { echo "usage: ${MY_NAME} [-e key=val ...] [-s shell(s)] [-t test(s)]" } env='' # process command line flags while getopts 'e:hs:t:' opt; do case ${opt} in e) # set an environment variable key=`expr "${OPTARG}" : '\([^=]*\)='` val=`expr "${OPTARG}" : '[^=]*=\(.*\)'` if [ -z "${key}" -o -z "${val}" ]; then usage exit 1 fi eval "${key}='${val}'" export ${key} env="${env:+${env} }${key}" ;; h) usage; exit 0 ;; # output help s) shells=${OPTARG} ;; # list of shells to run t) tests=${OPTARG} ;; # list of tests to run *) usage; exit 1 ;; esac done shift `expr ${OPTIND} - 1` # fill shells and/or tests shells=${shells:-${SHELLS}} tests=${tests:-${TESTS}} # error checking if [ -z "${tests}" ]; then th_error 'no tests found to run; exiting' exit 1 fi cat <&1; ) done done git-ftp-1.0.2/tests/shunit2-2.1.6/src/shunit2_test_asserts.sh000077500000000000000000000150301246645256000236220ustar00rootroot00000000000000#! /bin/sh # $Id: shunit2_test_asserts.sh 312 2011-03-14 22:41:29Z kate.ward@forestent.com $ # vim:et:ft=sh:sts=2:sw=2 # # Copyright 2008 Kate Ward. All Rights Reserved. # Released under the LGPL (GNU Lesser General Public License) # # Author: kate.ward@forestent.com (Kate Ward) # # shUnit2 unit test for assert functions # load test helpers . ./shunit2_test_helpers #------------------------------------------------------------------------------ # suite tests # commonEqualsSame() { fn=$1 ( ${fn} 'x' 'x' >"${stdoutF}" 2>"${stderrF}" ) th_assertTrueWithNoOutput 'equal' $? "${stdoutF}" "${stderrF}" ( ${fn} "${MSG}" 'x' 'x' >"${stdoutF}" 2>"${stderrF}" ) th_assertTrueWithNoOutput 'equal; with msg' $? "${stdoutF}" "${stderrF}" ( ${fn} 'abc def' 'abc def' >"${stdoutF}" 2>"${stderrF}" ) th_assertTrueWithNoOutput 'equal with spaces' $? "${stdoutF}" "${stderrF}" ( ${fn} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithOutput 'not equal' $? "${stdoutF}" "${stderrF}" ( ${fn} '' '' >"${stdoutF}" 2>"${stderrF}" ) th_assertTrueWithNoOutput 'null values' $? "${stdoutF}" "${stderrF}" ( ${fn} arg1 >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}" ( ${fn} arg1 arg2 arg3 arg4 >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}" } commonNotEqualsSame() { fn=$1 ( ${fn} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" ) th_assertTrueWithNoOutput 'not same' $? "${stdoutF}" "${stderrF}" ( ${fn} "${MSG}" 'x' 'y' >"${stdoutF}" 2>"${stderrF}" ) th_assertTrueWithNoOutput 'not same, with msg' $? "${stdoutF}" "${stderrF}" ( ${fn} 'x' 'x' >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithOutput 'same' $? "${stdoutF}" "${stderrF}" ( ${fn} '' '' >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithOutput 'null values' $? "${stdoutF}" "${stderrF}" ( ${fn} arg1 >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}" ( ${fn} arg1 arg2 arg3 arg4 >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}" } testAssertEquals() { commonEqualsSame 'assertEquals' } testAssertNotEquals() { commonNotEqualsSame 'assertNotEquals' } testAssertSame() { commonEqualsSame 'assertSame' } testAssertNotSame() { commonNotEqualsSame 'assertNotSame' } testAssertNull() { ( assertNull '' >"${stdoutF}" 2>"${stderrF}" ) th_assertTrueWithNoOutput 'null' $? "${stdoutF}" "${stderrF}" ( assertNull "${MSG}" '' >"${stdoutF}" 2>"${stderrF}" ) th_assertTrueWithNoOutput 'null, with msg' $? "${stdoutF}" "${stderrF}" ( assertNull 'x' >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithOutput 'not null' $? "${stdoutF}" "${stderrF}" ( assertNull >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}" ( assertNull arg1 arg2 arg3 >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}" } testAssertNotNull() { ( assertNotNull 'x' >"${stdoutF}" 2>"${stderrF}" ) th_assertTrueWithNoOutput 'not null' $? "${stdoutF}" "${stderrF}" ( assertNotNull "${MSG}" 'x' >"${stdoutF}" 2>"${stderrF}" ) th_assertTrueWithNoOutput 'not null, with msg' $? "${stdoutF}" "${stderrF}" ( assertNotNull 'x"b' >"${stdoutF}" 2>"${stderrF}" ) th_assertTrueWithNoOutput 'not null, with double-quote' $? \ "${stdoutF}" "${stderrF}" ( assertNotNull "x'b" >"${stdoutF}" 2>"${stderrF}" ) th_assertTrueWithNoOutput 'not null, with single-quote' $? \ "${stdoutF}" "${stderrF}" ( assertNotNull 'x$b' >"${stdoutF}" 2>"${stderrF}" ) th_assertTrueWithNoOutput 'not null, with dollar' $? \ "${stdoutF}" "${stderrF}" ( assertNotNull 'x`b' >"${stdoutF}" 2>"${stderrF}" ) th_assertTrueWithNoOutput 'not null, with backtick' $? \ "${stdoutF}" "${stderrF}" ( assertNotNull '' >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithOutput 'null' $? "${stdoutF}" "${stderrF}" # there is no test for too few arguments as $1 might actually be null ( assertNotNull arg1 arg2 arg3 >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}" } testAssertTrue() { ( assertTrue 0 >"${stdoutF}" 2>"${stderrF}" ) th_assertTrueWithNoOutput 'true' $? "${stdoutF}" "${stderrF}" ( assertTrue "${MSG}" 0 >"${stdoutF}" 2>"${stderrF}" ) th_assertTrueWithNoOutput 'true, with msg' $? "${stdoutF}" "${stderrF}" ( assertTrue '[ 0 -eq 0 ]' >"${stdoutF}" 2>"${stderrF}" ) th_assertTrueWithNoOutput 'true condition' $? "${stdoutF}" "${stderrF}" ( assertTrue 1 >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithOutput 'false' $? "${stdoutF}" "${stderrF}" ( assertTrue '[ 0 -eq 1 ]' >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithOutput 'false condition' $? "${stdoutF}" "${stderrF}" ( assertTrue '' >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithOutput 'null' $? "${stdoutF}" "${stderrF}" ( assertTrue >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}" ( assertTrue arg1 arg2 arg3 >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}" } testAssertFalse() { ( assertFalse 1 >"${stdoutF}" 2>"${stderrF}" ) th_assertTrueWithNoOutput 'false' $? "${stdoutF}" "${stderrF}" ( assertFalse "${MSG}" 1 >"${stdoutF}" 2>"${stderrF}" ) th_assertTrueWithNoOutput 'false, with msg' $? "${stdoutF}" "${stderrF}" ( assertFalse '[ 0 -eq 1 ]' >"${stdoutF}" 2>"${stderrF}" ) th_assertTrueWithNoOutput 'false condition' $? "${stdoutF}" "${stderrF}" ( assertFalse 0 >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithOutput 'true' $? "${stdoutF}" "${stderrF}" ( assertFalse '[ 0 -eq 0 ]' >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithOutput 'true condition' $? "${stdoutF}" "${stderrF}" ( assertFalse '' >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithOutput 'true condition' $? "${stdoutF}" "${stderrF}" ( assertFalse >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}" ( assertFalse arg1 arg2 arg3 >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}" } #------------------------------------------------------------------------------ # suite functions # oneTimeSetUp() { tmpDir="${__shunit_tmpDir}/output" mkdir "${tmpDir}" stdoutF="${tmpDir}/stdout" stderrF="${tmpDir}/stderr" MSG='This is a test message' } # load and run shUnit2 [ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0 . ${TH_SHUNIT} git-ftp-1.0.2/tests/shunit2-2.1.6/src/shunit2_test_failures.sh000077500000000000000000000053261246645256000237570ustar00rootroot00000000000000#! /bin/sh # $Id: shunit2_test_failures.sh 286 2008-11-24 21:42:34Z kate.ward@forestent.com $ # vim:et:ft=sh:sts=2:sw=2 # # Copyright 2008 Kate Ward. All Rights Reserved. # Released under the LGPL (GNU Lesser General Public License) # # Author: kate.ward@forestent.com (Kate Ward) # # shUnit2 unit test for failure functions # load common unit-test functions . ./shunit2_test_helpers #----------------------------------------------------------------------------- # suite tests # testFail() { ( fail >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithOutput 'fail' $? "${stdoutF}" "${stderrF}" ( fail "${MSG}" >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithOutput 'fail with msg' $? "${stdoutF}" "${stderrF}" ( fail arg1 >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithOutput 'too many arguments' $? "${stdoutF}" "${stderrF}" } testFailNotEquals() { ( failNotEquals 'x' 'x' >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithOutput 'same' $? "${stdoutF}" "${stderrF}" ( failNotEquals "${MSG}" 'x' 'x' >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithOutput 'same with msg' $? "${stdoutF}" "${stderrF}" ( failNotEquals 'x' 'y' >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithOutput 'not same' $? "${stdoutF}" "${stderrF}" ( failNotEquals '' '' >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithOutput 'null values' $? "${stdoutF}" "${stderrF}" ( failNotEquals >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}" ( failNotEquals arg1 arg2 arg3 arg4 >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}" } testFailSame() { ( failSame 'x' 'x' >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithOutput 'same' $? "${stdoutF}" "${stderrF}" ( failSame "${MSG}" 'x' 'x' >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithOutput 'same with msg' $? "${stdoutF}" "${stderrF}" ( failSame 'x' 'y' >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithOutput 'not same' $? "${stdoutF}" "${stderrF}" ( failSame '' '' >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithOutput 'null values' $? "${stdoutF}" "${stderrF}" ( failSame >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}" ( failSame arg1 arg2 arg3 arg4 >"${stdoutF}" 2>"${stderrF}" ) th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}" } #----------------------------------------------------------------------------- # suite functions # oneTimeSetUp() { tmpDir="${__shunit_tmpDir}/output" mkdir "${tmpDir}" stdoutF="${tmpDir}/stdout" stderrF="${tmpDir}/stderr" MSG='This is a test message' } # load and run shUnit2 [ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0 . ${TH_SHUNIT} git-ftp-1.0.2/tests/shunit2-2.1.6/src/shunit2_test_helpers000066400000000000000000000112001246645256000231570ustar00rootroot00000000000000# $Id: shunit2_test_helpers 286 2008-11-24 21:42:34Z kate.ward@forestent.com $ # vim:et:ft=sh:sts=2:sw=2 # # Copyright 2008 Kate Ward. All Rights Reserved. # Released under the LGPL (GNU Lesser General Public License) # # Author: kate.ward@forestent.com (Kate Ward) # # shUnit2 unit test common functions # treat unset variables as an error when performing parameter expansion set -u # set shwordsplit for zsh [ -n "${ZSH_VERSION:-}" ] && setopt shwordsplit # # constants # # path to shUnit2 library. can be overridden by setting SHUNIT_INC TH_SHUNIT=${SHUNIT_INC:-./shunit2} # configure debugging. set the DEBUG environment variable to any # non-empty value to enable debug output, or TRACE to enable trace # output. TRACE=${TRACE:+'th_trace '} [ -n "${TRACE}" ] && DEBUG=1 [ -z "${TRACE}" ] && TRACE=':' DEBUG=${DEBUG:+'th_debug '} [ -z "${DEBUG}" ] && DEBUG=':' # # variables # th_RANDOM=0 # # functions # # message functions th_trace() { echo "${MY_NAME}:TRACE $@" >&2; } th_debug() { echo "${MY_NAME}:DEBUG $@" >&2; } th_info() { echo "${MY_NAME}:INFO $@" >&2; } th_warn() { echo "${MY_NAME}:WARN $@" >&2; } th_error() { echo "${MY_NAME}:ERROR $@" >&2; } th_fatal() { echo "${MY_NAME}:FATAL $@" >&2; } # output subtest name th_subtest() { echo " $@" >&2; } # generate a random number th_generateRandom() { tfgr_random=${th_RANDOM} while [ "${tfgr_random}" = "${th_RANDOM}" ]; do if [ -n "${RANDOM:-}" ]; then # $RANDOM works tfgr_random=${RANDOM}${RANDOM}${RANDOM}$$ elif [ -r '/dev/urandom' ]; then tfgr_random=`od -vAn -N4 -tu4 "${stdoutF}" 2>"${stderrF}" ) grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null rtrn=$? assertTrue '_ASSERT_EQUALS_ failure' ${rtrn} [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 ( ${_ASSERT_EQUALS_} '"some msg"' 'x' 'y' >"${stdoutF}" 2>"${stderrF}" ) grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null rtrn=$? assertTrue '_ASSERT_EQUALS_ w/ msg failure' ${rtrn} [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 } testAssertNotEquals() { # start skipping if LINENO not available [ -z "${LINENO:-}" ] && startSkipping ( ${_ASSERT_NOT_EQUALS_} 'x' 'x' >"${stdoutF}" 2>"${stderrF}" ) grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null rtrn=$? assertTrue '_ASSERT_NOT_EQUALS_ failure' ${rtrn} [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 ( ${_ASSERT_NOT_EQUALS_} '"some msg"' 'x' 'x' >"${stdoutF}" 2>"${stderrF}" ) grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null rtrn=$? assertTrue '_ASSERT_NOT_EQUALS_ w/ msg failure' ${rtrn} [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 } testSame() { # start skipping if LINENO not available [ -z "${LINENO:-}" ] && startSkipping ( ${_ASSERT_SAME_} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" ) grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null rtrn=$? assertTrue '_ASSERT_SAME_ failure' ${rtrn} [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 ( ${_ASSERT_SAME_} '"some msg"' 'x' 'y' >"${stdoutF}" 2>"${stderrF}" ) grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null rtrn=$? assertTrue '_ASSERT_SAME_ w/ msg failure' ${rtrn} [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 } testNotSame() { # start skipping if LINENO not available [ -z "${LINENO:-}" ] && startSkipping ( ${_ASSERT_NOT_SAME_} 'x' 'x' >"${stdoutF}" 2>"${stderrF}" ) grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null rtrn=$? assertTrue '_ASSERT_NOT_SAME_ failure' ${rtrn} [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 ( ${_ASSERT_NOT_SAME_} '"some msg"' 'x' 'x' >"${stdoutF}" 2>"${stderrF}" ) grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null rtrn=$? assertTrue '_ASSERT_NOT_SAME_ w/ msg failure' ${rtrn} [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 } testNull() { # start skipping if LINENO not available [ -z "${LINENO:-}" ] && startSkipping ( ${_ASSERT_NULL_} 'x' >"${stdoutF}" 2>"${stderrF}" ) grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null rtrn=$? assertTrue '_ASSERT_NULL_ failure' ${rtrn} [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 ( ${_ASSERT_NULL_} '"some msg"' 'x' >"${stdoutF}" 2>"${stderrF}" ) grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null rtrn=$? assertTrue '_ASSERT_NULL_ w/ msg failure' ${rtrn} [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 } testNotNull() { # start skipping if LINENO not available [ -z "${LINENO:-}" ] && startSkipping ( ${_ASSERT_NOT_NULL_} '' >"${stdoutF}" 2>"${stderrF}" ) grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null rtrn=$? assertTrue '_ASSERT_NOT_NULL_ failure' ${rtrn} [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 ( ${_ASSERT_NOT_NULL_} '"some msg"' '""' >"${stdoutF}" 2>"${stderrF}" ) grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null rtrn=$? assertTrue '_ASSERT_NOT_NULL_ w/ msg failure' ${rtrn} [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stdoutF}" "${stderrF}" >&2 } testAssertTrue() { # start skipping if LINENO not available [ -z "${LINENO:-}" ] && startSkipping ( ${_ASSERT_TRUE_} ${SHUNIT_FALSE} >"${stdoutF}" 2>"${stderrF}" ) grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null rtrn=$? assertTrue '_ASSERT_TRUE_ failure' ${rtrn} [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 ( ${_ASSERT_TRUE_} '"some msg"' ${SHUNIT_FALSE} >"${stdoutF}" 2>"${stderrF}" ) grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null rtrn=$? assertTrue '_ASSERT_TRUE_ w/ msg failure' ${rtrn} [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 } testAssertFalse() { # start skipping if LINENO not available [ -z "${LINENO:-}" ] && startSkipping ( ${_ASSERT_FALSE_} ${SHUNIT_TRUE} >"${stdoutF}" 2>"${stderrF}" ) grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null rtrn=$? assertTrue '_ASSERT_FALSE_ failure' ${rtrn} [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 ( ${_ASSERT_FALSE_} '"some msg"' ${SHUNIT_TRUE} >"${stdoutF}" 2>"${stderrF}" ) grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null rtrn=$? assertTrue '_ASSERT_FALSE_ w/ msg failure' ${rtrn} [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 } testFail() { # start skipping if LINENO not available [ -z "${LINENO:-}" ] && startSkipping ( ${_FAIL_} >"${stdoutF}" 2>"${stderrF}" ) grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null rtrn=$? assertTrue '_FAIL_ failure' ${rtrn} [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 ( ${_FAIL_} '"some msg"' >"${stdoutF}" 2>"${stderrF}" ) grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null rtrn=$? assertTrue '_FAIL_ w/ msg failure' ${rtrn} [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 } testFailNotEquals() { # start skipping if LINENO not available [ -z "${LINENO:-}" ] && startSkipping ( ${_FAIL_NOT_EQUALS_} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" ) grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null rtrn=$? assertTrue '_FAIL_NOT_EQUALS_ failure' ${rtrn} [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 ( ${_FAIL_NOT_EQUALS_} '"some msg"' 'x' 'y' >"${stdoutF}" 2>"${stderrF}" ) grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null rtrn=$? assertTrue '_FAIL_NOT_EQUALS_ w/ msg failure' ${rtrn} [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 } testFailSame() { # start skipping if LINENO not available [ -z "${LINENO:-}" ] && startSkipping ( ${_FAIL_SAME_} 'x' 'x' >"${stdoutF}" 2>"${stderrF}" ) grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null rtrn=$? assertTrue '_FAIL_SAME_ failure' ${rtrn} [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 ( ${_FAIL_SAME_} '"some msg"' 'x' 'x' >"${stdoutF}" 2>"${stderrF}" ) grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null rtrn=$? assertTrue '_FAIL_SAME_ w/ msg failure' ${rtrn} [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 } testFailNotSame() { # start skipping if LINENO not available [ -z "${LINENO:-}" ] && startSkipping ( ${_FAIL_NOT_SAME_} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" ) grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null rtrn=$? assertTrue '_FAIL_NOT_SAME_ failure' ${rtrn} [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 ( ${_FAIL_NOT_SAME_} '"some msg"' 'x' 'y' >"${stdoutF}" 2>"${stderrF}" ) grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null rtrn=$? assertTrue '_FAIL_NOT_SAME_ w/ msg failure' ${rtrn} [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 } #------------------------------------------------------------------------------ # suite functions # oneTimeSetUp() { tmpDir="${__shunit_tmpDir}/output" mkdir "${tmpDir}" stdoutF="${tmpDir}/stdout" stderrF="${tmpDir}/stderr" } # load and run shUnit2 [ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0 . ${TH_SHUNIT} git-ftp-1.0.2/tests/shunit2-2.1.6/src/shunit2_test_misc.sh000077500000000000000000000114161246645256000230750ustar00rootroot00000000000000#! /bin/sh # $Id: shunit2_test_misc.sh 322 2011-04-24 00:09:45Z kate.ward@forestent.com $ # vim:et:ft=sh:sts=2:sw=2 # # Copyright 2008 Kate Ward. All Rights Reserved. # Released under the LGPL (GNU Lesser General Public License) # # Author: kate.ward@forestent.com (Kate Ward) # # shUnit2 unit tests of miscellaneous things # load test helpers . ./shunit2_test_helpers #------------------------------------------------------------------------------ # suite tests # # Note: the test script is prefixed with '#' chars so that shUnit2 does not # incorrectly interpret the embedded functions as real functions. testUnboundVariable() { sed 's/^#//' >"${unittestF}" <"${stdoutF}" 2>"${stderrF}" ) assertFalse 'expected a non-zero exit value' $? grep '^ASSERT:Unknown failure' "${stdoutF}" >/dev/null assertTrue 'assert message was not generated' $? grep '^Ran [0-9]* test' "${stdoutF}" >/dev/null assertTrue 'test count message was not generated' $? grep '^FAILED' "${stdoutF}" >/dev/null assertTrue 'failure message was not generated' $? } testIssue7() { ( assertEquals 'Some message.' 1 2 >"${stdoutF}" 2>"${stderrF}" ) diff "${stdoutF}" - >/dev/null < but was:<2> EOF rtrn=$? assertEquals ${SHUNIT_TRUE} ${rtrn} [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2 } testPrepForSourcing() { assertEquals '/abc' `_shunit_prepForSourcing '/abc'` assertEquals './abc' `_shunit_prepForSourcing './abc'` assertEquals './abc' `_shunit_prepForSourcing 'abc'` } testEscapeCharInStr() { actual=`_shunit_escapeCharInStr '\' ''` assertEquals '' "${actual}" assertEquals 'abc\\' `_shunit_escapeCharInStr '\' 'abc\'` assertEquals 'abc\\def' `_shunit_escapeCharInStr '\' 'abc\def'` assertEquals '\\def' `_shunit_escapeCharInStr '\' '\def'` actual=`_shunit_escapeCharInStr '"' ''` assertEquals '' "${actual}" assertEquals 'abc\"' `_shunit_escapeCharInStr '"' 'abc"'` assertEquals 'abc\"def' `_shunit_escapeCharInStr '"' 'abc"def'` assertEquals '\"def' `_shunit_escapeCharInStr '"' '"def'` actual=`_shunit_escapeCharInStr '$' ''` assertEquals '' "${actual}" assertEquals 'abc\$' `_shunit_escapeCharInStr '$' 'abc$'` assertEquals 'abc\$def' `_shunit_escapeCharInStr '$' 'abc$def'` assertEquals '\$def' `_shunit_escapeCharInStr '$' '$def'` # actual=`_shunit_escapeCharInStr "'" ''` # assertEquals '' "${actual}" # assertEquals "abc\\'" `_shunit_escapeCharInStr "'" "abc'"` # assertEquals "abc\\'def" `_shunit_escapeCharInStr "'" "abc'def"` # assertEquals "\\'def" `_shunit_escapeCharInStr "'" "'def"` # # must put the backtick in a variable so the shell doesn't misinterpret it # # while inside a backticked sequence (e.g. `echo '`'` would fail). # backtick='`' # actual=`_shunit_escapeCharInStr ${backtick} ''` # assertEquals '' "${actual}" # assertEquals '\`abc' \ # `_shunit_escapeCharInStr "${backtick}" ${backtick}'abc'` # assertEquals 'abc\`' \ # `_shunit_escapeCharInStr "${backtick}" 'abc'${backtick}` # assertEquals 'abc\`def' \ # `_shunit_escapeCharInStr "${backtick}" 'abc'${backtick}'def'` } testEscapeCharInStr_specialChars() { # make sure our forward slash doesn't upset sed assertEquals '/' `_shunit_escapeCharInStr '\' '/'` # some shells escape these differently #assertEquals '\\a' `_shunit_escapeCharInStr '\' '\a'` #assertEquals '\\b' `_shunit_escapeCharInStr '\' '\b'` } # Test the various ways of declaring functions. # # Prefixing (then stripping) with comment symbol so these functions aren't # treated as real functions by shUnit2. testExtractTestFunctions() { f="${tmpD}/extract_test_functions" sed 's/^#//' <"${f}" #testABC() { echo 'ABC'; } #test_def() { # echo 'def' #} #testG3 () #{ # echo 'G3' #} #function test4() { echo '4'; } # test5() { echo '5'; } #some_test_function() { echo 'some func'; } #func_with_test_vars() { # testVariable=1234 #} EOF actual=`_shunit_extractTestFunctions "${f}"` assertEquals 'testABC test_def testG3 test4 test5' "${actual}" } #------------------------------------------------------------------------------ # suite functions # setUp() { for f in ${expectedF} ${stdoutF} ${stderrF}; do cp /dev/null ${f} done rm -fr "${tmpD}" mkdir "${tmpD}" } oneTimeSetUp() { tmpD="${SHUNIT_TMPDIR}/tmp" expectedF="${SHUNIT_TMPDIR}/expected" stdoutF="${SHUNIT_TMPDIR}/stdout" stderrF="${SHUNIT_TMPDIR}/stderr" unittestF="${SHUNIT_TMPDIR}/unittest" } # load and run shUnit2 [ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0 . ${TH_SHUNIT} git-ftp-1.0.2/tests/shunit2-2.1.6/src/shunit2_test_standalone.sh000077500000000000000000000020221246645256000242630ustar00rootroot00000000000000#! /bin/sh # $Id: shunit2_test_standalone.sh 303 2010-05-03 13:11:27Z kate.ward@forestent.com $ # vim:et:ft=sh:sts=2:sw=2 # # Copyright 2010 Kate Ward. All Rights Reserved. # Released under the LGPL (GNU Lesser General Public License) # Author: kate.ward@forestent.com (Kate Ward) # # shUnit2 unit test for standalone operation. # # This unit test is purely to test that calling shunit2 directly, while passing # the name of a unit test script, works. When run, this script determines if it # is running as a standalone program, and calls main() if it is. ARGV0=`basename "$0"` # load test helpers . ./shunit2_test_helpers #------------------------------------------------------------------------------ # suite tests # testStandalone() { assertTrue ${SHUNIT_TRUE} } #------------------------------------------------------------------------------ # main # main() { ${TH_SHUNIT} "${ARGV0}" } # are we running as a standalone? if [ "${ARGV0}" = 'shunit2_test_standalone.sh' ]; then if [ $# -gt 0 ]; then main "$@"; else main; fi fi