├── .gitignore ├── LICENSE-2.0.txt ├── R ├── .gitignore ├── DESCRIPTION ├── NAMESPACE ├── R │ └── fibonacci.R ├── README.md ├── exec │ └── fibonacci_client.R └── tests │ ├── testthat.R │ └── testthat │ └── test_fibonacci.R ├── README.md ├── c ├── .gitignore ├── Makefile ├── README.md ├── cunit-to-junit.xsl ├── set-paths.sh ├── src │ ├── fibonacci.c │ ├── fibonacci.h │ └── fibonacci_program.c └── test │ ├── cunit_test_driver.c │ ├── fibonacci_cunit_test.c │ └── fibonacci_cunit_test.h ├── cpp ├── .gitignore ├── Makefile ├── README.md ├── set-paths.sh ├── src │ ├── fibonacci.h │ └── fibonacci_program.cc └── test │ ├── cppunit_test_driver.cc │ ├── fibonacci_cppunit_test.cc │ └── fibonacci_google_test.cc ├── fortran ├── .gitignore ├── FRUIT_LICENSE.txt ├── Makefile ├── README.md ├── fruit │ ├── LICENSE.txt │ ├── fruit.f90 │ └── fruit_util.f90 ├── src │ ├── fibonacci.f90 │ └── fibonacci_program.f90 └── test │ ├── fibonacci_test.f90 │ ├── fruit_helpers.F90 │ └── fruit_test_driver.F90 ├── java ├── .gitignore ├── JUNIT_LICENSE.txt ├── README.md ├── build.xml ├── lib │ └── junit-4.10.jar ├── src │ └── math │ │ └── Fibonacci.java └── test │ └── math │ └── FibonacciTest.java ├── jenkins ├── Install.md ├── Languages.md ├── Periodic.md ├── README.md ├── Shell.md ├── VersionControl.md └── examples │ ├── C job │ └── config.xml │ ├── CVS job │ └── config.xml │ ├── Cpp job │ └── config.xml │ ├── Fortran job │ └── config.xml │ ├── Git job │ └── config.xml │ ├── Java job │ └── config.xml │ ├── Mercurial job │ └── config.xml │ ├── PHP job │ └── config.xml │ ├── Periodic job │ └── config.xml │ ├── Python job │ └── config.xml │ ├── SVN job │ └── config.xml │ ├── Shell job │ └── config.xml │ ├── cvs-notify-jenkins.sh │ ├── git-post-commit │ ├── git-post-receive │ ├── hgrc │ └── svn-post-commit ├── php ├── .gitignore ├── README.md ├── src │ ├── Fibonacci.php │ ├── FibonacciProgram.php │ └── autoload.php └── test │ └── FibonacciTest.php ├── python ├── .gitignore ├── README.md └── maths │ ├── __init__.py │ ├── fibonacci.py │ └── tests │ ├── __init__.py │ └── test_fibonacci.py ├── sh ├── README.md └── fibonacci.sh └── travis ├── HelloWorld.md ├── Languages.md ├── README.md └── examples ├── c-travis.yml ├── cpp-travis.yml ├── java-travis.yml ├── php-travis.yml └── python-travis.yml /.gitignore: -------------------------------------------------------------------------------- 1 | ## Emacs 2 | 3 | *~ 4 | 5 | ## Mac 6 | 7 | .DS_Store 8 | -------------------------------------------------------------------------------- /LICENSE-2.0.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /R/.gitignore: -------------------------------------------------------------------------------- 1 | # R 2 | 3 | .RData 4 | .Rhistory 5 | -------------------------------------------------------------------------------- /R/DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: ssi.r.sample 2 | Type: Package 3 | Title: R Fibonacci series example plus unit tests 4 | Version: 1.0 5 | Date: 2015-10-01 6 | Author: Mike Jackson 7 | Maintainer: Mike Jackson 8 | Description: R Fibonacci series example plus unit tests. 9 | License: Apache License 10 | Suggests: testthat 11 | -------------------------------------------------------------------------------- /R/NAMESPACE: -------------------------------------------------------------------------------- 1 | export(fibonacci) 2 | -------------------------------------------------------------------------------- /R/R/fibonacci.R: -------------------------------------------------------------------------------- 1 | # Copyright 2014 The University of Edinburgh. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 12 | # implied. See the License for the specific language governing 13 | # permissions and limitations under the License. 14 | 15 | #' Calculate the Fibonacci number of the given integer. 16 | #' 17 | #' @param n an integer, if <= 0 then 0 is assumed. 18 | #' @return Fibonacci number 19 | 20 | fibonacci<-function(n) 21 | { 22 | if (n <= 0) 23 | { 24 | return(0) 25 | } 26 | if (n == 1) 27 | { 28 | return(1) 29 | } 30 | return(fibonacci(n - 1) + fibonacci(n - 2)) 31 | } 32 | -------------------------------------------------------------------------------- /R/README.md: -------------------------------------------------------------------------------- 1 | R and testthat 2 | ============== 3 | 4 | Prerequisites 5 | ------------- 6 | 7 | **R**: 8 | 9 | To check if R is installed already: 10 | 11 | ``` 12 | $ R --version 13 | R version 3.2.2 (2015-08-14) -- "Fire Safety" 14 | ``` 15 | 16 | If not, then see [R](https://cran.r-project.org/). 17 | 18 | **testthat test framework**: 19 | 20 | To download and install see [testthat](https://cran.r-project.org/web/packages/testthat/index.html). To quickly check if testthat is installed already, and, if not, to install it, run: 21 | 22 | ``` 23 | $ install.packages("testthat") 24 | ``` 25 | 26 | If you get 27 | 28 | ``` 29 | Warning message: 30 | package testthat is not available (for R version 3.2.2) 31 | ``` 32 | 33 | then manually download and install testthat and its dependencies: 34 | 35 | ``` 36 | $ wget https://cran.r-project.org/src/contrib/testthat_0.10.0.tar.gz 37 | $ wget https://cran.r-project.org/src/contrib/digest_0.6.8.tar.gz 38 | $ wget https://cran.r-project.org/src/contrib/crayon_1.3.1.tar.gz 39 | $ wget https://cran.r-project.org/src/contrib/memoise_0.2.1.tar.gz 40 | $ R CMD INSTALL memoise_0.2.1.tar.gz 41 | $ R CMD INSTALL crayon_1.3.1.tar.gz 42 | $ R CMD INSTALL digest_0.6.8.tar.gz 43 | $ R CMD INSTALL testthat_0.10.0.tar.gz 44 | ``` 45 | 46 | Usage 47 | ----- 48 | 49 | Install: 50 | 51 | ``` 52 | $ cd .. 53 | $ R CMD check R 54 | $ R CMD INSTALL R 55 | ``` 56 | 57 | To install tests too: 58 | 59 | ``` 60 | $ R CMD INSTALL --install-tests R 61 | ``` 62 | 63 | Run: 64 | 65 | ``` 66 | $ cd R/ 67 | $ Rscript exec/fibonacci_client.R 30 68 | fib( 30 ) = 832040 69 | ``` 70 | 71 | Run tests: 72 | 73 | ``` 74 | $ cd tests/ 75 | $ Rscript testthat.R 76 | Loading required package: methods 77 | Loading required package: ssi.r.sample 78 | Fibonacci tests : ..... 79 | 80 | DONE 81 | ``` 82 | 83 | Run tests within R: 84 | 85 | ``` 86 | $ R 87 | > library(testthat) 88 | > library(ssi.r.sample) 89 | > test_file("tests/testthat/test_fibonacci.R") 90 | Fibonacci tests : ..... 91 | 92 | DONE 93 | ``` 94 | 95 | Run package tests, if tests have been installed: 96 | 97 | ``` 98 | $ R 99 | > library(testthat) 100 | > test_package("ssi.r.sample") 101 | Fibonacci tests : .... 102 | 103 | DONE 104 | ``` 105 | -------------------------------------------------------------------------------- /R/exec/fibonacci_client.R: -------------------------------------------------------------------------------- 1 | #' Simple client to calculate the Fibonacci number of the given integer. 2 | #' 3 | #' Usage: Rscript fibonacci_client.R n 4 | #' Example: Rscript fibonacci_client.R 10 5 | 6 | library(ssi.r.sample) 7 | 8 | args <- commandArgs(TRUE) 9 | n <- strtoi(args[1]) 10 | fib <- fibonacci(n) 11 | cat("fib(", n, ") = ", fib, "\n") 12 | -------------------------------------------------------------------------------- /R/tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | test_check("ssi.r.sample", reporter="summary") 3 | -------------------------------------------------------------------------------- /R/tests/testthat/test_fibonacci.R: -------------------------------------------------------------------------------- 1 | # Copyright 2014 The University of Edinburgh. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 12 | # implied. See the License for the specific language governing 13 | # permissions and limitations under the License. 14 | 15 | #' Fibonacci numbers tests. 16 | 17 | library(testthat) 18 | library(ssi.r.sample) 19 | 20 | context("Fibonacci tests") 21 | 22 | test_that("fibonacci(0)",{ 23 | expect_that(0, equals(fibonacci(0))) 24 | }) 25 | 26 | test_that("fibonacci(1)",{ 27 | expect_that(1, equals(fibonacci(1))) 28 | }) 29 | 30 | test_that("fibonacci(2)",{ 31 | expect_that(1, equals(fibonacci(2))) 32 | }) 33 | 34 | test_that("fibonacci(3)",{ 35 | expect_that(2, equals(fibonacci(3))) 36 | }) 37 | 38 | test_that("fibonacci(30)",{ 39 | expect_that(832040, equals(fibonacci(30))) 40 | }) 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Build and Test Examples 2 | ======================= 3 | 4 | Introduction 5 | ------------ 6 | 7 | This repository provides examples of a Fibonacci series function implemented in a range of languages. Build files for popular build tools for each language are also provided as are examples of unit tests written in popular unit test frameworks for each language. These examples are provided to help you get started with using automated build tools and unit test frameworks. They are also used to provide an introduction to the popular continuous integration servers, Jenkins and Travis CI. 8 | 9 | Using this repository for teaching and learning 10 | ----------------------------------------------- 11 | 12 | We are happy if course organisers and students wish to use this repository as a resource for their teaching and learning. However, we request that you **do not to submit Pull Requests to this repository** as when learning about Travis CI. If you wish to use it that way then please **Fork the repository into your own GitHub project or account**. 13 | 14 | Languages, build tools and unit test frameworks 15 | ----------------------------------------------- 16 | 17 | Examples using the following languages, build tools and unit test frameworks are provided. Click on README for information on how to build, run and test each example: 18 | 19 | | Language | Build tool | Unit test framework | README | 20 | | -------- | ---------- | ------------------- | ------ | 21 | | Bash Shell | - | - | [README](./sh/README.md) | 22 | | Python | - | pytest | [README](./python/README.md) | 23 | | Java | ANT | JUnit | [README](./java/README.md) | 24 | | C | Make | CUnit | [README](./c/README.md) | 25 | | C++ | Make | CppUnit and googletest | [README](./cpp/README.md) | 26 | | Fortran | Make | FRUIT | [README](./fortran/README.md) | 27 | | PHP | - | PHPUnit | [README](./php/README.md) | 28 | | R | - | testthat | [README](./R/README.md) | 29 | 30 | Continuous integration 31 | ---------------------- 32 | 33 | Continuous integration can help you to build and test your software regularly. This, in turn, can help you to demonstrate that your software does what it claims to do, and that it does so correctly. It also helps you to rapidly release bug-fixes and up-to-date versions of your software. Continuous integration can also be used to automate experiments that are run using software. For an overview, see The Software Sustainability Institute's [How continuous integration can help you regularly test and release your software](http://software.ac.uk/how-continuous-integration-can-help-you-regularly-test-and-release-your-software). 34 | 35 | **Jenkins** 36 | 37 | [Jenkins](http://jenkins-ci.org) is a popular, open source continuous integration server, which you can deploy locally. For an introduction to Jenkins, using the Fibonacci series examples in a range of languages, see: 38 | 39 | * [Getting started with Jenkins](./jenkins/README.md). The walkthrough assumes you have installed the software required to build and test the Fibonacci series examples (or, at least, that needed by the language you are interested in). 40 | 41 | **Travis CI** 42 | 43 | [Travis CI](https://travis-ci.org/) is a hosted continuous integration server, which provides automated build and test services for projects hosted on GitHub. For an introduction to Travis CI, using the Fibonacci series examples, in a range of languages, see: 44 | 45 | * [Getting started with Travis CI](./travis/README.md) 46 | 47 | *Warning: please be aware that Travis CI has a [security issue](https://blog.aquasec.com/travis-ci-security) with its Free Tier service. By design, “secret” data such as access credentials are exposed within historical clear-text logs which are accessible by anyone via the Travis CI API. Please see this [article](https://blog.aquasec.com/travis-ci-security) for more information.* 48 | 49 | For an overview of hosted continuous integration, see The Software Sustainability Institute's [Hosted continuous integration](http://www.software.ac.uk/resources/guides/hosted-continuous-integration). 50 | 51 | How to contribute 52 | ----------------- 53 | 54 | If you have any comments, corrections or additions then please either raise an [issue](https://github.com/softwaresaved/build_and_test_examples/issues) or submit a pull request. 55 | 56 | Copyright and licence 57 | --------------------- 58 | 59 | Copyright (c) 2014-2018 The University of Edinburgh. 60 | 61 | Code is licensed under the [Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0.html) licence. The licence text is also in [LICENSE-2.0.txt](./LICENSE-2.0.txt). 62 | 63 | Documents are licensed under the Creative Commons [Attribution-NonCommercial 2.5 UK: Scotland (CC BY-NC 2.5 SCOTLAND)](http://creativecommons.org/licenses/by-nc/2.5/scotland/). 64 | 65 | This directory includes third-party software. Please see the `README.md` files in sub-directories for more information. 66 | -------------------------------------------------------------------------------- /c/.gitignore: -------------------------------------------------------------------------------- 1 | ## C 2 | 3 | *.o 4 | fibonacci 5 | fibonacci-tests 6 | CUnitAutomated-Listing.xml 7 | CUnitAutomated-Results.xml 8 | TestResults.xml 9 | -------------------------------------------------------------------------------- /c/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2015 The University of Edinburgh. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 12 | # implied. See the License for the specific language governing 13 | # permissions and limitations under the License. 14 | 15 | CC=gcc -O3 16 | LDFLAGS=-lcunit 17 | 18 | SRCDIR= src 19 | TESTDIR= test 20 | INC=-I$(SRCDIR) -I$(TESTDIR) -I$(HOME)/include 21 | 22 | OBJS=fibonacci.o 23 | TESTS=fibonacci_cunit_test.o 24 | 25 | fibonacci: $(OBJS) fibonacci_program.o 26 | $(CC) -o $@ $^ $(INC) 27 | 28 | fibonacci-tests: $(TESTS) $(OBJS) cunit_test_driver.o 29 | $(CC) -o $@ $^ $(INC) $(LDFLAGS) 30 | 31 | %.o : $(SRCDIR)/%.c 32 | $(CC) -c $^ -o $@ $(INC) 33 | %.o : $(TESTDIR)/%.c 34 | $(CC) -c $< -o $@ $(INC) 35 | 36 | .PHONY : xunit-report 37 | xunit-report : 38 | xsltproc -novalid cunit-to-junit.xsl CUnitAutomated-Results.xml > TestResults.xml 39 | 40 | .PHONY : test 41 | test : fibonacci-tests 42 | ./$< 43 | 44 | .PHONY : all 45 | all : fibonacci test 46 | 47 | .PHONY : clean 48 | clean : 49 | rm -f fibonacci 50 | rm -f fibonacci-tests 51 | rm -f CUnit*.xml 52 | rm -f TestResults.xml 53 | rm -f *.o 54 | rm -f *~ 55 | rm -f src/*~ 56 | rm -f test/*~ 57 | -------------------------------------------------------------------------------- /c/README.md: -------------------------------------------------------------------------------- 1 | C, CUnit and Make 2 | ================= 3 | 4 | Prerequisites 5 | ------------- 6 | 7 | **gcc**: 8 | 9 | To check if `gcc` is installed already: 10 | 11 | ``` 12 | $ gcc -v 13 | gcc version 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC) 14 | ``` 15 | 16 | **CUnit test framework**: 17 | 18 | To download, build and install see [CUnit](http://cunit.sourceforge.net/). The following provides a quick summary of the key steps to build and install CUnit in your home directory: 19 | 20 | ``` 21 | $ wget http://downloads.sourceforge.net/project/cunit/CUnit/2.1-2/CUnit-2.1-2-src.tar.bz2 22 | $ tar -xvjpf CUnit-2.1-2-src.tar.bz2 23 | $ cd CUnit-2.1-2 24 | $ ./configure --prefix=$HOME 25 | $ make 26 | $ make install 27 | $ ls $HOME/include/CUnit 28 | Util.h TestDB.h CUnit_intl.h CUError.h Basic.h 29 | TestRun.h MyMem.h CUnit.h Console.h Automated.h 30 | $ ls $HOME/lib 31 | libcunit.a libcunit.so libcunit.so.1.0.1 32 | libcunit.la libcunit.so.1 33 | $ ls $HOME/share/CUnit 34 | CUnit-List.dtd CUnit-Run.dtd Memory-Dump.dtd 35 | CUnit-List.xsl CUnit-Run.xsl Memory-Dump.xsl 36 | $ export C_INCLUDE_PATH=$HOME/include:$C_INCLUDE_PATH 37 | $ export LIBRARY_PATH=$HOME/lib:$LIBRARY_PATH 38 | $ export LD_LIBRARY_PATH=$HOME/lib:$LD_LIBRARY_PATH 39 | ``` 40 | 41 | **xsltproc XSLT processor**: 42 | 43 | To check if `xsltproc` is installed already: 44 | 45 | ``` 46 | $ xsltproc -version 47 | Using libxml 20706, libxslt 10126 and libexslt 815 48 | xsltproc was compiled against libxml 20706, libxslt 10126 and libexslt 815 49 | libxslt 10126 was compiled against libxml 20706 50 | libexslt 815 was compiled against libxml 20706 51 | ``` 52 | 53 | **CUnit to JUnit XSL transform**: 54 | 55 | This is provided. 56 | 57 | * Files: `cunit-to-junit.xsl`. 58 | * Version: Unspecified. 59 | * Licence: Unspecified. Written by Oliver van Porten. 60 | * Web site: http://www.van-porten.de/2009/05/cunit-tests-in-hudson/. 61 | * Web site: https://bitbucket.org/mcdeck/cunit-to-junit 62 | 63 | Usage 64 | ----- 65 | 66 | Compile: 67 | 68 | ``` 69 | $ make fibonacci 70 | ``` 71 | 72 | Run: 73 | 74 | ``` 75 | $ ./fibonacci 30 76 | fibonacci(30) = 832040 77 | ``` 78 | 79 | Compile and run tests and view XML test report: 80 | 81 | ``` 82 | $ make test 83 | $ cat CUnitAutomated-Results.xml 84 | ``` 85 | 86 | Convert above XML test report into an XML xUnit-style test report: 87 | 88 | ``` 89 | $ make xunit-report 90 | $ cat TestResults.xml 91 | ``` 92 | 93 | Clean up: 94 | 95 | ``` 96 | $ make clean 97 | ``` 98 | -------------------------------------------------------------------------------- /c/cunit-to-junit.xsl: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 0 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 0 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 0 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 0 72 | 73 | 74 | 75 | 76 | Failure 77 | 78 | File: 79 | Line: 80 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /c/set-paths.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | export C_INCLUDE_PATH=$HOME/include:$C_INCLUDE_PATH 3 | export LIBRARY_PATH=$HOME/lib:$LIBRARY_PATH 4 | export LD_LIBRARY_PATH=$HOME/lib:$LD_LIBRARY_PATH 5 | -------------------------------------------------------------------------------- /c/src/fibonacci.c: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The University of Edinburgh. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 12 | // implied. See the License for the specific language governing 13 | // permissions and limitations under the License. 14 | 15 | #include "fibonacci.h" 16 | 17 | unsigned int fibonacci(unsigned int n) 18 | { 19 | if (n < 2) 20 | { 21 | return n; 22 | } 23 | else 24 | { 25 | return fibonacci(n - 1) + fibonacci(n - 2); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /c/src/fibonacci.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The University of Edinburgh. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 12 | // implied. See the License for the specific language governing 13 | // permissions and limitations under the License. 14 | 15 | #ifndef FIBONACCI_H 16 | #define FIBONACCI_H 17 | 18 | /** 19 | * Calculate the Fibonacci number of the given integer. 20 | * 21 | * @param n 22 | * @return Fibonacci number. 23 | */ 24 | unsigned int fibonacci(unsigned int n); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /c/src/fibonacci_program.c: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The University of Edinburgh. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 12 | // implied. See the License for the specific language governing 13 | // permissions and limitations under the License. 14 | 15 | #include 16 | #include "fibonacci.h" 17 | 18 | void print_usage() 19 | { 20 | printf("Usage: ./fibonacci N\n"); 21 | printf(" where N >= 0\n"); 22 | } 23 | 24 | int main(int argc, char **argv) 25 | { 26 | if (argc <= 1) 27 | { 28 | print_usage(); 29 | return(1); 30 | } 31 | int n = atoi(argv[1]); 32 | if (n < 0) 33 | { 34 | print_usage(); 35 | return(2); 36 | } 37 | int fib = fibonacci(n); 38 | printf("fibonacci(%d) = %d\n", n, fib); 39 | return(0); 40 | } 41 | -------------------------------------------------------------------------------- /c/test/cunit_test_driver.c: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The University of Edinburgh. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 12 | // implied. See the License for the specific language governing 13 | // permissions and limitations under the License. 14 | 15 | #include 16 | #include 17 | #include "fibonacci_cunit_test.h" 18 | 19 | /* 20 | * Set up and run tests. 21 | * 22 | * @return CUE_SUCCESS if successful, else a CUnit error code if 23 | * any problems arise. 24 | */ 25 | int main() 26 | { 27 | if (CUE_SUCCESS != CU_initialize_registry()) 28 | { 29 | return CU_get_error(); 30 | } 31 | 32 | CU_pSuite suite = 33 | CU_add_suite("Fibonacci Suite", initialise_suite, cleanup_suite); 34 | if (NULL == suite) 35 | { 36 | CU_cleanup_registry(); 37 | return CU_get_error(); 38 | } 39 | 40 | if ((NULL == CU_add_test(suite, "test_fibonacci_1", test_fibonacci_1)) || 41 | (NULL == CU_add_test(suite, "test_fibonacci_2", test_fibonacci_2)) || 42 | (NULL == CU_add_test(suite, "test_fibonacci_3", test_fibonacci_3)) || 43 | (NULL == CU_add_test(suite, "test_fibonacci_30", test_fibonacci_30))) 44 | { 45 | CU_cleanup_registry(); 46 | return CU_get_error(); 47 | } 48 | 49 | // Run all tests using CUnit Basic interface which outputs 50 | // results to command-line. 51 | CU_basic_set_mode(CU_BRM_VERBOSE); 52 | CU_basic_run_tests(); 53 | 54 | // Run all tests using CUnit Automated interface which outputs 55 | // results to a file, default name CUnitAutomated-Results.xml. 56 | // DTD CUnit-Run.dtd and and XSL stylesheet CUnit-Run.xsl in Share/ 57 | // Uncomment this line to override default output file prefix. 58 | // CU_set_output_filename("Test"); 59 | CU_list_tests_to_file(); 60 | 61 | // Output listing of tests in suites to a file, default name 62 | // CUnitAutomated-Listing.xml 63 | // DTD CUnit-List.dtd and and XSL stylesheet CUnit-List.xsl in Share/ 64 | CU_automated_run_tests(); 65 | 66 | CU_cleanup_registry(); 67 | return CU_get_error(); 68 | } 69 | -------------------------------------------------------------------------------- /c/test/fibonacci_cunit_test.c: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The University of Edinburgh. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 12 | // implied. See the License for the specific language governing 13 | // permissions and limitations under the License. 14 | 15 | #include "fibonacci_cunit_test.h" 16 | 17 | int initialise_suite(void) 18 | { 19 | return 0; 20 | } 21 | 22 | int cleanup_suite(void) 23 | { 24 | return 0; 25 | } 26 | 27 | void test_fibonacci_1(void) 28 | { 29 | CU_ASSERT_EQUAL(fibonacci(1), 1); 30 | } 31 | 32 | void test_fibonacci_2(void) 33 | { 34 | CU_ASSERT_EQUAL(fibonacci(2), 1); 35 | } 36 | 37 | void test_fibonacci_3(void) 38 | { 39 | CU_ASSERT_EQUAL(fibonacci(3), 2); 40 | } 41 | 42 | void test_fibonacci_30(void) 43 | { 44 | CU_ASSERT_EQUAL(fibonacci(30), 832040); 45 | } 46 | -------------------------------------------------------------------------------- /c/test/fibonacci_cunit_test.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The University of Edinburgh. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 12 | // implied. See the License for the specific language governing 13 | // permissions and limitations under the License. 14 | 15 | #ifndef FIBONACCI_CUNIT_TEST_H 16 | #define FIBONACCI_CUNIT_TEST_H 17 | 18 | #include "CUnit/Automated.h" 19 | #include "CUnit/Basic.h" 20 | #include "fibonacci.h" 21 | 22 | /* 23 | * Initialise test suite. 24 | * @return zero on success, non-zero otherwise. 25 | */ 26 | int initialise_suite(void); 27 | 28 | /* 29 | * Clean up test suite. 30 | * @return zero on success, non-zero otherwise. 31 | */ 32 | int cleanup_suite(void); 33 | 34 | /* 35 | * Test fibonacci(1). 36 | */ 37 | void test_fibonacci_1(void); 38 | 39 | /* 40 | * Test fibonacci(2). 41 | */ 42 | void test_fibonacci_2(void); 43 | 44 | /* 45 | * Test fibonacci(3). 46 | */ 47 | void test_fibonacci_3(void); 48 | 49 | /* 50 | * Test fibonacci(30). 51 | */ 52 | void test_fibonacci_30(void); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /cpp/.gitignore: -------------------------------------------------------------------------------- 1 | ## C++ 2 | 3 | *.o 4 | fibonacci 5 | fibonacci-cppunittests 6 | fibonacci-googletests 7 | TestResults.xml 8 | -------------------------------------------------------------------------------- /cpp/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2015 The University of Edinburgh. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 12 | # implied. See the License for the specific language governing 13 | # permissions and limitations under the License. 14 | 15 | CXX=c++ 16 | LDFLAGS=-lcunit 17 | 18 | CPPUNITLDFLAGS=-lcppunit 19 | GOOGLELDFLAGS=-lgtest -lgtest_main 20 | 21 | SRCDIR=src 22 | TESTDIR=test 23 | INC=-I$(SRCDIR) -I$(TESTDIR) -I$(HOME)/include 24 | 25 | HEADER=src/fibonacci.h 26 | CPPUNITTESTS=fibonacci_cppunit_test.o 27 | GOOGLETESTS=fibonacci_google_test.o 28 | 29 | fibonacci: fibonacci_program.o $(HEADER) 30 | $(CXX) -o $@ $^ $(INC) 31 | 32 | fibonacci-cppunittests: $(HEADER) $(CPPUNITTESTS) cppunit_test_driver.o 33 | $(CXX) -o $@ $^ $(INC) $(CPPUNITLDFLAGS) 34 | 35 | fibonacci-googletests: $(HEADER) $(GOOGLETESTS) 36 | $(CXX) -o $@ $^ $(INC) $(GOOGLELDFLAGS) 37 | 38 | %.o : $(SRCDIR)/%.cc $(HEADER) 39 | $(CXX) -c $< -o $@ $(INC) 40 | %.o : $(TESTDIR)/%.cc $(HEADER) 41 | $(CXX) -c $< -o $@ $(INC) 42 | 43 | .PHONY : test 44 | test : fibonacci-cppunittests 45 | ./$< 46 | 47 | .PHONY : googletest 48 | googletest : fibonacci-googletests 49 | ./$< --gtest_output="xml:TestResults.xml" 50 | 51 | .PHONY : all 52 | all : fibonacci test googletest 53 | 54 | .PHONY : clean 55 | clean : 56 | rm -f fibonacci 57 | rm -f fibonacci-cppunittests 58 | rm -f fibonacci-googletests 59 | rm -f TestResults.xml 60 | rm -f *.o 61 | rm -f *~ 62 | rm -f src/*~ 63 | rm -f test/*~ 64 | -------------------------------------------------------------------------------- /cpp/README.md: -------------------------------------------------------------------------------- 1 | C++, CppUnit, googletest and Make 2 | ================================= 3 | 4 | Prerequisites 5 | ------------- 6 | 7 | **c++**: 8 | 9 | To check if `c++` is installed already: 10 | 11 | ``` 12 | 13 | $ c++ -v 14 | gcc version 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC) 15 | ``` 16 | 17 | **CppUnit test framework**: 18 | 19 | To download, build and install see [CppUnit](http://www.freedesktop.org/wiki/Software/cppunit/). The following provides a quick summary of the key steps to build and install CppUnit in your home directory: 20 | 21 | ``` 22 | $ wget http://dev-www.libreoffice.org/src/cppunit-1.13.2.tar.gz 23 | $ tar -xvzf cppunit-1.13.2.tar.gz 24 | $ cd cppunit-1.13.2 25 | $ ./configure --prefix=$HOME 26 | $ make 27 | $ make install 28 | $ ls $HOME/include/cppunit 29 | AdditionalMessage.h Protector.h TestResultCollector.h 30 | Asserter.h SourceLine.h TestResult.h 31 | BriefTestProgressListener.h SynchronizedObject.h TestRunner.h 32 | CompilerOutputter.h TestAssert.h TestSuccessListener.h 33 | config TestCaller.h TestSuite.h 34 | config-auto.h TestCase.h TextOutputter.h 35 | Exception.h TestComposite.h TextTestProgressListener.h 36 | extensions TestFailure.h TextTestResult.h 37 | Message.h TestFixture.h TextTestRunner.h 38 | Outputter.h Test.h tools 39 | plugin TestLeaf.h ui 40 | portability TestListener.h XmlOutputter.h 41 | Portability.h TestPath.h XmlOutputterHook.h 42 | $ ls $HOME/lib 43 | libcppunit-1.13.so.0 libcppunit.a libcppunit.so 44 | libcppunit-1.13.so.0.0.2 libcppunit.la 45 | $ ls $HOME/share/cppunit 46 | html 47 | $ export CPLUS_INCLUDE_PATH=$HOME/include:$CPLUS_INCLUDE_PATH 48 | $ export LIBRARY_PATH=$HOME/lib:$LIBRARY_PATH 49 | $ export LD_LIBRARY_PATH=$HOME/lib:$LD_LIBRARY_PATH 50 | ``` 51 | 52 | **googletest test framework**: 53 | 54 | To download, build and install see [googletest](https://github.com/google/googletest/). The following provides a quick summary of the key steps to build and install googletest in your home directory: 55 | 56 | ``` 57 | $ wget https://github.com/google/googletest/archive/release-1.7.0.zip 58 | $ unzip release-1.7.0.zip 59 | $ cd googletest-release-1.7.0/ 60 | $ mkdir build 61 | $ cd build 62 | $ cmake .. -Dgtest_disable_pthreads=ON 63 | $ make 64 | $ mkdir $HOME/include 65 | $ cp -r ../include/gtest/ $HOME/include/ 66 | $ mkdir $HOME/lib 67 | $ cp libgtest*a $HOME/lib/ 68 | $ ls $HOME/include/gtest 69 | gtest-death-test.h gtest-param-test.h.pump gtest-spi.h 70 | gtest.h gtest_pred_impl.h gtest-test-part.h 71 | gtest-message.h gtest-printers.h gtest-typed-test.h 72 | gtest-param-test.h gtest_prod.h internal 73 | $ ls $HOME/lib 74 | libgtest.a libgtest_main.a 75 | $ export CPLUS_INCLUDE_PATH=$HOME/include:$CPLUS_INCLUDE_PATH 76 | $ export LIBRARY_PATH=$HOME/lib:$LIBRARY_PATH 77 | $ export LD_LIBRARY_PATH=$HOME/lib:$LD_LIBRARY_PATH 78 | ``` 79 | 80 | Usage 81 | ----- 82 | 83 | Compile: 84 | 85 | ``` 86 | $ make fibonacci 87 | ``` 88 | 89 | Run: 90 | 91 | ``` 92 | $ ./fibonacci 30 93 | fibonacci(30) = 832040 94 | ``` 95 | 96 | Compile and run CppUnit tests and view XML test report: 97 | 98 | ``` 99 | $ make test 100 | $ cat TestResults.xml 101 | ``` 102 | 103 | Compile and run googletest tests and view XML xUnit-style test report: 104 | 105 | ``` 106 | $ make googletest 107 | $ cat TestResults.xml 108 | ``` 109 | 110 | Clean up: 111 | 112 | ``` 113 | $ make clean 114 | ``` 115 | 116 | Comments on CppUnit 1.13.2 117 | -------------------------- 118 | 119 | According to Wikipedia, "CppUnit has been forked several times and the current, actively maintained version is by Markus Mohrhard of the LibreOffice project (which uses CppUnit heavily)". This is the version used above. 120 | 121 | Documentation for an earlier version are in the last three links below: 122 | 123 | * Wikipedia - [CppUnit](http://en.wikipedia.org/wiki/CppUnit). 124 | * LibreOffice [CppUnit](http://www.freedesktop.org/wiki/Software/cppunit/). 125 | * Original [CppUnit](http://sourceforge.net/apps/mediawiki/cppunit/index.php?title=Main_Page) project on SourceForge. 126 | * [CppUnit Cookbook](http://cppunit.sourceforge.net/doc/1.11.6/cppunit_cookbook.html). 127 | * [CppUnit assertons](http://cppunit.sourceforge.net/doc/1.11.6/group___assertions.html). 128 | 129 | If during `configure` you get: 130 | 131 | ``` 132 | dirname: extra operand `/bin' 133 | ``` 134 | 135 | edit `configure` and replace all occurrences of: 136 | 137 | ``` 138 | /* automatically generated */ 139 | ``` 140 | 141 | with: 142 | 143 | ``` 144 | $ac_prefix_conf_INP 145 | ``` 146 | 147 | See CppUnit [support request 53](http://sourceforge.net/p/cppunit/support-requests/53/) for more information. 148 | 149 | `cppunit-config` displays C++ flags to use: 150 | 151 | ``` 152 | $ cd ~/bin 153 | $ ./cppunit-config --cflags 154 | -I$HOME/include 155 | $ ./cppunit-config --libs 156 | -L$HOME/lib -lcppunit -ldl 157 | ``` 158 | -------------------------------------------------------------------------------- /cpp/set-paths.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | export CPLUS_INCLUDE_PATH=$HOME/include:$CPLUS_INCLUDE_PATH 3 | export LIBRARY_PATH=$HOME/lib:$LIBRARY_PATH 4 | export LD_LIBRARY_PATH=$HOME/lib:$LD_LIBRARY_PATH 5 | -------------------------------------------------------------------------------- /cpp/src/fibonacci.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The University of Edinburgh. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 12 | // implied. See the License for the specific language governing 13 | // permissions and limitations under the License. 14 | 15 | #ifndef FIBONACCI_H 16 | #define FIBONACCI_H 17 | 18 | /** 19 | * Fibonacci numbers class. 20 | */ 21 | class Fibonacci 22 | { 23 | public: 24 | /** 25 | * Calculate the Fibonacci number of the given integer. 26 | * 27 | * @param n 28 | * @return Fibonacci number. 29 | */ 30 | static unsigned int fibonacci(unsigned int n) 31 | { 32 | if (n < 2) 33 | { 34 | return n; 35 | } 36 | else 37 | { 38 | return fibonacci(n - 1) + fibonacci(n - 2); 39 | } 40 | } 41 | }; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /cpp/src/fibonacci_program.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The University of Edinburgh. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 12 | // implied. See the License for the specific language governing 13 | // permissions and limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include "fibonacci.h" 20 | 21 | using namespace std; 22 | 23 | void print_usage() 24 | { 25 | cout << "Usage: ./fibonacci N\n"; 26 | cout << " where N >= 0\n"; 27 | } 28 | 29 | int main(int argc, char **argv) 30 | { 31 | if (argc <= 1) 32 | { 33 | print_usage(); 34 | return(1); 35 | } 36 | int n = atoi(argv[1]); 37 | if (n < 0) 38 | { 39 | print_usage(); 40 | return(2); 41 | } 42 | int fib = Fibonacci::fibonacci(n); 43 | cout << "fibonacci(" << n << ") = " << fib << "\n"; 44 | return(0); 45 | } 46 | -------------------------------------------------------------------------------- /cpp/test/cppunit_test_driver.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2015 The University of Edinburgh. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 12 | // implied. See the License for the specific language governing 13 | // permissions and limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | /* 28 | * Set up and run tests. 29 | * 30 | * @return 0 if successful else 1. 31 | */ 32 | int main() 33 | { 34 | // Set up result collection. 35 | CppUnit::TestResult controller; 36 | CppUnit::TestResultCollector result; 37 | controller.addListener(&result); 38 | CppUnit::BriefTestProgressListener progressListener; 39 | controller.addListener(&progressListener); 40 | 41 | std::ofstream xmlout("TestResults.xml"); 42 | CppUnit::XmlOutputter xmlOutputter (&result, xmlout); 43 | CppUnit::TextOutputter consoleOutputter (&result, std::cout); 44 | 45 | CppUnit::TextUi::TestRunner runner; 46 | CppUnit::TestFactoryRegistry ®istry = 47 | CppUnit::TestFactoryRegistry::getRegistry(); 48 | runner.addTest(registry.makeTest()); 49 | 50 | runner.run(controller); 51 | 52 | xmlOutputter.write(); 53 | consoleOutputter.write(); 54 | 55 | return result.wasSuccessful() ? 0 : 1; 56 | } 57 | -------------------------------------------------------------------------------- /cpp/test/fibonacci_cppunit_test.cc: -------------------------------------------------------------------------------- 1 | 2 | // Copyright 2014 The University of Edinburgh. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | // implied. See the License for the specific language governing 14 | // permissions and limitations under the License. 15 | 16 | #include 17 | #include "fibonacci.h" 18 | 19 | /** 20 | * Test class for Fibonacci. 21 | */ 22 | class FibonacciTest:public CppUnit::TestFixture 23 | { 24 | 25 | CPPUNIT_TEST_SUITE(FibonacciTest); 26 | CPPUNIT_TEST(testFibonacci1); 27 | CPPUNIT_TEST(testFibonacci2); 28 | CPPUNIT_TEST(testFibonacci3); 29 | CPPUNIT_TEST(testFibonacci30); 30 | CPPUNIT_TEST_SUITE_END(); 31 | 32 | public: 33 | 34 | /* Initialise test suite - no-op. */ 35 | void setUp() 36 | { 37 | // No-op. 38 | } 39 | 40 | /* Clean up test suite - no-op. */ 41 | void tearDown() { 42 | // No-op. 43 | } 44 | 45 | /* Test Fibonacci::fibonacci(1). */ 46 | void testFibonacci1() { 47 | int result = Fibonacci::fibonacci(1); 48 | CPPUNIT_ASSERT_EQUAL(1, result); 49 | } 50 | 51 | /* Test Fibonacci::fibonacci(2). */ 52 | void testFibonacci2() { 53 | int result = Fibonacci::fibonacci(2); 54 | CPPUNIT_ASSERT_EQUAL(1, result); 55 | } 56 | 57 | /* Test Fibonacci::fibonacci(3). */ 58 | void testFibonacci3() { 59 | int result = Fibonacci::fibonacci(3); 60 | CPPUNIT_ASSERT_EQUAL(2, result); 61 | } 62 | 63 | /* Test Fibonacci::fibonacci(30). */ 64 | void testFibonacci30() { 65 | int result = Fibonacci::fibonacci(30); 66 | CPPUNIT_ASSERT_EQUAL(832040, result); 67 | } 68 | }; 69 | 70 | CPPUNIT_TEST_SUITE_REGISTRATION(FibonacciTest); 71 | -------------------------------------------------------------------------------- /cpp/test/fibonacci_google_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The University of Edinburgh. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 12 | // implied. See the License for the specific language governing 13 | // permissions and limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | 20 | #include "fibonacci.h" 21 | 22 | class FibonacciTest : public ::testing::Test 23 | { 24 | protected: 25 | 26 | /* Initialise test suite - no-op. */ 27 | virtual void SetUp() 28 | { 29 | // No-op. 30 | } 31 | 32 | /* Clean up test suite - no-op. */ 33 | virtual void TearDown() { 34 | // No-op. 35 | } 36 | }; 37 | 38 | TEST_F(FibonacciTest, fibonacci1) 39 | { 40 | int result = Fibonacci::fibonacci(1); 41 | ASSERT_EQ(1, result); 42 | } 43 | 44 | TEST_F(FibonacciTest, fibonacci2) 45 | { 46 | int result = Fibonacci::fibonacci(2); 47 | ASSERT_EQ(1, result); 48 | } 49 | 50 | TEST_F(FibonacciTest, fibonacci3) 51 | { 52 | int result = Fibonacci::fibonacci(3); 53 | ASSERT_EQ(2, result); 54 | } 55 | 56 | TEST_F(FibonacciTest, fibonacci30) 57 | { 58 | int result = Fibonacci::fibonacci(30); 59 | ASSERT_EQ(832040, result); 60 | } 61 | -------------------------------------------------------------------------------- /fortran/.gitignore: -------------------------------------------------------------------------------- 1 | ## Fortran 2 | 3 | *.mod 4 | *.o 5 | fibonacci 6 | fibonacci-tests 7 | result*.xml 8 | -------------------------------------------------------------------------------- /fortran/FRUIT_LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | License: 3 | 4 | Copyright (c) 2005-2010, 2012-2013, Andrew Hang Chen and contributors, 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | * Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | * Neither the name of the Westinghouse Electric Company nor the 15 | names of its contributors may be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL ANDREW HANG CHEN AND CONTRIBUTORS BE LIABLE FOR ANY 22 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | 30 | Note: 31 | The orignal work of FRUIT was 32 | created by Andrew Hang Chen while working at Westinghouse Electric 33 | Company. The package was donated by Westinghouse Electric Company as 34 | an open source project. 35 | 36 | 37 | Contributors: 38 | Andrew Hang Chen 39 | sgould 40 | istomoya 41 | If you feel you should be listed here and aren't, please let us know. 42 | 43 | 44 | -------------------------------------------------------------------------------- /fortran/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2015 The University of Edinburgh. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 12 | # implied. See the License for the specific language governing 13 | # permissions and limitations under the License. 14 | 15 | FORTRAN=gfortran 16 | FLAGS=-O0 --std=f2003 17 | 18 | SRCDIR=src 19 | TESTDIR=test 20 | FRUITDIR=fruit 21 | 22 | OBJS=fibonacci.o 23 | TESTS=fruit_helpers.o fibonacci_test.o fruit_test_driver.o 24 | FRUITS=fruit_util.o fruit.o 25 | 26 | fibonacci : $(OBJS) fibonacci_program.o 27 | $(FORTRAN) $(FLAGS) $^ -o $@ 28 | 29 | fibonacci-tests : $(FRUITS) $(OBJS) $(TESTS) 30 | $(FORTRAN) $(FLAGS) $^ -o $@ 31 | 32 | %.o : $(SRCDIR)/%.f90 33 | $(FORTRAN) $(FLAGS) -c $< -o $@ 34 | %.o : $(TESTDIR)/%.f90 35 | $(FORTRAN) $(FLAGS) -c $< -o $@ 36 | %.o : $(TESTDIR)/%.F90 37 | $(FORTRAN) $(FLAGS) -c $< -o $@ 38 | %.o : $(FRUITDIR)/%.f90 39 | $(FORTRAN) $(FLAGS) -c $< -o $@ 40 | 41 | .PHONY : test 42 | test : fibonacci-tests 43 | ./$< 44 | 45 | .PHONY : all 46 | all : fibonacci test 47 | 48 | .PHONY : clean 49 | clean : 50 | rm -f fibonacci 51 | rm -f fibonacci-tests 52 | rm -f result*.xml 53 | rm -f *.mod 54 | rm -f *.o 55 | rm -f *~ 56 | rm -f src/*~ 57 | rm -f test/*~ 58 | -------------------------------------------------------------------------------- /fortran/README.md: -------------------------------------------------------------------------------- 1 | Fortran, FRUIT and Make 2 | ======================= 3 | 4 | Prerequisites 5 | ------------- 6 | 7 | **gfortran**: 8 | 9 | To check if `gfortran` is installed already: 10 | 11 | ``` 12 | $ gfortran -v 13 | gcc version 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC) 14 | ``` 15 | 16 | **FRUIT test framework**: 17 | 18 | This is provided. 19 | 20 | * Files: `fruit/*` 21 | * Version: 3.3.4, downloaded 02/06/14. 22 | * License: BSD license, `FRUIT_LICENSE.txt`. 23 | * Web site: http://sourceforge.net/projects/fortranxunit/. 24 | * Used by: test code in `test/`. 25 | 26 | Usage 27 | ----- 28 | 29 | Compile: 30 | 31 | ``` 32 | $ make fibonacci 33 | ``` 34 | 35 | Run: 36 | 37 | ``` 38 | $ ./fibonacci 30 39 | fibonacci( 30 ) = 832040 40 | ``` 41 | 42 | Compile and run tests and view XML xUnit-style test report: 43 | 44 | ``` 45 | $ make test 46 | $ cat result.xml 47 | ``` 48 | 49 | Clean up: 50 | 51 | ``` 52 | $ make clean 53 | ``` 54 | -------------------------------------------------------------------------------- /fortran/fruit/LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | License: 3 | 4 | Copyright (c) 2005-2010, 2012-2013, Andrew Hang Chen and contributors, 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | * Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | * Neither the name of the Westinghouse Electric Company nor the 15 | names of its contributors may be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL ANDREW HANG CHEN AND CONTRIBUTORS BE LIABLE FOR ANY 22 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | 30 | Note: 31 | The orignal work of FRUIT was 32 | created by Andrew Hang Chen while working at Westinghouse Electric 33 | Company. The package was donated by Westinghouse Electric Company as 34 | an open source project. 35 | 36 | 37 | Contributors: 38 | Andrew Hang Chen 39 | sgould 40 | istomoya 41 | If you feel you should be listed here and aren't, please let us know. 42 | 43 | 44 | -------------------------------------------------------------------------------- /fortran/fruit/fruit_util.f90: -------------------------------------------------------------------------------- 1 | 2 | ! Copyright (c) 2005-2010, 2012-2013, Andrew Hang Chen and contributors, 3 | ! All rights reserved. 4 | ! Licensed under the 3-clause BSD license. 5 | 6 | module fruit_util 7 | private 8 | 9 | public :: equals, to_s, strip 10 | 11 | interface equals 12 | module procedure equalEpsilon 13 | module procedure floatEqual 14 | module procedure integerEqual 15 | module procedure doublePrecisionEqual 16 | module procedure stringEqual 17 | module procedure logicalEqual 18 | end interface 19 | 20 | interface to_s 21 | module procedure to_s_int_ 22 | module procedure to_s_real_ 23 | module procedure to_s_logical_ 24 | module procedure to_s_double_ 25 | module procedure to_s_complex_ 26 | module procedure to_s_double_complex_ 27 | module procedure to_s_string_ 28 | end interface 29 | 30 | interface strip 31 | module procedure strip_ 32 | module procedure strip_length_ 33 | end interface 34 | contains 35 | 36 | function to_s_int_ (value) 37 | implicit none 38 | character(len=500):: to_s_int_ 39 | integer, intent(in) :: value 40 | character(len=500) :: result 41 | write (result, *) value 42 | to_s_int_ = adjustl(trim(result)) 43 | end function to_s_int_ 44 | 45 | function to_s_real_ (value) 46 | implicit none 47 | character(len=500):: to_s_real_ 48 | real, intent(in) :: value 49 | character(len=500) :: result 50 | write (result, *) value 51 | to_s_real_ = adjustl(trim(result)) 52 | end function to_s_real_ 53 | 54 | function to_s_double_ (value) 55 | implicit none 56 | character(len=500):: to_s_double_ 57 | double precision, intent(in) :: value 58 | character(len=500) :: result 59 | write (result, *) value 60 | to_s_double_ = adjustl(trim(result)) 61 | end function to_s_double_ 62 | 63 | function to_s_complex_ (value) 64 | implicit none 65 | character(len=500):: to_s_complex_ 66 | complex, intent(in) :: value 67 | character(len=500) :: result 68 | write (result, *) value 69 | to_s_complex_ = adjustl(trim(result)) 70 | end function to_s_complex_ 71 | 72 | function to_s_double_complex_ (value) 73 | implicit none 74 | character(len=500):: to_s_double_complex_ 75 | complex(kind=kind(1.0D0)), intent(in) :: value 76 | character(len=500) :: result 77 | write (result, *) value 78 | to_s_double_complex_ = adjustl(trim(result)) 79 | end function to_s_double_complex_ 80 | 81 | function to_s_logical_ (value) 82 | implicit none 83 | character(len=500):: to_s_logical_ 84 | logical, intent(in) :: value 85 | character(len=500) :: result 86 | write (result, *) value 87 | to_s_logical_ = adjustl(trim(result)) 88 | end function to_s_logical_ 89 | 90 | function to_s_string_ (value) 91 | implicit none 92 | character(len=500):: to_s_string_ 93 | character(len=*), intent(in) :: value 94 | to_s_string_ = value 95 | end function to_s_string_ 96 | 97 | function strip_(value) 98 | implicit none 99 | character(len=500):: strip_ 100 | character(len=*), intent(in) :: value 101 | strip_ = trim(adjustl(value)) 102 | end function strip_ 103 | 104 | function strip_length_(value, length) 105 | implicit none 106 | character(len=*), intent(in) :: value 107 | integer, intent(in) :: length 108 | character(len= length):: strip_length_ 109 | strip_length_ = trim(adjustl(value)) 110 | end function strip_length_ 111 | 112 | !------------------------ 113 | ! test if 2 values are close 114 | !------------------------ 115 | !logical function equals (number1, number2) 116 | ! real, intent (in) :: number1, number2 117 | ! 118 | ! return equalEpsilon (number1, number2, epsilon(number1)) 119 | ! 120 | !end function equals 121 | 122 | 123 | function equalEpsilon (number1, number2, epsilon ) result (resultValue) 124 | real , intent (in) :: number1, number2, epsilon 125 | logical :: resultValue 126 | 127 | resultValue = .false. 128 | 129 | ! test very small number1 130 | if ( abs(number1) < epsilon .and. abs(number1 - number2) < epsilon ) then 131 | resultValue = .true. 132 | else 133 | if ((abs(( number1 - number2)) / number1) < epsilon ) then 134 | resultValue = .true. 135 | else 136 | resultValue = .false. 137 | end if 138 | end if 139 | 140 | end function equalEpsilon 141 | 142 | function floatEqual (number1, number2 ) result (resultValue) 143 | real , intent (in) :: number1, number2 144 | real :: epsilon 145 | logical :: resultValue 146 | 147 | resultValue = .false. 148 | epsilon = 1E-6 149 | 150 | ! test very small number1 151 | if ( abs(number1) < epsilon .and. abs(number1 - number2) < epsilon ) then 152 | resultValue = .true. 153 | else 154 | if ((abs(( number1 - number2)) / number1) < epsilon ) then 155 | resultValue = .true. 156 | else 157 | resultValue = .false. 158 | end if 159 | end if 160 | end function floatEqual 161 | 162 | function doublePrecisionEqual (number1, number2 ) result (resultValue) 163 | double precision , intent (in) :: number1, number2 164 | real :: epsilon 165 | logical :: resultValue 166 | 167 | resultValue = .false. 168 | epsilon = 1E-6 169 | !epsilon = epsilon (number1) 170 | 171 | ! test very small number1 172 | if ( abs(number1) < epsilon .and. abs(number1 - number2) < epsilon ) then 173 | resultValue = .true. 174 | else 175 | if ((abs(( number1 - number2)) / number1) < epsilon ) then 176 | resultValue = .true. 177 | else 178 | resultValue = .false. 179 | end if 180 | end if 181 | end function doublePrecisionEqual 182 | 183 | function integerEqual (number1, number2 ) result (resultValue) 184 | integer , intent (in) :: number1, number2 185 | logical :: resultValue 186 | 187 | resultValue = .false. 188 | 189 | if ( number1 .eq. number2 ) then 190 | resultValue = .true. 191 | else 192 | resultValue = .false. 193 | end if 194 | end function integerEqual 195 | 196 | function stringEqual (str1, str2 ) result (resultValue) 197 | character(*) , intent (in) :: str1, str2 198 | logical :: resultValue 199 | 200 | resultValue = .false. 201 | 202 | if ( str1 .eq. str2 ) then 203 | resultValue = .true. 204 | end if 205 | end function stringEqual 206 | 207 | function logicalEqual (l1, l2 ) result (resultValue) 208 | logical, intent (in) :: l1, l2 209 | logical :: resultValue 210 | 211 | resultValue = .false. 212 | 213 | if ( l1 .eqv. l2 ) then 214 | resultValue = .true. 215 | end if 216 | end function logicalEqual 217 | 218 | end module fruit_util 219 | -------------------------------------------------------------------------------- /fortran/src/fibonacci.f90: -------------------------------------------------------------------------------- 1 | !> Fibonacci numbers module. 2 | 3 | !! Copyright 2014 The University of Edinburgh. 4 | !! 5 | !! Licensed under the Apache License, Version 2.0 (the "License"); 6 | !! you may not use this file except in compliance with the License. 7 | !! You may obtain a copy of the License at 8 | !! 9 | !! http://www.apache.org/licenses/LICENSE-2.0 10 | !! 11 | !! Unless required by applicable law or agreed to in writing, software 12 | !! distributed under the License is distributed on an "AS IS" BASIS, 13 | !! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | !! implied. See the License for the specific language governing 15 | !! permissions and limitations under the License. 16 | 17 | module fibonacci_module 18 | 19 | implicit none 20 | 21 | contains 22 | 23 | !> Calculate the Fibonacci number of the given integer. 24 | recursive function fibonacci(n) result (fib) 25 | integer, intent(in) :: n !< If n <= 0 then 0 is assumed. 26 | integer :: fib !< Fibonacci number 27 | if (n < 2) then 28 | fib = n 29 | else 30 | fib = fibonacci(n - 1) + fibonacci(n - 2) 31 | endif 32 | end function fibonacci 33 | 34 | end module fibonacci_module 35 | -------------------------------------------------------------------------------- /fortran/src/fibonacci_program.f90: -------------------------------------------------------------------------------- 1 | !> Command-line tool to calculate the Fibonacci number of a given 2 | !! integer. 3 | 4 | !! Copyright 2014 The University of Edinburgh. 5 | !! 6 | !! Licensed under the Apache License, Version 2.0 (the "License"); 7 | !! you may not use this file except in compliance with the License. 8 | !! You may obtain a copy of the License at 9 | !! 10 | !! http://www.apache.org/licenses/LICENSE-2.0 11 | !! 12 | !! Unless required by applicable law or agreed to in writing, software 13 | !! distributed under the License is distributed on an "AS IS" BASIS, 14 | !! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 15 | !! implied. See the License for the specific language governing 16 | !! permissions and limitations under the License. 17 | 18 | program fibonacci_program 19 | 20 | use fibonacci_module 21 | 22 | implicit none 23 | 24 | integer :: num_arguments, n, fib 25 | character(60) :: argument 26 | 27 | num_arguments=command_argument_count() 28 | if (num_arguments == 0) then 29 | call print_usage() 30 | stop 1 31 | end if 32 | call get_command_argument(1, argument) 33 | read(argument,*) n 34 | if (n < 0) then 35 | call print_usage() 36 | stop 2 37 | end if 38 | fib = fibonacci(n) 39 | write(*,*) 'fibonacci(',n,') = ',fib 40 | 41 | contains 42 | 43 | subroutine print_usage() 44 | write(*,*) 'Usage: ./fibonacci N' 45 | write(*,*) ' where N >= 0' 46 | end subroutine print_usage 47 | 48 | end program fibonacci_program 49 | -------------------------------------------------------------------------------- /fortran/test/fibonacci_test.f90: -------------------------------------------------------------------------------- 1 | !> Test module for fibonacci_module. 2 | 3 | !! Copyright 2014 The University of Edinburgh. 4 | !! 5 | !! Licensed under the Apache License, Version 2.0 (the "License"); 6 | !! you may not use this file except in compliance with the License. 7 | !! You may obtain a copy of the License at 8 | !! 9 | !! http://www.apache.org/licenses/LICENSE-2.0 10 | !! 11 | !! Unless required by applicable law or agreed to in writing, software 12 | !! distributed under the License is distributed on an "AS IS" BASIS, 13 | !! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | !! implied. See the License for the specific language governing 15 | !! permissions and limitations under the License. 16 | 17 | module fibonacci_test 18 | use fruit 19 | use fruit_helpers 20 | use fibonacci_module 21 | 22 | implicit none 23 | 24 | contains 25 | 26 | !> Initialise test suite - no-op. 27 | subroutine setup 28 | end subroutine setup 29 | 30 | !> Clean up test suite - no-op. 31 | subroutine teardown 32 | end subroutine teardown 33 | 34 | !> Test fibonacci(1). 35 | subroutine test_fibonacci1() 36 | call assert_equals(1, fibonacci(1)) 37 | end subroutine test_fibonacci1 38 | 39 | !> Test fibonacci(2). 40 | subroutine test_fibonacci2() 41 | call assert_equals(1, fibonacci(2)) 42 | end subroutine test_fibonacci2 43 | 44 | !> Test fibonacci(3). 45 | subroutine test_fibonacci3() 46 | call assert_equals(2, fibonacci(3)) 47 | end subroutine test_fibonacci3 48 | 49 | !> Test fibonacci(30). 50 | subroutine test_fibonacci30() 51 | call assert_equals(832040, fibonacci(30)) 52 | end subroutine test_fibonacci30 53 | 54 | !> Call each test. 55 | subroutine fibonacci_basket() 56 | character(len=*) :: suite_name 57 | parameter(suite_name='fibonacci_test') 58 | 59 | call run_fruit_test_case(test_fibonacci1,'test_fibonacci1',& 60 | setup,teardown,suite_name) 61 | call run_fruit_test_case(test_fibonacci2,'test_fibonacci2',& 62 | setup,teardown,suite_name) 63 | call run_fruit_test_case(test_fibonacci3,'test_fibonacci3',& 64 | setup,teardown,suite_name) 65 | call run_fruit_test_case(test_fibonacci30,'test_fibonacci30',& 66 | setup,teardown,suite_name) 67 | 68 | end subroutine fibonacci_basket 69 | 70 | end module fibonacci_test 71 | -------------------------------------------------------------------------------- /fortran/test/fruit_helpers.F90: -------------------------------------------------------------------------------- 1 | !> FRUIT unit test framework helper subroutines. 2 | !! Based on driver code auto-generated by FRUIT's Ruby pre-processor. 3 | 4 | !! Copyright 2014 The University of Edinburgh. 5 | !! 6 | !! Licensed under the Apache License, Version 2.0 (the "License"); 7 | !! you may not use this file except in compliance with the License. 8 | !! You may obtain a copy of the License at 9 | !! 10 | !! http://www.apache.org/licenses/LICENSE-2.0 11 | !! 12 | !! Unless required by applicable law or agreed to in writing, software 13 | !! distributed under the License is distributed on an "AS IS" BASIS, 14 | !! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 15 | !! implied. See the License for the specific language governing 16 | !! permissions and limitations under the License. 17 | 18 | module fruit_helpers 19 | 20 | use fruit 21 | implicit none 22 | 23 | contains 24 | 25 | !> Invoke a test case sub-routine of a test suite, invoking the 26 | !! suite's setup sub-routine first, and its teardown sub-routine 27 | !! after. This sub-routine was abstracted out from "basket" code 28 | !! auto-generated by FRUIT's Ruby pre-processor. 29 | subroutine run_fruit_test_case(test_case,test_case_name, & 30 | setup,teardown,test_suite_name) 31 | interface 32 | subroutine test_case() 33 | end subroutine 34 | end interface 35 | character(*),intent(in) :: test_case_name 36 | interface 37 | subroutine setup() 38 | end subroutine 39 | end interface 40 | interface 41 | subroutine teardown() 42 | end subroutine 43 | end interface 44 | character(*),intent(in) :: test_suite_name 45 | 46 | call setup() 47 | write(*,'(/A,A,A,A)') 'Running: ',test_suite_name,':',test_case_name 48 | call set_unit_name(test_case_name) 49 | call run_test_case(test_case,test_case_name) 50 | if (.not. is_case_passed()) then 51 | call case_failed_xml(test_case_name,test_suite_name) 52 | else 53 | call case_passed_xml(test_case_name,test_suite_name) 54 | end if 55 | call teardown() 56 | end subroutine run_fruit_test_case 57 | 58 | end module fruit_helpers 59 | -------------------------------------------------------------------------------- /fortran/test/fruit_test_driver.F90: -------------------------------------------------------------------------------- 1 | !> FRUIT unit test framework driver. 2 | 3 | program fruit_test_driver 4 | 5 | use fruit 6 | 7 | ! Add modules here... 8 | use fibonacci_test 9 | 10 | call init_fruit() 11 | call init_fruit_xml() 12 | 13 | ! Add module basket calls here.. 14 | call fibonacci_basket() 15 | 16 | call fruit_summary() 17 | call fruit_summary_xml() 18 | call fruit_finalize() 19 | 20 | end program fruit_test_driver 21 | -------------------------------------------------------------------------------- /java/.gitignore: -------------------------------------------------------------------------------- 1 | ## Java 2 | 3 | *.class 4 | build 5 | -------------------------------------------------------------------------------- /java/JUNIT_LICENSE.txt: -------------------------------------------------------------------------------- 1 | JUnit license - http://junit.org for JUnit 4.10 2 | 3 | Common Public License - v 1.0 4 | THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS COMMON PUBLIC 5 | LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM 6 | CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. 7 | 8 | 1. DEFINITIONS 9 | 10 | "Contribution" means: 11 | a) in the case of the initial Contributor, the initial code and 12 | documentation distributed under this Agreement, and 13 | b) in the case of each subsequent Contributor: 14 | i) changes to the Program, and 15 | ii) additions to the Program; 16 | where such changes and/or additions to the Program originate from and are 17 | distributed by that particular Contributor. A Contribution 'originates' from a 18 | Contributor if it was added to the Program by such Contributor itself or anyone 19 | acting on such Contributor's behalf. Contributions do not include additions to 20 | the Program which: (i) are separate modules of software distributed in 21 | conjunction with the Program under their own license agreement, and (ii) are 22 | not derivative works of the Program. 23 | "Contributor" means any person or entity that distributes the Program. 24 | "Licensed Patents " mean patent claims licensable by a Contributor which are 25 | necessarily infringed by the use or sale of its Contribution alone or when 26 | combined with the Program. 27 | "Program" means the Contributions distributed in accordance with this Agreement. 28 | "Recipient" means anyone who receives the Program under this Agreement, 29 | including all Contributors. 30 | 31 | 2. GRANT OF RIGHTS 32 | 33 | a) Subject to the terms of this Agreement, each Contributor hereby grants 34 | Recipient a non-exclusive, worldwide, royalty-free copyright license to 35 | reproduce, prepare derivative works of, publicly display, publicly perform, 36 | distribute and sublicense the Contribution of such Contributor, if any, and 37 | such derivative works, in source code and object code form. 38 | b) Subject to the terms of this Agreement, each Contributor hereby grants 39 | Recipient a non-exclusive, worldwide, royalty-free patent license under 40 | Licensed Patents to make, use, sell, offer to sell, import and otherwise 41 | transfer the Contribution of such Contributor, if any, in source code and 42 | object code form. This patent license shall apply to the combination of the 43 | Contribution and the Program if, at the time the Contribution is added by the 44 | Contributor, such addition of the Contribution causes such combination to be 45 | covered by the Licensed Patents. The patent license shall not apply to any 46 | other combinations which include the Contribution. No hardware per se is 47 | licensed hereunder. 48 | c) Recipient understands that although each Contributor grants the 49 | licenses to its Contributions set forth herein, no assurances are provided by 50 | any Contributor that the Program does not infringe the patent or other 51 | intellectual property rights of any other entity. Each Contributor disclaims 52 | any liability to Recipient for claims brought by any other entity based on 53 | infringement of intellectual property rights or otherwise. As a condition to 54 | exercising the rights and licenses granted hereunder, each Recipient hereby 55 | assumes sole responsibility to secure any other intellectual property rights 56 | needed, if any. For example, if a third party patent license is required to 57 | allow Recipient to distribute the Program, it is Recipient's responsibility to 58 | acquire that license before distributing the Program. 59 | d) Each Contributor represents that to its knowledge it has sufficient 60 | copyright rights in its Contribution, if any, to grant the copyright license 61 | set forth in this Agreement. 62 | 63 | 3. REQUIREMENTS 64 | 65 | A Contributor may choose to distribute the Program in object code form under 66 | its own license agreement, provided that: 67 | a) it complies with the terms and conditions of this Agreement; and 68 | b) its license agreement: 69 | i) effectively disclaims on behalf of all Contributors all warranties and 70 | conditions, express and implied, including warranties or conditions of title 71 | and non-infringement, and implied warranties or conditions of merchantability 72 | and fitness for a particular purpose; 73 | ii) effectively excludes on behalf of all Contributors all liability for 74 | damages, including direct, indirect, special, incidental and consequential 75 | damages, such as lost profits; 76 | iii) states that any provisions which differ from this Agreement are 77 | offered by that Contributor alone and not by any other party; and 78 | iv) states that source code for the Program is available from such 79 | Contributor, and informs licensees how to obtain it in a reasonable manner on 80 | or through a medium customarily used for software exchange. 81 | When the Program is made available in source code form: 82 | a) it must be made available under this Agreement; and 83 | b) a copy of this Agreement must be included with each copy of the 84 | Program. 85 | Contributors may not remove or alter any copyright notices contained within the 86 | Program. 87 | Each Contributor must identify itself as the originator of its Contribution, if 88 | any, in a manner that reasonably allows subsequent Recipients to identify the 89 | originator of the Contribution. 90 | 91 | 4. COMMERCIAL DISTRIBUTION 92 | 93 | Commercial distributors of software may accept certain responsibilities with 94 | respect to end users, business partners and the like. While this license is 95 | intended to facilitate the commercial use of the Program, the Contributor who 96 | includes the Program in a commercial product offering should do so in a manner 97 | which does not create potential liability for other Contributors. Therefore, if 98 | a Contributor includes the Program in a commercial product offering, such 99 | Contributor ("Commercial Contributor") hereby agrees to defend and indemnify 100 | every other Contributor ("Indemnified Contributor") against any losses, damages 101 | and costs (collectively "Losses") arising from claims, lawsuits and other legal 102 | actions brought by a third party against the Indemnified Contributor to the 103 | extent caused by the acts or omissions of such Commercial Contributor in 104 | connection with its distribution of the Program in a commercial product 105 | offering. The obligations in this section do not apply to any claims or Losses 106 | relating to any actual or alleged intellectual property infringement. In order 107 | to qualify, an Indemnified Contributor must: a) promptly notify the Commercial 108 | Contributor in writing of such claim, and b) allow the Commercial Contributor 109 | to control, and cooperate with the Commercial Contributor in, the defense and 110 | any related settlement negotiations. The Indemnified Contributor may 111 | participate in any such claim at its own expense. 112 | For example, a Contributor might include the Program in a commercial product 113 | offering, Product X. That Contributor is then a Commercial Contributor. If that 114 | Commercial Contributor then makes performance claims, or offers warranties 115 | related to Product X, those performance claims and warranties are such 116 | Commercial Contributor's responsibility alone. Under this section, the 117 | Commercial Contributor would have to defend claims against the other 118 | Contributors related to those performance claims and warranties, and if a court 119 | requires any other Contributor to pay any damages as a result, the Commercial 120 | Contributor must pay those damages. 121 | 122 | 5. NO WARRANTY 123 | 124 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN 125 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR 126 | IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, 127 | NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each 128 | Recipient is solely responsible for determining the appropriateness of using 129 | and distributing the Program and assumes all risks associated with its exercise 130 | of rights under this Agreement, including but not limited to the risks and 131 | costs of program errors, compliance with applicable laws, damage to or loss of 132 | data, programs or equipment, and unavailability or interruption of operations. 133 | 134 | 6. DISCLAIMER OF LIABILITY 135 | 136 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY 137 | CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, 138 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST 139 | PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 140 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 141 | WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS 142 | GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 143 | 144 | 7. GENERAL 145 | 146 | If any provision of this Agreement is invalid or unenforceable under applicable 147 | law, it shall not affect the validity or enforceability of the remainder of the 148 | terms of this Agreement, and without further action by the parties hereto, such 149 | provision shall be reformed to the minimum extent necessary to make such 150 | provision valid and enforceable. 151 | If Recipient institutes patent litigation against a Contributor with respect to 152 | a patent applicable to software (including a cross-claim or counterclaim in a 153 | lawsuit), then any patent licenses granted by that Contributor to such 154 | Recipient under this Agreement shall terminate as of the date such litigation 155 | is filed. In addition, if Recipient institutes patent litigation against any 156 | entity (including a cross-claim or counterclaim in a lawsuit) alleging that the 157 | Program itself (excluding combinations of the Program with other software or 158 | hardware) infringes such Recipient's patent(s), then such Recipient's rights 159 | granted under Section 2(b) shall terminate as of the date such litigation is 160 | filed. 161 | All Recipient's rights under this Agreement shall terminate if it fails to 162 | comply with any of the material terms or conditions of this Agreement and does 163 | not cure such failure in a reasonable period of time after becoming aware of 164 | such noncompliance. If all Recipient's rights under this Agreement terminate, 165 | Recipient agrees to cease use and distribution of the Program as soon as 166 | reasonably practicable. However, Recipient's obligations under this Agreement 167 | and any licenses granted by Recipient relating to the Program shall continue 168 | and survive. 169 | Everyone is permitted to copy and distribute copies of this Agreement, but in 170 | order to avoid inconsistency the Agreement is copyrighted and may only be 171 | modified in the following manner. The Agreement Steward reserves the right to 172 | publish new versions (including revisions) of this Agreement from time to time. 173 | No one other than the Agreement Steward has the right to modify this Agreement. 174 | IBM is the initial Agreement Steward. IBM may assign the responsibility to 175 | serve as the Agreement Steward to a suitable separate entity. Each new version 176 | of the Agreement will be given a distinguishing version number. The Program 177 | (including Contributions) may always be distributed subject to the version of 178 | the Agreement under which it was received. In addition, after a new version of 179 | the Agreement is published, Contributor may elect to distribute the Program 180 | (including its Contributions) under the new version. Except as expressly stated 181 | in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to 182 | the intellectual property of any Contributor under this Agreement, whether 183 | expressly, by implication, estoppel or otherwise. All rights in the Program not 184 | expressly granted under this Agreement are reserved. 185 | This Agreement is governed by the laws of the State of New York and the 186 | intellectual property laws of the United States of America. No party to this 187 | Agreement will bring a legal action under this Agreement more than one year 188 | after the cause of action arose. Each party waives its rights to a jury trial 189 | in any resulting litigation. 190 | -------------------------------------------------------------------------------- /java/README.md: -------------------------------------------------------------------------------- 1 | Java, JUnit and ANT 2 | =================== 3 | 4 | Prerequisites 5 | ------------- 6 | 7 | **Java JDK and JRE**: 8 | 9 | To check if Java JDK and JRE are installed already: 10 | 11 | ``` 12 | $ javac -version 13 | javac 1.6.0_24 14 | 15 | $ java -version 16 | java version "1.6.0_24" 17 | OpenJDK Runtime Environment (IcedTea6 1.11.3) (6b24-1.11.3-1ubuntu0.11.04.1) 18 | OpenJDK Client VM (build 20.0-b12, mixed mode, sharing) 19 | ``` 20 | 21 | Output may vary depending on the Java implementation e.g. for Oracle: 22 | 23 | ``` 24 | $ javac -version 25 | javac 1.7.0_60 26 | 27 | $ java -version 28 | java version "1.7.0_60" 29 | Java(TM) SE Runtime Environment (build 1.7.0_60-b19) 30 | Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode) 31 | ``` 32 | 33 | If Java JDK and JRE are not installed, then see one of: 34 | 35 | * [Oracle Java](http://www.oracle.com/technetwork/java/javase/overview/index.html). 36 | * [OpenJDK Java](http://openjdk.java.net/). 37 | 38 | **ANT build tool**: 39 | 40 | To check if ANT is installed already: 41 | 42 | ``` 43 | $ ant -version 44 | Apache Ant version 1.7.1 compiled on November 24 2010 45 | ``` 46 | 47 | If not, then see [Apache ANT](http://ant.apache.org/bindownload.cgi). 48 | 49 | After installing, ensure ANT is in your path e.g. 50 | 51 | ``` 52 | $ export PATH=$HOME/apache-ant-1.7.1/bin:$PATH 53 | ``` 54 | 55 | **JUnit test framework**: 56 | 57 | This is provided. 58 | 59 | * File: `lib/junit-4.10.jar` 60 | * License: JUnit license, `JUNIT_LICENSE.txt`. 61 | * Web site: http://junit.org. 62 | * Used by: test code in `test/`. 63 | 64 | Usage 65 | ----- 66 | 67 | Compile and JAR: 68 | 69 | ``` 70 | $ ant jar 71 | ``` 72 | 73 | Run: 74 | 75 | ``` 76 | $ java -classpath build/lib/math.jar math.Fibonacci 30 77 | fib(30) = 832040 78 | ``` 79 | 80 | Compile and run tests and view XML xUnit-style test report: 81 | 82 | ``` 83 | $ ant test 84 | $ cat build/test/xml/TESTS-TestSuites.xml 85 | ``` 86 | 87 | Convert above XML test report into HTML: 88 | 89 | ``` 90 | $ ant test-report 91 | $ cat build/test/html/index.html 92 | ``` 93 | 94 | Clean up: 95 | 96 | ``` 97 | $ ant clean 98 | ``` 99 | -------------------------------------------------------------------------------- /java/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 20 | 21 | 22 | ANT build file to build and test math package. 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 52 | 53 | 54 | 55 | 56 | 57 | 59 | 60 | 61 | 62 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 76 | 77 | 78 | 79 | 80 | 81 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /java/lib/junit-4.10.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softwaresaved/build_and_test_examples/713ba4d46873be92df8ced3214c7e196b1ee68de/java/lib/junit-4.10.jar -------------------------------------------------------------------------------- /java/src/math/Fibonacci.java: -------------------------------------------------------------------------------- 1 | package math; 2 | 3 | // Copyright 2014 The University of Edinburgh. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | // implied. See the License for the specific language governing 15 | // permissions and limitations under the License. 16 | 17 | /** 18 | * Fibonacci numbers class. 19 | */ 20 | public class Fibonacci 21 | { 22 | /** 23 | * Calculate the Fibonacci number of the given integer. 24 | * 25 | * @param n 26 | * @return Fibonacci number. 27 | * @throws IllegalArgumentException if n is < 0. 28 | */ 29 | public static int fib(int n) 30 | { 31 | if (n < 0) 32 | { 33 | throw new IllegalArgumentException("n must be >= 0"); 34 | } 35 | else if (n < 2) 36 | { 37 | return n; 38 | } 39 | else 40 | { 41 | return fib(n - 1) + fib(n - 2); 42 | } 43 | } 44 | 45 | /** Print usage information. */ 46 | public static void print_usage() 47 | { 48 | System.out.println("Usage: java math.Fibonacci N"); 49 | System.out.println(" where N >= 0"); 50 | } 51 | 52 | public static void main(String[] args) 53 | { 54 | if (args.length < 1) 55 | { 56 | print_usage(); 57 | System.exit(1); 58 | } 59 | int n = Integer.parseInt(args[0]); 60 | if (n < 0) 61 | { 62 | print_usage(); 63 | System.exit(2); 64 | } 65 | int fibonacci = Fibonacci.fib(n); 66 | System.out.print("fib(" + n + ") = " + fibonacci + "\n"); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /java/test/math/FibonacciTest.java: -------------------------------------------------------------------------------- 1 | package math; 2 | 3 | // Copyright 2014 The University of Edinburgh. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | // implied. See the License for the specific language governing 15 | // permissions and limitations under the License. 16 | 17 | import org.junit.After; 18 | import org.junit.Before; 19 | import org.junit.Test; 20 | import static org.junit.Assert.*; 21 | 22 | import math.Fibonacci; 23 | 24 | /** 25 | * Test class for Fibonacci class. 26 | */ 27 | public class FibonacciTest 28 | { 29 | /** Initialise test suite - no-op. */ 30 | @Before 31 | public void setUp() 32 | { 33 | } 34 | 35 | /** Clean up test suite - no-op. */ 36 | @After 37 | public void tearDown() 38 | { 39 | } 40 | 41 | /** Test fib(1). */ 42 | @Test 43 | public void testFib1() 44 | { 45 | assertEquals(1, Fibonacci.fib(1)); 46 | } 47 | 48 | /** Test fib(2). */ 49 | @Test 50 | public void testFib2() 51 | { 52 | assertEquals(1, Fibonacci.fib(2)); 53 | } 54 | 55 | /** Test fib(3). */ 56 | @Test 57 | public void testFib3() 58 | { 59 | assertEquals(2, Fibonacci.fib(3)); 60 | } 61 | 62 | /** Test fib(30). */ 63 | @Test 64 | public void testFib30() 65 | { 66 | assertEquals(832040, Fibonacci.fib(30)); 67 | } 68 | 69 | /** Test fib(-1). */ 70 | @Test 71 | public void testFibMinusOne() 72 | { 73 | boolean caught = false; 74 | try 75 | { 76 | Fibonacci.fib(-1); 77 | } 78 | catch (IllegalArgumentException e) 79 | { 80 | caught = true; 81 | } 82 | assertTrue(caught); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /jenkins/Install.md: -------------------------------------------------------------------------------- 1 | Installing Jenkins 2 | ================= 3 | 4 | This page provides a brief introduction to installing Jenkins. For full information, see the [Jenkins](http://jenkins-ci.org) web site. 5 | 6 | Prerequisites 7 | ------------- 8 | 9 | **Java JDK and JRE**: 10 | 11 | To check if Java JDK and JRE are installed already: 12 | 13 | ``` 14 | $ javac -version 15 | javac 1.6.0_24 16 | 17 | $ java -version 18 | java version "1.6.0_24" 19 | OpenJDK Runtime Environment (IcedTea6 1.11.3) (6b24-1.11.3-1ubuntu0.11.04.1) 20 | OpenJDK Client VM (build 20.0-b12, mixed mode, sharing) 21 | ``` 22 | 23 | Output may vary depending on the Java implementation e.g. for Oracle: 24 | 25 | ``` 26 | $ javac -version 27 | javac 1.7.0_60 28 | 29 | $ java -version 30 | java version "1.7.0_60" 31 | Java(TM) SE Runtime Environment (build 1.7.0_60-b19) 32 | Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode) 33 | ``` 34 | 35 | If Java JDK and JRE are not installed, then see one of: 36 | 37 | * [Oracle Java](http://www.oracle.com/technetwork/java/javase/overview/index.html). 38 | * [OpenJDK Java](http://openjdk.java.net/). 39 | 40 | Download Jenkins 41 | ---------------- 42 | 43 | The current version of Jenkins can be downloaded from [Jenkins](http://jenkins-ci.org) or, via the command-line: 44 | 45 | From the command-line you can get it by running: 46 | 47 | ``` 48 | $ wget http://mirrors.jenkins-ci.org/war/latest/jenkins.war 49 | ``` 50 | 51 | To see which version of Jenkins you have, run: 52 | 53 | ``` 54 | $ java -jar jenkins.war --version 55 | Running from: $HOME/jenkins.war 56 | webroot: $user.home/.jenkins 57 | 1.631 58 | ``` 59 | 60 | Deploy Jenkins 61 | -------------- 62 | 63 | Jenkins is provided as a web archive, WAR file, `jenkins.war`. It can be deployed into a servlet container e.g. [Apache Tomcat](http://tomcat.apache.org/). However, it also comes with its own web server and can be used stand-alone. So, to start up Jenkins run: 64 | 65 | ``` 66 | $ java -jar jenkins.war 67 | ``` 68 | 69 | This uses a default configuration file directory of `.jenkins`. If you are unhappy with this, or want to use a different directory, then move `.jenkins` to the location you prefer and set a `JENKINS_HOME` environment variable to point to this location e.g. 70 | 71 | ``` 72 | $ mv .jenkins $HOME/jenkins-config 73 | $ export JENKINS_HOME=$HOME/jenkins-config 74 | ``` 75 | 76 | Jenkins uses the default port of 8080. To use a different port, run: 77 | 78 | ``` 79 | $ java -jar jenkins.war --httpPort=9090 80 | ``` 81 | 82 | For all of Jenkins start-up options, run: 83 | 84 | ``` 85 | $ java -jar jenkins.war --help 86 | ``` 87 | 88 | When you start Jenkins for the first time, it will show the following: 89 | 90 | ``` 91 | Jenkins initial setup is required. An admin user has been created and a password generated. 92 | Please use the following password to proceed to installation: 93 | ``` 94 | 95 | It will then print a password, which you should take note of. 96 | 97 | View Jenkins 98 | ------------ 99 | 100 | Once Jenkins has started, browse to the URL and port which you started Jenkins with. For example, if you started Jenkins stand-alone with the default port then browse to http://localhost:8080. 101 | 102 | If you specified another port e.g. `9090`, then browse to http://localhost:9090. 103 | 104 | You should see the Jenkins front page which will prompt you to "Unblock Jenkins". 105 | 106 | You will be prompted for your password, so enter it into the Administrator password box. 107 | 108 | Click Continue. 109 | 110 | Click Install suggested plugins. 111 | 112 | You may now have to wait a while for the plugins to install. 113 | 114 | Once installed, follow the on-screen instructions. 115 | 116 | 117 | -------------------------------------------------------------------------------- /jenkins/Languages.md: -------------------------------------------------------------------------------- 1 | Create a Jenkins job for popular programming languages 2 | ====================================================== 3 | 4 | Jenkins can build and run code written in many languages, including C, C++, Fortran, Java, PHP and Python code, either directly or via automated build tools like Make or ANT. It can also run unit tests, for example written for CUnit, CppUnit, googletest, FRUIT, JUnit, PHPUnit or pytest, and report on the success or failure of tests. 5 | 6 | Create a Jenkins job 7 | -------------------- 8 | 9 | * On the Jenkins front page, click New Item. 10 | * Enter a name in the Item name field e.g. one of `C job`, `Cpp job`, `Fortran job`, `Java job`, `PHP job`, `Python job`. Note that Jenkins uses the terms "project" and "job" interchangeably. 11 | * Select Freestyle project. 12 | * Click OK. 13 | 14 | Build and test code 15 | ------------------- 16 | 17 | * On the configuration page, under the General tab, click Advanced... 18 | * Select Use custom workspace. 19 | * Enter the directory with your code e.g. one of: 20 | 21 | ``` 22 | $HOME/build_and_test_examples/c 23 | $HOME/build_and_test_examples/cpp 24 | $HOME/build_and_test_examples/fortran 25 | $HOME/build_and_test_examples/java 26 | $HOME/build_and_test_examples/php 27 | $HOME/build_and_test_examples/python 28 | ``` 29 | 30 | * Scroll down the page to under the Build heading. 31 | 32 | For C, C++, Fortran, PHP and Python: 33 | 34 | * Click Add build step and select Execute shell. 35 | * Enter the commands that compile the code and tests and run the tests. 36 | * C: 37 | 38 | ``` 39 | export C_INCLUDE_PATH=$HOME/include:$C_INCLUDE_PATH 40 | export LIBRARY_PATH=$HOME/lib:$LIBRARY_PATH 41 | export LD_LIBRARY_PATH=$HOME/lib:$LD_LIBRARY_PATH 42 | make test 43 | make xunit-report 44 | ``` 45 | 46 | * C++: 47 | 48 | ``` 49 | export CPLUS_INCLUDE_PATH=$HOME/include:$CPLUS_INCLUDE_PATH 50 | export LIBRARY_PATH=$HOME/lib:$LIBRARY_PATH 51 | export LD_LIBRARY_PATH=$HOME/lib:$LD_LIBRARY_PATH 52 | make googletest 53 | ``` 54 | 55 | * Fortran: 56 | 57 | ``` 58 | make test 59 | ``` 60 | 61 | * PHP: 62 | 63 | ``` 64 | phpunit --log-junit TestResults.xml --bootstrap src/autoload.php test/FibonacciTest.php 65 | ``` 66 | 67 | * Python 68 | 69 | ``` 70 | py.test --junit-xml=report.xml 71 | ``` 72 | 73 | For Java, Jenkins has in-built support for ANT: 74 | 75 | * Click Add build step and select Invoke ANT. 76 | * Enter the ANT target that compiles the code and tests and runs the JUnit tests e.g.: 77 | 78 | ``` 79 | test 80 | ``` 81 | 82 | For all languages: 83 | 84 | * Click Save. 85 | 86 | * On the new page that appears, click Build Now. 87 | * You should see a new job scheduled in the Build History table. 88 | * When it completes, the little ball in the Build History table should be blue which means the job succeeded without errors. 89 | * Click the job link e.g. `28-Sep-2015 14:15:42`. 90 | * The build results page for that job will appear. 91 | * Click Console Output and you should see the output from the command-line. 92 | * Click Back to Project. 93 | * Click Workspace and you can browse the directory in which the build commands are run. 94 | * Click Back to Dashboard to see the Jenkins front page which summarises all the projects set up and the success (or failure) of the last job for each of these. Clicking on the green arrow "run" icon will re-run the associated job. 95 | 96 | Publish test results 97 | -------------------- 98 | 99 | Jenkins can parse XML test results, in JUnit-compliant XML results file, and present test in a more useful, interactive way, that allows the test packages, classes, modules, classes, methods and functions to be browsed. Many test frameworks either output JUnit-compliant XML directly (e.g. googletest, FRUIT, JUnit, PHPUnit and pytest) or in an XML format that can be converted into a JUnit-compliant XML results file (e.g. CUnit - our `make xunit-report` target does this conversion). CppUnit outputs an XML file, `TestResults.xml`, but this is not in xUnit-compliant XML format and a conversion does not, yet, exist. 100 | 101 | To instruct Jenkins to parse these result files 102 | 103 | * Click your job. 104 | * Click Configure. 105 | * Under the Post-build Actions heading, click Add post-build action. 106 | * Select Publish JUnit test result report. 107 | * In the Test report XMLs field. enter the location of the test report XML file e.g. 108 | - C: `TestResults.xml` 109 | - C++ and googletest: `TestResults.xml` 110 | - Fortran: `result.xml` 111 | - Java: `build/test/xml/TESTS-TestSuites.xml` 112 | - PHP: `TestResults.xml` 113 | - Python: `report.xml` 114 | * If you get a warning that your file `doesn't match anything` you can ignore this as the file hasn't been created yet. 115 | * Click Save. 116 | * Click Build Now. 117 | * When the job completes, click the job's link in the Build History table. 118 | * Now on the build results page for that job, there is a Test Result link which should also say (no failures). 119 | * Click the Test Result link and you can browse the test results. These are hierarchically organised by: 120 | - C: C source file and function name. 121 | - C++: source file and function name. 122 | - Fortran: source file and function name. 123 | - Java: package, class and method name. 124 | - PHP: file, class and function name. 125 | - Python: package, class and function name. 126 | 127 | How Jenkins behaves when there are errors 128 | ----------------------------------------- 129 | 130 | * Edit your code or tests so a test fails e.g. edit edit the Fibonacci function to always return `1` by updating: 131 | - C: `src/fibonacci.c` 132 | - C++: `src/fibonacci.h` 133 | - Fortran: `src/fibonacci.f90` 134 | - Java: `src/math/Fibonacci.java` 135 | - PHP: `src/Fibonacci.php` 136 | - Python: `src/fibonacci.py` 137 | * Click Back to Project. 138 | * Click Build Now. 139 | 140 | * This time the ball in the Build History table should be one of yellow or red. 141 | - C, Fortran and Java will show as yellow. Yellow means the build is unstable. Jenkins [defines](https://wiki.jenkins-ci.org/display/JENKINS/Terminology) a build as unstable if it was built successfully but a test result publisher has noted that a test has failed. This is because CUnit, FRUIT, and JUnit (invoked via ANT's `junit` task) returns an exit code of `0`, indicating success, Jenkins executes the post-build action to parse the test results file and so detects the test failures. 142 | - C++, PHP and Python will show as red. This means the build failed. This is because googletest, PHPUnit and pytest return an exit code of `1` if any test fails. 143 | * Click the job link. 144 | * Click the Test Result link and you can browse to see the individual test functions that failed. Remember, too that the console output is always available via the Console Output link. 145 | * Click Back to project then Back to dashboard. 146 | -------------------------------------------------------------------------------- /jenkins/Periodic.md: -------------------------------------------------------------------------------- 1 | Configure a job to run periodically 2 | =================================== 3 | 4 | Jenkins can be configured to run jobs periodically. For example: 5 | 6 | * Select a project. 7 | * Click Configure. 8 | * Under the Build Triggers heading, click Build periodically. 9 | * A Schedule form will appear. The general format for entries in this form is: 10 | 11 | ``` 12 | MINUTE HOUR DAY_OF_MONTH MONTH DAY_OF_WEEL 13 | ``` 14 | 15 | * So, enter the following to run the job every 2 minutes (Click on the "?" icon to see a complete description of the options available): 16 | 17 | ``` 18 | */2 * * * * 19 | ``` 20 | 21 | * Click Apply. 22 | * Click ENABLE AUTO REFRESH on the top-right of the Jenkins page, if it has not already been clicked. If it has you'll see DISABLE AUTO REFRESH, so just leave it be. 23 | * Now sit back and you should see new jobs appear in the Build History every 2 minutes. 24 | 25 | As another example, we could set up a simple job to regularly ping a URL to see if it is still available. The [ADMIRE](http://www.admire-project.eu/) project did this to ensure their service end-points were live. Jenkins provided them with a means to check and display service availability in a simple, visually useful way. 26 | -------------------------------------------------------------------------------- /jenkins/README.md: -------------------------------------------------------------------------------- 1 | Getting started with Jenkins 2 | ============================ 3 | 4 | [Jenkins](http://jenkins-ci.org) is a popular, open source [continuous integration](http://en.wikipedia.org/wiki/Continuous_Integration) server. In these pages we provide an introduction to Jenkins and how it can be used to automate the building and testing of software. We also show how Jenkins build-and-test jobs can be triggered by changes to code held in popular source code repositories including Git, Mercurial, Subversion and CVS. 5 | 6 | This is not intended to be a complete introduction to everything that Jenkins offers. Rather, it is hoped that it will serve to get you started, helping you through your first 20 minutes of using Jenkins, to give an idea as to its potential and usefulness. 7 | 8 | The walkthrough can be performed using Linux or UNIX. 9 | 10 | Install and deploy Jenkins 11 | -------------------------- 12 | 13 | * [Installing Jenkins](./Install.md) 14 | 15 | Use Jenkins to run build-and-test jobs for various languages 16 | ------------------------------------------------------------ 17 | 18 | Jenkins can build and run code written in many languages, including C, C++, Fortran, Java, PHP and Python code, either directly or via automated build tools like Make or ANT. It can also run unit tests, for example written for CUnit, CppUnit, googletest, FRUIT, JUnit, PHPUnit or pytest, and report on the success or failure of tests. 19 | 20 | * [Create a Jenkins job for popular programming languages](./Languages.md) including C, C++, Fortran, Java, PHP and Python. 21 | 22 | Use Jenkins to run jobs periodically 23 | ------------------------------------ 24 | 25 | Jenkins can be configured to run jobs periodically. 26 | 27 | * [Configure a job to run periodically](./Periodic.md) 28 | 29 | Use Jenkins to run build-and-test jobs when source code changes 30 | --------------------------------------------------------------- 31 | 32 | Jenkins can be configured to detect and respond to changes made to code or files held under popular source code repositories, including Git, Mercurial, Subversion and CVS. If the code is changed, then the server can automatically spawn a new build-and-test job. This means that the software is rebuilt and tested every time the code is changed. Since the server can be remote from your own machine, it means you can continue working while the tests are under way. 33 | 34 | * [Configure a job to run when updates are committed a source code repository](./VersionControl.md) 35 | 36 | Use Jenkins to run experiments 37 | ------------------------------ 38 | 39 | Jenkins can not only trigger builds for very complex software but also trigger and provide a summary of the success or failure of experiment runs. Jenkins can run any shell script and report on the success or failure depending on whether the script exits with 0, for success, or non-zero, for failure. Jenkins imposes no restriction as to what this shell script does. 40 | 41 | Jenkins can provide a summary of the console output on the build results page. It also, on a project page, allows us, via the Workspace link, to browse the project's workspace. Typically this is the directory where the scripts are invoked. If output files are placed here by the scripts, then they can be viewed via Jenkins too. 42 | 43 | For a simple example of using Jenkins to run a shell script, see: 44 | 45 | * [Create a Jenkins shell script job](./Shell.md) 46 | 47 | Importing Jenkins jobs 48 | ---------------------- 49 | 50 | The [examples/](./examples) directories contains examples of Jenkins job configuration files for each of the jobs written following the above instructions. These are plain-text XML files which can be imported into Jenkins. They assume `build_and_test_examples` is located in your `$HOME` directory. 51 | 52 | The source code repository-related examples assume you have set up source code repositories, as described in the above pages. 53 | 54 | To import any of these jobs into Jenkins: 55 | 56 | ``` 57 | $ cp -r jenkins/JOB_NAME $HOME/.jenkins/jobs/ 58 | ``` 59 | 60 | For the following jobs, replace `/home/user` with the full path to your source code repository: 61 | 62 | ``` 63 | CVS job/config.xml 64 | Git job/config.xml 65 | Mercurial job/config.xml 66 | SVN job/config.xml 67 | ``` 68 | 69 | On the Jenkins dashboard: 70 | 71 | * Click Manage Jenkins. 72 | * Click Reload configuration from disk. 73 | * You should see JOB_NAME. 74 | * Click green "run" icon. 75 | 76 | Further information 77 | ------------------- 78 | 79 | This has just touched upon the myriad configuration options, build steps, test steps, notification mechanisms and publishing options that Jenkins supports. 80 | 81 | For more information check out: 82 | 83 | * Jenkins' [Meet Jenkins](https://wiki.jenkins-ci.org/display/JENKINS/Meet+Jenkins) 84 | * Jenkins' [Use Jenkins](https://wiki.jenkins-ci.org/display/JENKINS/Use+Jenkins) 85 | -------------------------------------------------------------------------------- /jenkins/Shell.md: -------------------------------------------------------------------------------- 1 | Create a Jenkins shell script job 2 | ================================= 3 | 4 | Jenkins can run any shell script and report on the success or failure depending on whether the script exits with 0, for success, or non-zero, for failure. 5 | 6 | * On the Jenkins front page, click New Item. 7 | * Enter a name in the Item name field e.g. `Shell job`. Note that Jenkins uses the terms "project" and "job" interchangeably. 8 | * Select Freestyle project. 9 | * Click OK. 10 | * On the configuration page, under the Advanced Project Options heading, click Advanced... 11 | * Select Use custom workspace. 12 | * Enter the directory with your shell script e.g. `$HOME/build_and_test_examples/sh`. 13 | * Scroll down the page to under the Build heading. 14 | * Click Add build step and select Execute shell. 15 | * Enter: 16 | 17 | ``` 18 | ./fibonacci.sh 20 19 | ``` 20 | 21 | * Click Save. 22 | * On the new page that appears, click Build Now. 23 | * You should see a new job scheduled in the Build History table. 24 | * When it completes, the little ball should be blue which means the job succeeded without errors. 25 | * Click the job link e.g. `28-Sep-2015 14:15:42`. 26 | * The build results page for that job will appear. 27 | * Click Console Output and you should see the output from the command-line. 28 | * Click Workspace and you can browse the directory in which the build commands are run. 29 | * Click Back to Project. 30 | * Click Back to Dashboard to see the Jenkins fromt page which summarises all the projects set up and the success (or failure) of the last job for each of these. Clicking on the green arrow "run" icon will re-run the associated job. 31 | 32 | How Jenkins behaves when there are errors 33 | ----------------------------------------- 34 | 35 | * Click Shell job. 36 | * Click Configure. 37 | * Edit the configuration and remove `20` from the build step so it is just: 38 | 39 | ``` 40 | ./fibonacci.sh 41 | ``` 42 | 43 | * Save the configuration and click Build Now. 44 | * Now when the job completes, there will be a little red ball next to the job link, which means the job failed with an error. 45 | * Click the job link. 46 | * Click Console Output and you should see the output from the command-line, including the reason for the failure. 47 | * Click Back to project then Back to dashboard. 48 | 49 | Summary 50 | ------- 51 | 52 | Though this is a very simple example, it demonstrates an important concept - Jenkins can run any script or set of scripts in this way. All Jenkins does is check the return values from the scripts: 53 | 54 | * If the return value is 0 the script has succeeded, if it is non-zero the script has failed. 55 | * If all the scripts succeed then the job succeeds. If any script fails then the job fails. 56 | -------------------------------------------------------------------------------- /jenkins/VersionControl.md: -------------------------------------------------------------------------------- 1 | Configure a job to run when updates are committed to a source code repository 2 | ============================================================================= 3 | 4 | Jenkins can be configured to detect and respond to changes made to code or files held under popular source code repositories, including Git, Mercurial, Subversion and CVS. If the code is changed, then the server can automatically spawn a new build-and-test job. This means that the software is rebuilt and tested every time the code is changed. Since the server can be remote from your own machine, it means you can continue working while the tests are under way. 5 | 6 | Create a repository 7 | ------------------- 8 | 9 | Create a repository based on the Python examples in `$HOME/build_and_test_examples/python`: 10 | 11 | **Create a Git repository** 12 | 13 | Run: 14 | 15 | ``` 16 | $ cp -r build_and_test_examples/python python-git 17 | $ cd python-git 18 | $ rm -rf report.xml maths/*.pyc maths/tests/*.pyc maths/tests/__pycache__ .gitignore 19 | $ git init 20 | $ git config --global user.name "Your name" 21 | $ git config --global user.email your@email.address 22 | $ git add . 23 | $ git commit -m "Initial import" . 24 | ``` 25 | 26 | Remove the current working files and set this repository to be a "bare" repository i.e. one with no current working copy: 27 | 28 | ``` 29 | $ rm -rf README.md maths 30 | $ git config --bool core.bare true 31 | ``` 32 | 33 | **Create a Mercurial repository** 34 | 35 | Create a Mercurial configuration file, `~/.hgrc` with content: 36 | 37 | ``` 38 | [ui] 39 | username = Your name 40 | ``` 41 | 42 | Run: 43 | 44 | ``` 45 | $ cp -r build_and_test_examples/python python-mercurial 46 | $ cd python-mercurial 47 | $ rm -rf report.xml maths/*.pyc maths/tests/*.pyc maths/tests/__pycache__ .gitignore 48 | $ hg init 49 | $ hg add . 50 | $ hg commit -m "Initial import" . 51 | ``` 52 | 53 | **Create a Subversion repository** 54 | 55 | Run: 56 | 57 | ``` 58 | $ svnadmin create $HOME/SVNROOT 59 | $ cp -r build_and_test_examples/python python 60 | $ cd python/ 61 | $ rm -rf report.xml maths/*.pyc maths/tests/*.pyc maths/tests/__pycache__ .gitignore 62 | $ svn import file://$HOME/SVNROOT/python -m "Initial import" 63 | ``` 64 | 65 | **Create a CVS repository** 66 | 67 | Run: 68 | 69 | ``` 70 | $ cvs -d $HOME/CVSROOT init 71 | $ cp -r build_and_test_examples/python python 72 | $ cd python/ 73 | $ rm -rf report.xml maths/*.pyc maths/tests/*.pyc maths/tests/__pycache__ .gitignore 74 | $ cvs -d $HOME/CVSROOT import -m "Initial import" python vendor-tag release-tag 75 | ``` 76 | 77 | Install plug-ins 78 | ---------------- 79 | 80 | Jenkins supports CVS and Subversion by default. To use Git and Mercurial requires additional plug-ins. 81 | 82 | **Install the Git plug-in** 83 | 84 | * On the Jenkins front page, click Manage Jenkins. 85 | * Click Manage Plugins. 86 | * Click the Available tab. 87 | * In the Filter field, enter `git plugin`. 88 | * Select the Install box next to Git Plugin (and not GitHub Plugin) in the table. 89 | * Click Install without restart. 90 | 91 | **Install the Mercurial plug-in** 92 | 93 | * On the Jenkins front page, click Manage Jenkins. 94 | * Click Manage Plugins. 95 | * Click the Available tab. 96 | * In the Filter field, enter `mercurial plugin`. 97 | * Select the Install box next to Mercurial Plugin in the table 98 | * Click Install without restart. 99 | 100 | Create a Jenkins job 101 | -------------------- 102 | 103 | * On the Jenkins front page, click New Item. 104 | * Enter a name in the Item name field e.g. `Git job`, `Mercurial job`, `Subversion job`, `CVS job`. 105 | * Select Freestyle software project. 106 | * Click OK. 107 | 108 | Check out the repository and runs tests 109 | --------------------------------------- 110 | 111 | * On the configuration page, under Source Code Management, select your repository type e.g. Git, Mercurial, Subversion or CVS. 112 | * For Git enter: 113 | - Repository URL: `file://$HOME/python-git`, replacing `$HOME` with the full path to your home directory e.g. `/home/user`. 114 | * For Mercurial enter: 115 | - Repository URL: `file://$HOME/python-mercurial`, replacing `$HOME` with the full path to your home directory e.g. `/home/user`. 116 | * For Subversion enter: 117 | - Repository URL: `file://$HOME/SVNROOT/python`, replacing `$HOME` with the full path to your home directory e.g. `/home/user`. 118 | - Local module directory (optional): `.` 119 | * For CVS enter: 120 | - CVSROOT: `$HOME/CVSROOT`, replacing `$HOME` with the full path to your home directory e.g. `/home/user`. 121 | - Location: Head 122 | - Modules Remote Name: `python` 123 | * Scroll down the page to under the Build heading. 124 | * Click Add build step and select Execute shell. 125 | * Enter the commands that run the tests using `py.test`: 126 | 127 | ``` 128 | py.test --junit-xml=report.xml 129 | ``` 130 | 131 | * Under the Post-build Actions heading, click Add post-build action. 132 | * Select Publish JUnit test result report. 133 | * In the Test report XMLs field enter the location of the test report XML file, `report.xml`. 134 | * Click Save. 135 | * Click Build Now. 136 | * When the job completes, click on the job's link in the Build History table. 137 | * Click on Console Output and you should see the commands that check the repository out. 138 | 139 | Though we are using a local repository, Jenkins can be used with remote repositories whether these be hosted on your own servers or on a third-party service. 140 | 141 | Jenkins provides a lot of control over what is checked out from the repository e.g. modules, directories, branches or tags, and usernames/passwords or other credentials used to authenticate with the repository etc. 142 | 143 | Poll the repository 144 | ------------------- 145 | 146 | We can configure Jenkins to poll the repository for changes. This can be enabled by selecting the Poll SCM option under the Build Triggers heading on the project's configuration page. This takes a "schedule" that is the same as Build periodically (see [Configure a job to run periodically](./Periodic.md)). Jobs are only triggered if updates or changes to the repository have been made since the last job run. 147 | 148 | One problem with polling is that it is very expensive. It would be better for CVS to tell Jenkins when changes have been made and so trigger Jenkins to rerun the job. Jenkins allows us to do this. 149 | 150 | Configure a repository to notify Jenkins of changes 151 | --------------------------------------------------- 152 | 153 | We can configure a repository with a script that, when changes are made to the repository, pings a Jenkins URL that, in turn, triggers a Jenkins job. First, we need to tell Jenkins to be aware of changes from the repository: 154 | 155 | * Go to the configuration page for the project. 156 | * Scroll down to Build Triggers. 157 | * Select Poll SCM. 158 | * Check that the Schedule form is empty. 159 | * Click Save. 160 | 161 | **Configure Git** 162 | 163 | Git has a `hooks` directory which holds a `post-commit` and `post-receive` files, which contains commands that are invoked when changes to to the repository are committed or are pushed. 164 | 165 | Create a `post-commit` file in your Git repository's `hooks` directory, `$HOME/python-git/.git/hooks`, or edit it if it already exists. Add: 166 | 167 | ``` 168 | #!/bin/bash 169 | wget http://localhost:8080/git/notifyCommit?url=file://$HOME/python-git > /tmp.git.log 2>&1 170 | exit 0 171 | ``` 172 | 173 | * If you are using a different host or port name then replace `localhost` or `8080` with these. 174 | * See, for example, [post-commit](./examples/git-post-commit). 175 | * Set the script to be executable: 176 | 177 | ``` 178 | $ chmod +x $HOME/python-git/.git/hooks/post-commit 179 | ``` 180 | 181 | Now, repeat the above to create a `post-receive` file, with the same contents. 182 | 183 | * See, for example, [post-receive](./examples/git-post-receive) 184 | 185 | **Configure Mercurial** 186 | 187 | Mercurial has an `hgrc` file which a `hooks` section which contains commands that are invoked when changes to to the repository are committed or are pushed. 188 | 189 | Create an `hgrc` file in your Mercurial repository's `.hg` directory, `$HOME/python-mercurial/.hg`, or edit it if it already exists. Add: 190 | 191 | ``` 192 | [hooks] 193 | commit.jenkins = wget -q http://localhost:8080/mercurial/notifyCommit?url=file:/ 194 | /$HOME/python-mercurial > /tmp/hg.log 2>&1 195 | incoming.jenkins = wget -q http://localhost:8080/mercurial/notifyCommit?url=file 196 | ://$HOME/python-mercurial > /tmp/hg.log 2>&1 197 | ``` 198 | 199 | * If you are using a different host or port name then replace `localhost` or `8080` with these. 200 | * See, for example, [hgrc](./examples/hgrc). 201 | 202 | **Configure Subversion** 203 | 204 | Subversion has a `hooks` directory which holds a `post-commit` file, which contains commands that are invoked when changes to to the repository are committed. 205 | 206 | Create a `post-commit` file, in your Subversion repository's `hooks/` directory, `$HOME/SVNROOT/hooks`, or edit it if it already exists. Add: 207 | 208 | ``` 209 | #!/bin/bash 210 | REPOS="$1" 211 | REV="$2" 212 | UUID=`svnlook uuid $REPOS` 213 | wget \ 214 | --header "Content-Type:text/plain;charset=UTF-8" \ 215 | --post-data "`svnlook changed --revision $REV $REPOS`" \ 216 | --output-document "-" \ 217 | --timeout=2 \ 218 | http://localhost:9090/subversion/${UUID}/notifyCommit?rev=$REV > /tmp/svn.log 2>&1 219 | exit 0 220 | ``` 221 | 222 | * If you are using a different host or port name then replace `localhost` or `8080` with these. 223 | * See, for example, [post-commit](./examples/svn-post-commit). 224 | * Set the script to be executable: 225 | 226 | ``` 227 | $ chmod +x $HOME/SVNROOT/hooks/post-commit 228 | ``` 229 | 230 | **Configure CVS** 231 | 232 | Create a script `$HOME/CVSROOT/CVSROOT/cvs-notify-jenkins.sh` to trigger the Jenkins job: 233 | 234 | ``` 235 | #!/bin/bash 236 | wget "http://localhost:8080/job/CVS%20job/build?token=CVS-BUILD" 237 | ``` 238 | 239 | * If you are using a different host or port name then replace `localhost` or `8080` with these. 240 | * Set this script to be executable: 241 | 242 | ``` 243 | $ chmod +x $HOME/CVSROOT/CVSROOT/cvs-notify-jenkins.sh 244 | ``` 245 | * See, for example, [cvs-notify-jenkins.sh](./examples/cvs-notify-jenkins.sh). 246 | 247 | CVS has a `loginfo` file which contains commands that are invoked when changes to to the repository are committed. 248 | 249 | Edit the `loginfo` file, in your Subversion repository's `CVSROOT` directory, `$HOME/SVNROOT/hooks`: 250 | 251 | * Check out the CVS configuration files: 252 | 253 | ``` 254 | $ mkdir cvs-checkout 255 | $ cd cvs-checkout/ 256 | $ cvs -d $HOME/CVSROOT co CVSROOT 257 | $ cd CVSROOT 258 | ``` 259 | * Edit `loginfo` and add this line which will call the script to trigger a Jenkins job, whenever a change is commited to CVS: 260 | 261 | ``` 262 | ALL $CVSROOT/CVSROOT/cvs-notify-jenkins.sh 263 | ``` 264 | 265 | * Commit changes: 266 | 267 | ``` 268 | $ cvs commit -m "Added Jenkins notification on commit" 269 | ``` 270 | 271 | Check that a repository notifies Jenkins of changes 272 | --------------------------------------------------- 273 | 274 | Check out the Python code: 275 | 276 | * Using Git: 277 | 278 | ``` 279 | $ git clone file://$HOME/python-git my-python-git-clone 280 | $ cd my-python-git-clone 281 | ``` 282 | 283 | * Using Mercurial: 284 | 285 | ``` 286 | $ hg clone file://$HOME/python-mercurial my-python-mercurial-clone 287 | $ cd my-python-mercurial-clone 288 | ``` 289 | 290 | * Using Subversion: 291 | 292 | ``` 293 | $ mkdir $HOME/svn-checkout 294 | $ cd $HOME/svn-checkout 295 | $ svn co file://$HOME/$SVNROOT/python 296 | $ cd python 297 | ``` 298 | 299 | * Using CVS: 300 | 301 | ``` 302 | $ mkdir $HOME/cvs-checkout 303 | $ cd $HOME/cvs-checkout 304 | $ cvs -d $HOME/CVSROOT co python 305 | $ cd python 306 | ``` 307 | 308 | Edit `test/test_fibonacci.py` and add a new test: 309 | 310 | ``` 311 | def test_fibonacci10(self): 312 | """ Test fibonacci(10). """ 313 | self.assertEqual(55, fibonacci(10)) 314 | ``` 315 | 316 | Commit the change: 317 | 318 | * Using Git: 319 | 320 | ``` 321 | $ git commit -m "Added test_fibonacci10" test/test_fibonacci.py 322 | $ git push origin master 323 | ``` 324 | 325 | * Using Mercurial: 326 | 327 | ``` 328 | $ hg commit -m "Added test_fibonacci10" test/test_fibonacci.py 329 | $ hg push 330 | ``` 331 | 332 | * Using Subversion: 333 | 334 | ``` 335 | $ svn commit -m "Added test_fibonacci10" test/test_fibonacci.py 336 | ``` 337 | 338 | * Using CVS: 339 | 340 | ``` 341 | $ cvs commit -m "Added test_fibonacci10" test/test_fibonacci.py 342 | ``` 343 | 344 | In Jenkins, you should see a job being spawned and the new test being run. When the job completes: 345 | 346 | * Click on the job's link in the Build History table. There should be a section called Changes, with information from the repository on the latest changes. 347 | * Click on Test Result and you should see that the new test was run. 348 | -------------------------------------------------------------------------------- /jenkins/examples/C job/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | false 6 | 7 | 8 | true 9 | false 10 | false 11 | false 12 | 13 | false 14 | $HOME/build_and_test_examples/c 15 | 16 | 17 | export C_INCLUDE_PATH=$HOME/include:$C_INCLUDE_PATH 18 | export LIBRARY_PATH=$HOME/lib:$LIBRARY_PATH 19 | export LD_LIBRARY_PATH=$HOME/lib:$LD_LIBRARY_PATH 20 | make test 21 | make xunit-report 22 | 23 | 24 | 25 | 26 | TestResults.xml 27 | false 28 | 29 | 1.0 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /jenkins/examples/CVS job/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | false 6 | 7 | 8 | true 9 | 10 | 11 | /home/user/CVSROOT 12 | 13 | 14 | 15 | 16 | 17 | python 18 | 19 | 20 | 21 | HEAD 22 | false 23 | 24 | 25 | 26 | -1 27 | 28 | 29 | 30 | 31 | 32 | false 33 | 34 | 35 | true 36 | false 37 | true 38 | false 39 | false 40 | false 41 | 42 | true 43 | false 44 | false 45 | false 46 | 47 | 48 | 49 | false 50 | 51 | 52 | false 53 | 54 | 55 | py.test --junit-xml=report.xml 56 | 57 | 58 | 59 | 60 | report.xml 61 | false 62 | 63 | 1.0 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /jenkins/examples/Cpp job/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | false 6 | 7 | 8 | true 9 | false 10 | false 11 | false 12 | 13 | false 14 | $HOME/build_and_test_examples/cpp 15 | 16 | 17 | export CPLUS_INCLUDE_PATH=$HOME/include:$CPLUS_INCLUDE_PATH 18 | export LIBRARY_PATH=$HOME/lib:$LIBRARY_PATH 19 | export LD_LIBRARY_PATH=$HOME/lib:$LD_LIBRARY_PATH 20 | make googletest 21 | 22 | 23 | 24 | 25 | TestResults.xml 26 | false 27 | 28 | 1.0 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /jenkins/examples/Fortran job/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | false 6 | 7 | 8 | true 9 | false 10 | false 11 | false 12 | 13 | false 14 | $HOME/build_and_test_examples/fortran 15 | 16 | 17 | make test 18 | 19 | 20 | 21 | 22 | result.xml 23 | false 24 | 25 | 1.0 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /jenkins/examples/Git job/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | false 6 | 7 | 8 | 2 9 | 10 | 11 | file:///home/user/python-git 12 | 13 | 14 | 15 | 16 | */master 17 | 18 | 19 | false 20 | 21 | 22 | 23 | true 24 | false 25 | false 26 | false 27 | 28 | 29 | 30 | false 31 | 32 | 33 | false 34 | 35 | 36 | py.test --junit-xml=report.xml 37 | 38 | 39 | 40 | 41 | report.xml 42 | false 43 | 44 | 1.0 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /jenkins/examples/Java job/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | false 6 | 7 | 8 | true 9 | false 10 | false 11 | false 12 | 13 | false 14 | $HOME/build_and_test_examples/java 15 | 16 | 17 | test 18 | 19 | 20 | 21 | 22 | build/test/xml/TESTS-TestSuites.xml 23 | false 24 | 25 | 1.0 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /jenkins/examples/Mercurial job/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | false 6 | 7 | 8 | file:///home/user/python-mercurial 9 | 10 | BRANCH 11 | default 12 | false 13 | 14 | false 15 | 16 | true 17 | false 18 | false 19 | false 20 | 21 | 22 | 23 | false 24 | 25 | 26 | false 27 | 28 | 29 | py.test --junit-xml=report.xml 30 | 31 | 32 | 33 | 34 | report.xml 35 | false 36 | 37 | 1.0 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /jenkins/examples/PHP job/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | false 6 | 7 | 8 | true 9 | false 10 | false 11 | false 12 | 13 | false 14 | $HOME/build_and_test_examples/php 15 | 16 | 17 | phpunit --log-junit TestResults.xml --bootstrap src/autoload.php test/FibonacciTest.php 18 | 19 | 20 | 21 | 22 | 23 | TestResults.xml 24 | false 25 | 26 | 1.0 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /jenkins/examples/Periodic job/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | false 6 | 7 | 8 | true 9 | false 10 | false 11 | false 12 | 13 | 14 | */2 * * * * 15 | 16 | 17 | false 18 | $HOME/build_and_test_examples/python 19 | 20 | 21 | py.test --junit-xml=report.xml 22 | 23 | 24 | 25 | 26 | report.xml 27 | false 28 | 29 | 1.0 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /jenkins/examples/Python job/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | false 6 | 7 | 8 | true 9 | false 10 | false 11 | false 12 | 13 | false 14 | $HOME/build_and_test_examples/python 15 | 16 | 17 | py.test --junit-xml=report.xml 18 | 19 | 20 | 21 | 22 | report.xml 23 | false 24 | 25 | 1.0 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /jenkins/examples/SVN job/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | false 6 | 7 | 8 | 9 | 10 | file:///home/user/SVNROOT/python 11 | . 12 | infinity 13 | false 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | false 23 | false 24 | 25 | true 26 | false 27 | false 28 | false 29 | 30 | 31 | 32 | false 33 | 34 | 35 | false 36 | 37 | 38 | py.test --junit-xml=report.xml 39 | 40 | 41 | 42 | 43 | report.xml 44 | false 45 | 46 | 1.0 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /jenkins/examples/Shell job/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | false 6 | 7 | 8 | true 9 | false 10 | false 11 | false 12 | 13 | false 14 | $HOME/build_and_test_examples/sh 15 | 16 | 17 | ./fibonacci.sh 30 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /jenkins/examples/cvs-notify-jenkins.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | wget "http://localhost:8080/job/CVS%20job/build?token=CVS-BUILD" 3 | -------------------------------------------------------------------------------- /jenkins/examples/git-post-commit: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | wget http://localhost:8080/git/notifyCommit?url=file://$HOME/python-git > /tmp/git.log 2>&1 3 | exit 0 4 | -------------------------------------------------------------------------------- /jenkins/examples/git-post-receive: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | wget http://localhost:8080/git/notifyCommit?url=file://$HOME/python-git > /tmp/git.log 2>&1 3 | exit 0 4 | -------------------------------------------------------------------------------- /jenkins/examples/hgrc: -------------------------------------------------------------------------------- 1 | [hooks] 2 | commit.jenkins = wget -q http://localhost:8080/mercurial/notifyCommit?url=file://$HOME/python-mercurial > /tmp/hg.log 2>&1 3 | incoming.jenkins = wget -q http://localhost:8080/mercurial/notifyCommit?url=file://$HOME/python-mercurial > /tmp/hg.log 2>&1 4 | -------------------------------------------------------------------------------- /jenkins/examples/svn-post-commit: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | REPOS="$1" 3 | REV="$2" 4 | UUID=`svnlook uuid $REPOS` 5 | wget \ 6 | --header "Content-Type:text/plain;charset=UTF-8" \ 7 | --post-data "`svnlook changed --revision $REV $REPOS`" \ 8 | --output-document "-" \ 9 | --timeout=10 \ 10 | http://localhost:8080/subversion/${UUID}/notifyCommit?rev=$REV > /tmp/svn.log 2>&1 11 | exit 0 12 | -------------------------------------------------------------------------------- /php/.gitignore: -------------------------------------------------------------------------------- 1 | ## PHP 2 | 3 | TestResults.xml 4 | -------------------------------------------------------------------------------- /php/README.md: -------------------------------------------------------------------------------- 1 | PHP and PHPUnit 2 | =============== 3 | 4 | Prerequisites 5 | ------------- 6 | 7 | **PHP**: 8 | 9 | To check if `php` is installed already: 10 | 11 | ``` 12 | $ php --version 13 | PHP 5.5.9-1ubuntu4.9 (cli) (built: Apr 17 2015 11:44:57) 14 | ``` 15 | 16 | If not, then see [PHP Hypertext Preprocessor](http://php.net/). 17 | 18 | **PHPUnit test framework**: 19 | 20 | To check if PHPUnit is installed already: 21 | 22 | ``` 23 | $ phpunit --version 24 | PHPUnit 4.8.9 by Sebastian Bergmann and contributors. 25 | ``` 26 | 27 | To download and install see [PHPUnit](https://phpunit.de/)'s [Getting started](https://phpunit.de/getting-started.html). The following provides a quick summary of the key steps to download and install PHPUnit in your home directory: 28 | 29 | ``` 30 | $ wget https://phar.phpunit.de/phpunit.phar 31 | $ chmod +x phpunit.phar 32 | $ mkdir $HOME/bin 33 | $ mv phpunit.phar $HOME/bin/phpunit 34 | $ phpunit --version 35 | PHPUnit 4.8.9 by Sebastian Bergmann and contributors. 36 | ``` 37 | 38 | Usage 39 | ----- 40 | 41 | Run: 42 | 43 | ``` 44 | $ php src/FibonacciProgram.php 20 45 | 832040 46 | ``` 47 | 48 | Run tests and view XML xUnit-style test report: 49 | 50 | ``` 51 | $ phpunit --log-junit TestResults.xml --bootstrap src/autoload.php test/FibonacciTest.php 52 | $ cat TestResults.xml 53 | ``` 54 | -------------------------------------------------------------------------------- /php/src/Fibonacci.php: -------------------------------------------------------------------------------- 1 | = 0\n"); 32 | } 33 | 34 | 35 | if (count($argv) < 2) 36 | { 37 | printUsage(); 38 | } 39 | else 40 | { 41 | print(Fibonacci::fib($argv[1])); 42 | print("\n"); 43 | } 44 | -------------------------------------------------------------------------------- /php/src/autoload.php: -------------------------------------------------------------------------------- 1 | '/Fibonacci.php' 8 | ); 9 | } 10 | $cn = strtolower($class); 11 | if (isset($classes[$cn])) { 12 | require __DIR__ . $classes[$cn]; 13 | } 14 | } 15 | ); 16 | -------------------------------------------------------------------------------- /php/test/FibonacciTest.php: -------------------------------------------------------------------------------- 1 | assertEquals(0, Fibonacci::fib(0)); 48 | } 49 | 50 | /** Test Fibonacci::fib(1). */ 51 | public function testFib1() 52 | { 53 | $this->assertEquals(1, Fibonacci::fib(1)); 54 | } 55 | 56 | /** Test Fibonacci::fib(2). */ 57 | public function testFib2() 58 | { 59 | $this->assertEquals(1, Fibonacci::fib(2)); 60 | } 61 | 62 | /** Test Fibonacci::fib(3). */ 63 | public function testFib3() 64 | { 65 | $this->assertEquals(2, Fibonacci::fib(3)); 66 | } 67 | 68 | /** Test Fibonacci::fib(30). */ 69 | public function testFib30() 70 | { 71 | $this->assertEquals(832040, Fibonacci::fib(30)); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /python/.gitignore: -------------------------------------------------------------------------------- 1 | ## Python 2 | 3 | *.py[cod] 4 | .python-version 5 | nosetests.xml 6 | -------------------------------------------------------------------------------- /python/README.md: -------------------------------------------------------------------------------- 1 | Python and pytest 2 | ================= 3 | 4 | Prerequisites 5 | ------------- 6 | 7 | **Python 2.7+ or Python 3**: 8 | 9 | To check if Python is installed already: 10 | 11 | ``` 12 | $ python --version 13 | Python 2.7.1+ 14 | ``` 15 | 16 | If not, then see [Downloading Python](http://wiki.python.org/moin/BeginnersGuide/Download). The [Anaconda](http://continuum.io/anacondace.html) scientific Python installer which has a comprehensive Python tool stack. 17 | 18 | **pytest**: 19 | 20 | To check if pytest is installed already: 21 | 22 | ``` 23 | $ py.test --version 24 | This is pytest version 2.7.0, imported from /usr/lib/python2.7/site-packages/pytest.pyc 25 | ``` 26 | 27 | If not, then see [pytest](https://docs.pytest.org/en/latest/). 28 | 29 | Usage 30 | ----- 31 | 32 | Run: 33 | 34 | ``` 35 | $ python maths/fibonacci.py 30 36 | fibonacci(30) = 832040 37 | ``` 38 | 39 | Run tests and view XML xUnit-style test report: 40 | 41 | ``` 42 | $ py.test --junit-xml=report.xml 43 | ============================= test session starts ============================== 44 | platform linux2 -- Python 2.7.5 -- py-1.4.27 -- pytest-2.7.0 45 | rootdir: /home/mjj/prog-skills/build_and_test_examples/python, inifile: 46 | plugins: cov 47 | collected 5 items 48 | 49 | maths/tests/test_fibonacci.py ..... 50 | 51 | generated xml file: /home/mjj/prog-skills/build_and_test_examples/python/report.xml 52 | =========================== 5 passed in 0.30 seconds =========================== 53 | $ cat report.xml 54 | ``` 55 | -------------------------------------------------------------------------------- /python/maths/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /python/maths/fibonacci.py: -------------------------------------------------------------------------------- 1 | """ 2 | Fibonacci numbers function. 3 | """ 4 | 5 | # Copyright 2014 The University of Edinburgh. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 16 | # implied. See the License for the specific language governing 17 | # permissions and limitations under the License. 18 | 19 | import sys 20 | 21 | def fibonacci(n): 22 | """ 23 | Calculate the Fibonacci number of the given integer. 24 | @param n If n <= 0 then 0 is assumed. 25 | @return fibonacci number. 26 | """ 27 | if n <= 0: 28 | return 0 29 | elif n == 1: 30 | return 1 31 | else: 32 | return fibonacci(n - 1) + fibonacci(n - 2) 33 | 34 | def print_usage(): 35 | """ Print usage information. """ 36 | print("Usage: python fibonacci.py N") 37 | print(" where N >= 0") 38 | 39 | if __name__ == '__main__': 40 | if (len(sys.argv) < 2): 41 | print_usage() 42 | exit(1) 43 | n = int(sys.argv[1]) 44 | if (n < 0): 45 | print_usage() 46 | exit(2) 47 | fib = fibonacci(n) 48 | print("fibonacci(%d) = %d" % (n, fib)) 49 | -------------------------------------------------------------------------------- /python/maths/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softwaresaved/build_and_test_examples/713ba4d46873be92df8ced3214c7e196b1ee68de/python/maths/tests/__init__.py -------------------------------------------------------------------------------- /python/maths/tests/test_fibonacci.py: -------------------------------------------------------------------------------- 1 | """ 2 | Fibonacci numbers test class. 3 | """ 4 | 5 | # Copyright 2014 The University of Edinburgh. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 16 | # implied. See the License for the specific language governing 17 | # permissions and limitations under the License. 18 | 19 | import unittest 20 | 21 | from maths.fibonacci import fibonacci 22 | 23 | class TestFibonacci(unittest.TestCase): 24 | """ 25 | Fibonacci numbers test class. 26 | """ 27 | 28 | def setUp(self): 29 | """ Initialise test suite - no-op. """ 30 | pass 31 | 32 | def tearDown(self): 33 | """ Clean up test suite - no-op. """ 34 | pass 35 | 36 | def test_fibonacci0(self): 37 | """ Test fibonacci(0). """ 38 | self.assertEqual(0, fibonacci(0)) 39 | 40 | def test_fibonacci1(self): 41 | """ Test fibonacci(1). """ 42 | self.assertEqual(1, fibonacci(1)) 43 | 44 | def test_fibonacci2(self): 45 | """ Test fibonacci(2). """ 46 | self.assertEqual(1, fibonacci(2)) 47 | 48 | def test_fibonacci3(self): 49 | """ Test fibonacci(3). """ 50 | self.assertEqual(2, fibonacci(3)) 51 | 52 | def test_fibonacci30(self): 53 | """ Test fibonacci(30). """ 54 | self.assertEqual(832040, fibonacci(30)) 55 | 56 | if __name__ == '__main__': 57 | unittest.main() 58 | -------------------------------------------------------------------------------- /sh/README.md: -------------------------------------------------------------------------------- 1 | Bash Shell 2 | ========== 3 | 4 | Prerequisites 5 | ------------- 6 | 7 | **Bash shell**: 8 | 9 | If using Windows, then see [Git Bash](http://msysgit.github.io/). 10 | 11 | Usage 12 | ----- 13 | 14 | Run: 15 | 16 | ``` 17 | $ ./fibonacci.sh 30 18 | fibonacci 30 = 832040 19 | ``` 20 | -------------------------------------------------------------------------------- /sh/fibonacci.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2014 The University of Edinburgh. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | # implied. See the License for the specific language governing 15 | # permissions and limitations under the License. 16 | 17 | fibonacci_number=0 18 | 19 | # Calculate the Fibonacci number of the given integer. 20 | # If $1 <= 0 then 0 is assumed. 21 | # After execution fibonacci_number holds the result. 22 | fibonacci() { 23 | n=$1 24 | if [ $n -le 0 ]; then 25 | fibonacci_number=0 26 | elif [ $n -eq 1 ]; then 27 | fibonacci_number=1 28 | else 29 | a=0 30 | b=1 31 | count=2 32 | fibonacci_number=$a 33 | while [ $count -le $n ]; do 34 | fibonacci_number=$[$a+$b] 35 | a=$b 36 | b=$fibonacci_number 37 | count=$[$count + 1] 38 | done 39 | fi 40 | } 41 | 42 | print_usage() { 43 | echo "Usage: ./fibonacci.sh N" 44 | echo " where N >= 0" 45 | } 46 | 47 | if [ -z "$1" ]; then 48 | print_usage 49 | exit 1 50 | elif [ $1 -lt 0 ]; then 51 | print_usage 52 | exit 2 53 | else 54 | fibonacci $1 55 | echo "fibonacci $1 = $fibonacci_number" 56 | fi 57 | -------------------------------------------------------------------------------- /travis/HelloWorld.md: -------------------------------------------------------------------------------- 1 | "Hello World" with Travis CI 2 | ============================ 3 | 4 | Here, we will set up a first Travis CI job, based around a simple "hello world" example, to get you up and running with Travis CI. 5 | 6 | Sign in to GitHub 7 | ----------------- 8 | 9 | If you do not already have an account, then visit [GitHub](https://github.com) and create a free account. 10 | 11 | If you already have an account, then visit [GitHub](https://github.com) and sign in. 12 | 13 | In the following text, replace `USERNAME` with your GitHub user name. 14 | 15 | Create a new repository on GitHub 16 | --------------------------------- 17 | 18 | Visit https://github.com/USERNAME. 19 | 20 | Click **Repositories** tab. 21 | 22 | Click **New**. 23 | 24 | Enter Repository name: `travis-lab` 25 | 26 | Click **Create repository**. 27 | 28 | Clone your fork locally 29 | ----------------------- 30 | 31 | Within a terminal window, clone your forked repository: 32 | 33 | ``` 34 | $ git clone https://USERNAME@github.com/USERNAME/travis-lab 35 | Cloning into 'travis-lab'... 36 | warning: You appear to have cloned an empty repository. 37 | Checking connectivity... done. 38 | $ cd travis-lab 39 | ``` 40 | 41 | The warning is expected. We'll now add some content. 42 | 43 | Create a "hello world" program 44 | ------------------------------ 45 | 46 | Create a short Python script, `hello.py`, in your repository, with the content: 47 | 48 | ``` 49 | print("Hello world!") 50 | ```` 51 | 52 | Run it: 53 | 54 | ``` 55 | $ python hello.py 56 | Hello world! 57 | ``` 58 | 59 | Add and commit this file to your repository and push the changes to GitHub: 60 | 61 | ``` 62 | $ git add hello.py 63 | $ git commit -m "Added Python hello world script" . 64 | $ git push origin master 65 | ``` 66 | 67 | Visit https://github.com/USERNAME/travis-lab and check that the repository now contains `hello.py`. 68 | 69 | Sign in to Travis CI 70 | -------------------- 71 | 72 | Once you have an account on GitHub, you can use this to sign in to Travis CI, so go to Travis CI, https://travis-ci.org/. 73 | 74 | Click on Sign in with GitHub. 75 | 76 | Enable your repository on Travis CI 77 | ----------------------------------- 78 | 79 | Now, you need to tell Travis CI to check for changes in your repository, so click on your name on the top-right of the Travis CI page and select **Accounts**. 80 | 81 | This will take you to a page, https://travis-ci.org/profile/USERNAME, which shows a list of your GitHub repositories that Travis CI knows about. 82 | 83 | If you cannot see `USERNAME/travis-lab`, then click the **Sync account** button which tells Travis CI to check your current repositories on GitHub. 84 | 85 | When you can see `USERNAME/travis-lab`, then click on the button next to it to instruct Travis CI to monitor that repository for changes. The X icon should change to a check/tick icon. 86 | 87 | Create a `.travis.yml` job file 88 | ------------------------------- 89 | 90 | Travis CI looks for a file called `.travis.yml` in a Git repository. This file tells Travis CI how to build and test your software. In addition, this file can be used to specify any dependencies you need installed before building or testing your software. So, let's add one. 91 | 92 | Create `.travis.yml` with the content: 93 | 94 | ``` 95 | language: python 96 | 97 | python: 98 | 99 | - "2.7" 100 | 101 | script: 102 | 103 | - python hello.py 104 | ``` 105 | 106 | This says we want Travis CI to set up a Python 2.7 environment, then run our hello.py script. 107 | 108 | Add and commit this file to your repository and push the changes to GitHub: 109 | 110 | ``` 111 | $ git add .travis.yml 112 | $ git commit -m "Added Travis CI job file" . 113 | $ git push origin master 114 | ``` 115 | 116 | Visit https://github.com/USERNAME/travis-lab and check that the repository now contains `.travis.yml`. 117 | 118 | Explore the Travis CI job information 119 | ------------------------------------- 120 | 121 | Visit https://travis-ci.org/USERNAME. You should see a job called `travis-lab`. Jobs are named after the corresponding repositories. 122 | 123 | Click on `travis-lab`. 124 | 125 | This will take you to a page, https://travis-ci.org/USERNAME/travis-lab, which shows information about the run of your Travis CI job. 126 | 127 | The job should be coloured green and with a check/tick icon which means that the job succeeded. 128 | 129 | Information on your Git repository, including the commit ID and branch is also displayed i.e. the commit that triggered the job to run. 130 | 131 | Under the **Current** tab you should see the Travis CI output from running your job. Most of the content is Travis CI-specific configuration, relating to how it configures its environment to build and test your code. Scroll to the bottom and you'll see what Travis CI does after it clones your repository: 132 | 133 | ``` 134 | $ git clone --depth=50 --branch=master https://github.com/USERNAME/travis-lab.git USERNAME/travis-lab 135 | $ source ~/virtualenv/python2.7/bin/activate 136 | $ python --version 137 | Python 2.7.13 138 | $ pip --version 139 | pip 9.0.1 from /home/travis/virtualenv/python2.7.13/lib/python2.7/site-packages (python 2.7) 140 | Could not locate requirements.txt. Override the install: key in your .travis.yml to install dependencies. 141 | ``` 142 | 143 | Certain lines are hidden, usually those concerned with setting up the environment for the job. Hidden lines are denoted by an arrow to the left of the line number. Click on these arrows to see the hidden lines. 144 | 145 | At the very bottom, is the content of most interest, Travis CI's execution of our script: 146 | 147 | ``` 148 | $ python hello.py 149 | Hello world! 150 | The command "python hello.py" exited with 0. 151 | Done. Your build exited with 0. 152 | ``` 153 | 154 | If a job completes with an exit code of 0 then the job is coloured green and with a check/tick icon, which means that the job succeeded. 155 | 156 | If it completes with a non-zero exit code then the job is coloured red and with an X icon, which means that the job failed e.g. either the build failed or the tests failed. 157 | 158 | Jobs still running are coloured yellow. 159 | 160 | Add a `README.md` file with a build status icon 161 | ----------------------------------------------- 162 | 163 | Each job has an associated status icon e.g. https://travis-ci.org/USERNAME/travis-lab.svg?branch=master. This can be embedded into a `README.md` file in a Git repository, so the current status of the build is always shown when viewing the Git repository via GitHub's web interface. 164 | 165 | Create a `README.md` file e.g.: 166 | 167 | ``` 168 | # README for travis-lab 169 | 170 | [![Build status](https://travis-ci.org/USERNAME/travis-lab.svg?master)](https://travis-ci.org/USERNAME) 171 | ``` 172 | 173 | This is MarkDown syntax and specifies a hyperlink to https://travis-ci.org/USERNAME that is rendered as an SVG image, whose source is at https://travis-ci.org/USERNAME/travis-lab.svg?master. 174 | 175 | Add `README.md` to your repository, commit it and push it. 176 | 177 | As you have committed a change to your repository, this will trigger a new run of your job on Travis CI. On the page https://travis-ci.org/USERNAME/travis-lab, click **Build History**. You may see your build in progress. 178 | 179 | Visit https://github.com/USERNAME/travis-lab and look for your icon in your `README.md` file. This feature exploits the fact that GitHub's web interface renders MarkDown-formatted files as HTML. 180 | 181 | Explore a "real world" example 182 | ------------------------------ 183 | 184 | https://github.com/softwaresaved/recipy is a fork of recipy, https://github.com/recipy/recipy, a framework for logging provenance about the environments under which Python scripts for research are run. 185 | 186 | Look at its Travis CI icon at the bottom of its `README.md` file. 187 | 188 | Look at its `.travis.yml` script at https://github.com/softwaresaved/recipy/blob/master/.travis.yml. This is a more complex script: 189 | 190 | * It runs under both Python 2.7 and 3.4 (`python` section). 191 | * It does some Python version-specific configuration and installation and updates environment variables (`before_install` section). 192 | * It installs many Python packages needed to run recipy's tests (`install` section). 193 | * It runs the tests using py.test (`script` section). py.test is run in verbose mode (`-v`) and it is requested to show extra test information (`-r`) and to ouput to the terminal (`-s`). 194 | 195 | Look at its Travis CI status information at https://travis-ci.org/softwaresaved/recipy, browse the output and see the download script. Note how specifying two language versions triggers two sub-jobs, one for Python 2.7 and one for Python 2.4. Note also how using the py.test flags ensures that information about individual test functions that are run is displayed within the script. 196 | 197 | Change your code 198 | ---------------- 199 | 200 | Make changes to your `hello.py` Python script then commit your changes and push them to GitHub. Watch how Travis CI regularly triggers new jobs. 201 | 202 | Create a Python file with some functions, and an associated test file with some unit tests. Update the `script` section of `.travis.yml` to run the tests using py.test. 203 | 204 | -------------------------------------------------------------------------------- /travis/Languages.md: -------------------------------------------------------------------------------- 1 | Create a Travis CI job for popular programming languages 2 | ======================================================== 3 | 4 | Travis CI can build and run code written in many languages, including C, C++, Fortran, Java, PHP and Python, either directly or via automated build tools like Make or ANT. It can also run unit tests, for example written for CUnit, CppUnit, googletest, JUnit, PHPUnit or pytest, and report on the success or failure of tests. For example, Travis CI provides out-of-the-box support for: 5 | 6 | * C: gcc, clang, autotools, make. 7 | * C++: gcc, clang, autotools, make. 8 | * Java: versions of Oracle JDK and OpenJDK, ANT, Maven, Gradle. 9 | * PHP: versions of PHP, PHPUnit, XDebug. 10 | * Python: versions of Python 2 and 3, pytest and mock test libraries. 11 | * and many other [languages](http://docs.travis-ci.com/user/languages/). 12 | 13 | Declare the language 14 | -------------------- 15 | 16 | `.travis.yml` supports a `language` section which tells Travis CI which build environment it should use. Depending on the language selected, a language-specific section (e.g. `jdk`, `php` or `python`) can then be used to specify which versions of the language the job is to be run under. Travis CI will run the job for each of these versions. 17 | 18 | * Edit `.travis.yml`, clear its current contents, and declare your language and any versions of the language you want to test. You can only declare one language in `travis.yml`. 19 | 20 | **C** 21 | 22 | ``` 23 | language: c 24 | ``` 25 | 26 | **C++** 27 | 28 | ``` 29 | language: cpp 30 | ``` 31 | 32 | **Java** 33 | 34 | ``` 35 | language: java 36 | 37 | jdk: 38 | - oraclejdk8 39 | - openjdk7 40 | ``` 41 | 42 | Here, we request that Travis CI runs the job twice, once under Oracle JDK 8 and once under Open JDK 7. 43 | 44 | **PHP** 45 | 46 | ``` 47 | language: php 48 | 49 | php: 50 | - 5.4 51 | - 5.5 52 | ``` 53 | 54 | **Python** 55 | 56 | ``` 57 | language: python 58 | 59 | python: 60 | - "2.7" 61 | - "3.4" 62 | ``` 63 | 64 | Here, we request that Travis CI runs the job twice, once under Python 2.7 and once under Python 3.4. 65 | 66 | List packages to install 67 | ------------------------ 68 | 69 | An `addons` section can, amongst other things, be used to install any packages we need. This can be used to specify packages that, if working locally, we'd need to install using the `apt` package manager. For example, if we wanted to use `graphviz` we could write: 70 | 71 | ``` 72 | addons: 73 | apt: 74 | packages: 75 | - graphviz 76 | ``` 77 | 78 | None of our examples below need any additional packages. 79 | 80 | Define pre-install steps 81 | ------------------------ 82 | 83 | A `before_install` section lists the steps that need to be executed before we can build, run or test our code. 84 | 85 | By default, Travis CI will run commands in the root of our Git repository i.e. within `build_and_test_examples`. So, to use our language-specific examples, we need to change into the appropriate directory. We can do this as a `before_install` step. 86 | 87 | For certain languages, we also need to download, build and install additional dependencies. 88 | 89 | **C** 90 | 91 | We download, build and install CUnit, then change into our `c` directory: 92 | 93 | ``` 94 | before_install: 95 | - wget http://downloads.sourceforge.net/project/cunit/CUnit/2.1-2/CUnit-2.1-2-src.tar.bz2 96 | - tar -xvjpf CUnit-2.1-2-src.tar.bz2 97 | - cd CUnit-2.1-2 98 | - ./configure --prefix=$TRAVIS_BUILD_DIR 99 | - make 100 | - make install 101 | - export C_INCLUDE_PATH=$TRAVIS_BUILD_DIR/include:$C_INCLUDE_PATH 102 | - export LIBRARY_PATH=$TRAVIS_BUILD_DIR/lib:$LIBRARY_PATH 103 | - export LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/lib:$LD_LIBRARY_PATH 104 | - cd .. 105 | - cd c 106 | ``` 107 | 108 | **C++** 109 | 110 | We download, build and install googletest, then change into our `cpp` directory: 111 | 112 | ``` 113 | before_install: 114 | - wget https://googletest.googlecode.com/files/gtest-1.7.0.zip 115 | - unzip gtest-1.7.0.zip 116 | - cd gtest-1.7.0/ 117 | - ./configure --prefix=$TRAVIS_BUILD_DIR --with-pthreads=no 118 | - make 119 | - mkdir $TRAVIS_BUILD_DIR/include/ 120 | - cp -r include/gtest $TRAVIS_BUILD_DIR/include 121 | - mkdir $TRAVIS_BUILD_DIR/lib/ 122 | - cp lib/.libs/* $TRAVIS_BUILD_DIR/lib/ 123 | - cd .. 124 | - export CPLUS_INCLUDE_PATH=$TRAVIS_BUILD_DIR/include:$CPLUS_INCLUDE_PATH 125 | - export LIBRARY_PATH=$TRAVIS_BUILD_DIR/lib:$LIBRARY_PATH 126 | - export LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/lib:$LD_LIBRARY_PATH 127 | - cd cpp 128 | ``` 129 | 130 | **Java** 131 | 132 | ANT is pre-installed by Travis CI, JUnit is held within our `java` directory, so all we need to do is change into our `java` directory: 133 | 134 | ``` 135 | before_install: 136 | - cd java 137 | ``` 138 | 139 | **PHP** 140 | 141 | PHPUnit is pre-installed by Travis CI, so all we need to do is change into our `php` directory: 142 | 143 | ``` 144 | before_install: 145 | - cd php 146 | ``` 147 | 148 | **Python** 149 | 150 | pytest's `py.test` test runner is pre-installed by Travis CI, but we will install the Python `pytest-cov` package, using the Python `pip` package installer, so we can generate a code coverage report, a report on the lines of code executed by our tests. We will then change into our `python` directory: 151 | 152 | ``` 153 | before_install: 154 | - pip install pytest-cov 155 | - cd python 156 | ``` 157 | 158 | Build and test code 159 | ------------------- 160 | 161 | Now we are ready to run our build. We specify the build steps in a `script` entry. Certain languages have default actions they take if the `script` entry is omitted. 162 | 163 | **C** 164 | 165 | If there is no `script` entry then Travis CI will execute: 166 | 167 | ``` 168 | ./configure && make && make test 169 | ``` 170 | 171 | As we don't have a `configure` script, we need to provide a `script` section with the commands we want to run: 172 | 173 | ``` 174 | script: 175 | - make test 176 | ``` 177 | 178 | **C++** 179 | 180 | If there is no `script` entry then Travis CI will execute: 181 | 182 | ``` 183 | ./configure && make && make test 184 | ``` 185 | 186 | As we don't have a `configure` script, we need to provide a `script` section with the commands we want to run: 187 | 188 | ``` 189 | script: 190 | - make googletest 191 | ``` 192 | 193 | **Java** 194 | 195 | If there is no `script` entry then Travis CI will execute: 196 | 197 | ``` 198 | ant test 199 | ``` 200 | 201 | As this command will compile and run our example, we do not need to provide an explicit `script` section. However, we could provide one if we wanted to be explicit as to how our code is built and tested: 202 | 203 | ``` 204 | script: 205 | - ant test 206 | ``` 207 | 208 | **PHP** 209 | 210 | If there is no `script` entry then Travis CI will execute: 211 | 212 | ``` 213 | phpunit 214 | ``` 215 | 216 | However, to run our PHP tests we need to provide a bootstrap value, so we need to provide a `script` section with the PHPUnit command we want to run: 217 | 218 | ``` 219 | script: 220 | - phpunit --bootstrap src/autoload.php --debug --coverage-text test 221 | ``` 222 | 223 | We use PHPUnit's `--debug` and `--coverage-text` flags to print out information about the tests being run and a code coverage report. 224 | 225 | **Python** 226 | 227 | Python needs a `script` entry to specify how to run any tests: 228 | 229 | ``` 230 | script: 231 | - py.test -v --cov=maths 232 | ``` 233 | 234 | We use `py.test`'s `-v` and `--cove` flags to print out information about the tests being run and a code coverage report for the `maths` module. 235 | 236 | Example `.travis.yml` files 237 | --------------------------- 238 | 239 | Following the above examples you should have a completed `.travis.yml` file that looks like one of the following: 240 | 241 | * C: [.travis.yml](./examples/c-travis.yml). 242 | * C++: [.travis.yml](./examples/cpp-travis.yml). 243 | * Java: [.travis.yml](./examples/java-travis.yml). 244 | * PHP: [.travis.yml](./examples/php-travis.yml). 245 | * Python: [.travis.yml](./examples/python-travis.yml). 246 | 247 | Commit and push to trigger a new build 248 | -------------------------------------- 249 | 250 | Now, we should commit the changes to `travis.yml` to trigger a new build: 251 | 252 | * Commit and push changes: 253 | 254 | ``` 255 | $ git commit -m "Updated .travis.yml to configure build environment, install dependencies and build and run tests" .travis.yml 256 | $ git push origin master 257 | ``` 258 | 259 | * Visit https://travis-ci.org/USERNAME/build_and_test_examples. 260 | * If building C and C++ there should be a single job. 261 | * If building Java, PHP, and Python there should be a single job with two sub-jobs, one for each version of these languages we are testing under. 262 | * Jobs should be coloured green with a tick, indicating that they passed. 263 | * Click on one of the jobs. 264 | * You should see that the tests run and all passed e.g. 265 | 266 | C: 267 | 268 | ``` 269 | $ make test 270 | gcc -O3 -c test/fibonacci_cunit_test.c -o fibonacci_cunit_test.o -Isrc -Itest -I/home/travis/include 271 | gcc -O3 -c src/fibonacci.c -o fibonacci.o -Isrc -Itest -I/home/travis/include 272 | gcc -O3 -c test/cunit_test_driver.c -o cunit_test_driver.o -Isrc -Itest -I/home/travis/include 273 | gcc -O3 -o fibonacci-tests fibonacci_cunit_test.o fibonacci.o cunit_test_driver.o -Isrc -Itest -I/home/travis/include -lcunit 274 | ./fibonacci-tests 275 | CUnit - A unit testing framework for C - Version 2.1-2 276 | http://cunit.sourceforge.net/ 277 | Suite: Fibonacci Suite 278 | Test: test_fibonacci_1 ...passed 279 | Test: test_fibonacci_2 ...passed 280 | Test: test_fibonacci_3 ...passed 281 | Test: test_fibonacci_30 ...passed 282 | Run Summary: Type Total Ran Passed Failed Inactive 283 | suites 1 1 n/a 0 0 284 | tests 4 4 4 0 0 285 | asserts 4 4 4 0 n/a 286 | Elapsed time = 0.000 seconds 287 | The command "make test" exited with 0. 288 | Done. Your build exited with 0. 289 | ``` 290 | 291 | C++: 292 | 293 | ``` 294 | $ make googletest 295 | c++ -c test/fibonacci_google_test.cc -o fibonacci_google_test.o -Isrc -Itest -I/home/travis/include 296 | c++ -o fibonacci-googletests src/fibonacci.h fibonacci_google_test.o -Isrc -Itest -I/home/travis/include -lgtest -lgtest_main 297 | ./fibonacci-googletests --gtest_output="xml:TestResults.xml" 298 | Running main() from gtest_main.cc 299 | [==========] Running 4 tests from 1 test case. 300 | [----------] Global test environment set-up. 301 | [----------] 4 tests from FibonacciTest 302 | [ RUN ] FibonacciTest.fibonacci1 303 | [ OK ] FibonacciTest.fibonacci1 (0 ms) 304 | [ RUN ] FibonacciTest.fibonacci2 305 | [ OK ] FibonacciTest.fibonacci2 (0 ms) 306 | [ RUN ] FibonacciTest.fibonacci3 307 | [ OK ] FibonacciTest.fibonacci3 (0 ms) 308 | [ RUN ] FibonacciTest.fibonacci30 309 | [ OK ] FibonacciTest.fibonacci30 (6 ms) 310 | [----------] 4 tests from FibonacciTest (6 ms total) 311 | [----------] Global test environment tear-down 312 | [==========] 4 tests from 1 test case ran. (6 ms total) 313 | [ PASSED ] 4 tests. 314 | The command "make googletest" exited with 0. 315 | Done. Your build exited with 0. 316 | ``` 317 | 318 | Java: 319 | 320 | ``` 321 | $ ant test 322 | Buildfile: /home/travis/build/mikej888/build_and_test_examples/java/build.xml 323 | init: 324 | [mkdir] Created dir: /home/travis/build/mikej888/build_and_test_examples/java/build 325 | [mkdir] Created dir: /home/travis/build/mikej888/build_and_test_examples/java/build/lib 326 | [mkdir] Created dir: /home/travis/build/mikej888/build_and_test_examples/java/build/classes 327 | [mkdir] Created dir: /home/travis/build/mikej888/build_and_test_examples/java/build/test 328 | [mkdir] Created dir: /home/travis/build/mikej888/build_and_test_examples/java/build/test/classes 329 | compile: 330 | [javac] Compiling 1 source file to /home/travis/build/mikej888/build_and_test_examples/java/build/classes 331 | compile-tests: 332 | [javac] Compiling 1 source file to /home/travis/build/mikej888/build_and_test_examples/java/build/test/classes 333 | test: 334 | [mkdir] Created dir: /home/travis/build/mikej888/build_and_test_examples/java/build/test/xml 335 | [junit] Running math.FibonacciTest 336 | [junit] Testsuite: math.FibonacciTest 337 | [junit] Tests run: 5, Failures: 0, Errors: 0, Time elapsed: 0.11 sec 338 | [junit] Tests run: 5, Failures: 0, Errors: 0, Time elapsed: 0.11 sec 339 | [junit] 340 | [junit] Testcase: testFib3 took 0.007 sec 341 | [junit] Testcase: testFib30 took 0.007 sec 342 | [junit] Testcase: testFibMinusOne took 0 sec 343 | [junit] Testcase: testFib1 took 0 sec 344 | [junit] Testcase: testFib2 took 0 sec 345 | BUILD SUCCESSFUL 346 | Total time: 2 seconds 347 | The command "ant test" exited with 0. 348 | Done. Your build exited with 0. 349 | ``` 350 | 351 | PHP: 352 | 353 | ``` 354 | $ phpunit --bootstrap src/autoload.php --debug --coverage-text test 355 | PHPUnit 4.5.0 by Sebastian Bergmann and contributors. 356 | Starting test 'Maths\FibonacciTest::testFib0'. 357 | . 358 | Starting test 'Maths\FibonacciTest::testFib1'. 359 | . 360 | Starting test 'Maths\FibonacciTest::testFib2'. 361 | . 362 | Starting test 'Maths\FibonacciTest::testFib3'. 363 | . 364 | Starting test 'Maths\FibonacciTest::testFib30'. 365 | . 366 | Time: 1.42 minutes, Memory: 10.00Mb 367 | OK (5 tests, 5 assertions) 368 | Code Coverage Report: 369 | 2015-10-01 11:23:36 370 | 371 | Summary: 372 | Classes: 100.00% (1/1) 373 | Methods: 100.00% (1/1) 374 | Lines: 100.00% (16/16) 375 | \Maths::Fibonacci 376 | Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 7/ 7) 377 | The command "phpunit --bootstrap src/autoload.php --debug --coverage-text test" exited with 0. 378 | Done. Your build exited with 0. 379 | ``` 380 | 381 | Python: 382 | 383 | ``` 384 | $ py.test -v --cov=maths 385 | ============================= test session starts ============================== 386 | platform linux2 -- Python 2.7.9 -- py-1.4.26 -- pytest-2.6.4 -- /home/travis/virtualenv/python2.7.9/bin/python 387 | plugins: cov 388 | collected 5 items 389 | 390 | maths/tests/test_fibonacci.py::TestFibonacci::test_fibonacci0 PASSED 391 | maths/tests/test_fibonacci.py::TestFibonacci::test_fibonacci1 PASSED 392 | maths/tests/test_fibonacci.py::TestFibonacci::test_fibonacci2 PASSED 393 | maths/tests/test_fibonacci.py::TestFibonacci::test_fibonacci3 PASSED 394 | maths/tests/test_fibonacci.py::TestFibonacci::test_fibonacci30 PASSED 395 | 396 | ---------- coverage: platform linux2, python 2.7.9-final-0 ----------- 397 | Name Stmts Miss Cover 398 | --------------------------------------------------- 399 | maths/__init__.py 0 0 100% 400 | maths/fibonacci.py 20 11 45% 401 | maths/tests/__init__.py 0 0 100% 402 | maths/tests/test_fibonacci.py 19 1 95% 403 | --------------------------------------------------- 404 | TOTAL 39 12 69% 405 | 406 | =========================== 5 passed in 0.94 seconds =========================== 407 | The command "py.test -v --cov=msc" exited with 0. 408 | 409 | Done. Your build exited with 0. 410 | ``` 411 | 412 | Further information 413 | ------------------- 414 | 415 | For more information on Travis CI's support for the languages above, see the Travis CI pages on: 416 | 417 | * [C](http://docs.travis-ci.com/user/languages/c/) 418 | * [C++](http://docs.travis-ci.com/user/languages/cpp/) 419 | * [Java](http://docs.travis-ci.com/user/languages/java/) 420 | * [PHP](http://docs.travis-ci.com/user/languages/php/) 421 | * [Python](http://docs.travis-ci.com/user/languages/python/) 422 | 423 | -------------------------------------------------------------------------------- /travis/README.md: -------------------------------------------------------------------------------- 1 | Getting started with Travis CI 2 | ============================== 3 | 4 | [Travis CI](https://travis-ci.org/) is a hosted [continuous integration](http://en.wikipedia.org/wiki/Continuous_Integration) service, which provides automated build-and-test services for projects hosted on [GitHub](https://github.com). The service is free for open source projects. 5 | 6 | Travis CI detects and responds to changes made to code or files held within Git repositories on GitHub. If the code is changed, by a commit, then Travis CI automatically runs a build-and-test job for that repository. This means that the software is rebuilt and tested every time changes to the code are pushed to GitHub. Since Travis CI is remote from your own machine, it means you can continue working while the tests are under way. It also means you do not have to set up a machine for testing locally, which can be useful if you are don't have the funding, hardware or time to set this up yourself. 7 | 8 | This is not intended to be a complete introduction to everything that Travis CI offers. Rather, it is hoped that it will serve to get you started, helping you through your first 20 minutes of using Travis CI, to give an idea as to its potential and usefulness. 9 | 10 | The walkthrough can be performed using Linux or UNIX. 11 | 12 | "Hello World" with Travis CI 13 | ---------------------------- 14 | 15 | Here, we will set up a first Travis CI job, based around a simple "hello world" example, to get you up and running with Travis CI: 16 | 17 | * ["Hello World" with Travis CI](./HelloWorld.md) 18 | 19 | Use Travis CI to run build-and-test jobs for various languages 20 | -------------------------------------------------------------- 21 | 22 | Travis CI can build and run code written in many languages, including C, C++, Fortran, Java, PHP and Python, either directly or via automated build tools like Make or ANT. It can also run unit tests, for example written for CUnit, CppUnit, googletest, JUnit, PHPUnit or pytest, and report on the success or failure of tests. For example, Travis CI provides out-of-the-box support for: 23 | 24 | * [Create a Travis CI job for popular programming languages](./Languages.md) including C, C++, Java, PHP and Python. 25 | 26 | Publishing test results 27 | ----------------------- 28 | 29 | Unlike Jenkins, Travis CI does not allow build artefacts to be explored directly, nor does it parse xUnit-compliant XML test results into a browsable form. However, Travis CI can automatically upload build artefacts to an [Amazon S3](https://aws.amazon.com/s3/) (Simple Storage Service) area. For details, see: 30 | 31 | * Travis CI's [S3 Deployment](http://docs.travis-ci.com/user/deployment/s3/). 32 | * Travis CI's [Uploading Artifacts on Travis CI](http://docs.travis-ci.com/user/uploading-artifacts/). 33 | * Stack Overflow's [Access files stored on Amazon S3 through web browser](http://stackoverflow.com/questions/16784052/access-files-stored-on-amazon-s3-through-web-browser). 34 | 35 | Travis CI limitations 36 | --------------------- 37 | 38 | Travis CI will terminate a job if: 39 | 40 | * It takes longer than 120 minutes to run. 41 | * It produces a log that exceeds 4MB. 42 | * It produces no outputs for 10 minutes. 43 | * It consumes more than 3GB memory. 44 | 45 | See Travis CI's suggestions for [speeding up the build](http://docs.travis-ci.com/user/speeding-up-the-build/). The build matrix mentioned on that page can also help in reducing log sizes. Another way of reducing log sizes is to reduce the verbosity of test functions (e.g. ensuring they don't print to standard output or error) or to redirect their outputs to files. 46 | 47 | Further information 48 | ------------------- 49 | 50 | This has just touched upon the myriad configuration options, build steps, test steps, notification mechanisms and publishing options that Travis CI supports. For more information check out: 51 | 52 | * [Travis CI for Complete Beginners](http://docs.travis-ci.com/user/for-beginners/). 53 | * [Getting started](http://docs.travis-ci.com/user/getting-started/). 54 | * [Travis CI user documentation](http://docs.travis-ci.com/). 55 | * [Travis Client](https://github.com/travis-ci/travis.rb) - a Ruby-based command-line tool and library for command-line interaction with Travis CI. 56 | -------------------------------------------------------------------------------- /travis/examples/c-travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | before_install: 4 | - wget http://downloads.sourceforge.net/project/cunit/CUnit/2.1-2/CUnit-2.1-2-src.tar.bz2 5 | - tar -xvjpf CUnit-2.1-2-src.tar.bz2 6 | - cd CUnit-2.1-2 7 | - ./configure --prefix=$TRAVIS_BUILD_DIR 8 | - make 9 | - make install 10 | - export C_INCLUDE_PATH=$TRAVIS_BUILD_DIR/include:$C_INCLUDE_PATH 11 | - export LIBRARY_PATH=$TRAVIS_BUILD_DIR/lib:$LIBRARY_PATH 12 | - export LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/lib:$LD_LIBRARY_PATH 13 | - cd .. 14 | - cd c 15 | 16 | script: 17 | - make test 18 | -------------------------------------------------------------------------------- /travis/examples/cpp-travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | 3 | before_install: 4 | - wget https://googletest.googlecode.com/files/gtest-1.7.0.zip 5 | - unzip gtest-1.7.0.zip 6 | - cd gtest-1.7.0/ 7 | - ./configure --prefix=$TRAVIS_BUILD_DIR --with-pthreads=no 8 | - make 9 | - mkdir $TRAVIS_BUILD_DIR/include/ 10 | - cp -r include/gtest $TRAVIS_BUILD_DIR/include 11 | - mkdir $TRAVIS_BUILD_DIR/lib/ 12 | - cp lib/.libs/* $TRAVIS_BUILD_DIR/lib/ 13 | - cd .. 14 | - export CPLUS_INCLUDE_PATH=$TRAVIS_BUILD_DIR/include:$CPLUS_INCLUDE_PATH 15 | - export LIBRARY_PATH=$TRAVIS_BUILD_DIR/lib:$LIBRARY_PATH 16 | - export LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/lib:$LD_LIBRARY_PATH 17 | - cd cpp 18 | 19 | script: 20 | - make googletest 21 | -------------------------------------------------------------------------------- /travis/examples/java-travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | jdk: 4 | - oraclejdk8 5 | - openjdk7 6 | 7 | before_install: 8 | - cd java 9 | -------------------------------------------------------------------------------- /travis/examples/php-travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.4 5 | - 5.5 6 | 7 | before_install: 8 | - cd php 9 | 10 | script: 11 | - phpunit --bootstrap src/autoload.php --debug --coverage-text test 12 | -------------------------------------------------------------------------------- /travis/examples/python-travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | 3 | python: 4 | - "2.7" 5 | - "3.4" 6 | 7 | before_install: 8 | - pip install pytest-cov 9 | - cd python 10 | 11 | script: 12 | - py.test -v --cov=maths 13 | --------------------------------------------------------------------------------