From 2081f88c266455aeca553c86f75914e7334a280d Mon Sep 17 00:00:00 2001 From: Jukka Aho Date: Tue, 24 Jul 2018 12:10:09 +0300 Subject: [PATCH] Make package julia 0.7 compatible - Include files from `CheckHeader.jl` and `CheckTabs.jl`. - Activate Travis-CI. - Use Documenter.jl to generate documentation. --- .gitignore | 3 ++ .travis.yml | 15 ++++++++ README.md | 19 ++++++---- REQUIRE | 5 +++ docs/deploy.jl | 10 +++++ docs/make.jl | 12 ++++++ docs/src/index.md | 10 +++++ src/PkgTestSuite.jl | 29 ++------------ src/checkheader.jl | 82 ++++++++++++++++++++++++++++++++++++++++ src/checktabs.jl | 37 ++++++++++++++++++ test/runtests.jl | 13 +++++++ test/test_checkheader.jl | 24 ++++++++++++ test/test_checktabs.jl | 24 ++++++++++++ 13 files changed, 251 insertions(+), 32 deletions(-) create mode 100644 .travis.yml create mode 100644 REQUIRE create mode 100644 docs/deploy.jl create mode 100644 docs/make.jl create mode 100644 docs/src/index.md create mode 100644 src/checkheader.jl create mode 100644 src/checktabs.jl create mode 100644 test/runtests.jl create mode 100644 test/test_checkheader.jl create mode 100644 test/test_checktabs.jl diff --git a/.gitignore b/.gitignore index 381e0b6..f198260 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ *.jl.*.cov *.jl.mem deps/deps.jl +docs/site +new_file_with_tabs.jl +new_file_with_wrong_license_header.jl diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..4305575 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,15 @@ +language: julia +os: + - linux + - osx +julia: + - 0.6 + - 0.7 + - nightly +matrix: + allow_failures: + - julia: 0.7 + - julia: nightly + fast_finish: true +after_success: + - julia --color=yes -e 'using PkgTestSuite; deploy()' diff --git a/README.md b/README.md index 9de265c..9bf599d 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,21 @@ # PkgTestSuite.jl -Standard test suite for packages under JuliaFEM +[![Build Status](https://travis-ci.org/JuliaFEM/PkgTestSuite.jl.svg?branch=master)](https://travis-ci.org/JuliaFEM/PkgTestSuite.jl) + +Standard test suite for packages under JuliaFEM organization. The purpose of +this package is to +1. avoid unnecessary boilerplate code of setting up new packages, and +2. provide a standardized way to test that package matches to JuliaFEM standards. Usage from command line: ```julia julia> using PkgTestSuite -julia> test(pkg) -julia> deploy(pkg) +julia> test(pkg_name) +julia> deploy(pkg_name) ``` -`pkg` is the name of the package. If running `deploy()` from command line, documentation is generated to `docs/site`. +If running `deploy()` from command line, documentation is generated to `docs/site`. Usage from Travis-CI: @@ -25,10 +30,10 @@ after_success: ``` Default sequence is: -1. check that all source files contain licence string using CheckHeader.jl -2. check that no tabs are used in source files using CheckTabs.jl +1. check that all source files contain licence string +2. check that no tabs are used in source files 3. check code syntax using Lint.jl -4. check documentation using Documenter.jl +4. generate documentation of package using Documenter.jl 5. run all unit tests 6. deploy documentation to juliafem.github.io and coverage report to coveralls.io diff --git a/REQUIRE b/REQUIRE new file mode 100644 index 0000000..dd51ba8 --- /dev/null +++ b/REQUIRE @@ -0,0 +1,5 @@ +julia 0.6 +Coverage +Documenter +Lint +TimerOutputs diff --git a/docs/deploy.jl b/docs/deploy.jl new file mode 100644 index 0000000..ec37ace --- /dev/null +++ b/docs/deploy.jl @@ -0,0 +1,10 @@ +# This file is a part of JuliaFEM. +# License is MIT: see https://github.com/JuliaFEM/PkgTestSuite.jl/blob/master/LICENSE + +using Documenter + +deploydocs( + repo = "github.com/JuliaFEM/PkgTestSuite.jl.git", + julia = "0.7", + deps = nothing, + make = nothing) diff --git a/docs/make.jl b/docs/make.jl new file mode 100644 index 0000000..feee7de --- /dev/null +++ b/docs/make.jl @@ -0,0 +1,12 @@ +# This file is a part of JuliaFEM. +# License is MIT: see https://github.com/JuliaFEM/PkgTestSuite.jl/blob/master/LICENSE + +using Documenter +using PkgTestSuite + +makedocs(modules=[PkgTestSuite], + format = :html, + checkdocs = :all, + sitename = "PkgTestSuite.jl", + pages = ["index.md"] + ) diff --git a/docs/src/index.md b/docs/src/index.md new file mode 100644 index 0000000..5e3d491 --- /dev/null +++ b/docs/src/index.md @@ -0,0 +1,10 @@ +# PkgTestSuite.jl + +Package contains a standardized testing routines for packages under JuliaFEM +organization. + +```@meta +DocTestSetup = quote + using PkgTestSuite +end +``` diff --git a/src/PkgTestSuite.jl b/src/PkgTestSuite.jl index 59c5095..ba95948 100644 --- a/src/PkgTestSuite.jl +++ b/src/PkgTestSuite.jl @@ -1,38 +1,17 @@ # This file is a part of JuliaFEM. -# License is MIT: see https://github.com/PkgTestSuite.jl/blob/master/LICENSE +# License is MIT: see https://github.com/JuliaFEM/PkgTestSuite.jl/blob/master/LICENSE module PkgTestSuite -installed_packages = Pkg.installed() - -if !haskey(installed_packages, "CheckHeader") - Pkg.clone("https://github.com/ahojukka5/CheckHeader.jl.git") -end -if !haskey(installed_packages, "CheckTabs") - Pkg.clone("https://github.com/ahojukka5/CheckTabs.jl.git") -end -if !haskey(installed_packages, "Coverage") - Pkg.add("Coverage") -end -if !haskey(installed_packages, "Documenter") - Pkg.add("Documenter") -end -if !haskey(installed_packages, "Lint") - Pkg.add("Lint") -end -if !haskey(installed_packages, "TimerOutputs") - Pkg.add("TimerOutputs") -end - -using CheckHeader -using CheckTabs using Coverage using Documenter using Lint using TimerOutputs - using Base.Test +include("checkheader.jl") +include("checktabs.jl") + """ determine_pkg_name(pkg::String="") diff --git a/src/checkheader.jl b/src/checkheader.jl new file mode 100644 index 0000000..f9b2994 --- /dev/null +++ b/src/checkheader.jl @@ -0,0 +1,82 @@ +# This file is a part of JuliaFEM. +# License is MIT: see https://github.com/JuliaFEM/PkgTestSuite.jl/blob/master/LICENSE + +""" + read_header(fid) + +Read header from file content. + +Searches "part of" and "license" lines using regular expression +from file header. +""" +function read_header(fd) + lines = readlines(fd) + header_comment = true + header_lines = [] + regex_strings = [r"(This file is a part of \w+)", + r"(License is [\s\w.]+: [\w\W\s]+)"] + no_empty_lines = filter(x->x != "", lines) + for line in no_empty_lines + !startswith(line, "#") && break + for each in regex_strings + found = match(each, line) + found != nothing && push!(header_lines, found[1]) + end + end + return header_lines +end + +""" + checkheader(pkg_name; source_dirs=["src", "test"]) + +Check headers of files. + +Reads all julia source files from source_dirs and compares +that file license header matches the one found from packages +main file license header. +""" +function checkheader(package::String; source_dirs=["src", "test"]) + pkg_dir = Pkg.dir(package) + main_file = joinpath(pkg_dir, "src", package * ".jl") + main_header = open(read_header, main_file) + nlines = length(main_header) + info("Found header from $package.jl:") + info("------------------------------") + for j=1:nlines + info(main_header[j]) + end + info("------------------------------") + hasdiff = false + nfiles = 0 + for dir in source_dirs + isdir(joinpath(pkg_dir, dir)) || continue + all_files = readdir(joinpath(pkg_dir, dir)) + only_julia_files = filter(x->endswith(x, ".jl"), all_files) + for file_name in only_julia_files + nfiles += 1 + src_file = joinpath(pkg_dir, dir, file_name) + header_compare = open(read_header, src_file) + lines_in_compare = length(header_compare) + if lines_in_compare != nlines + info(header_compare, " ", file_name) + warn("The number of header lines differs in file $dir/$file_name:") + hasdiff = true + continue + end + for j=1:nlines + if main_header[j] != header_compare[j] + warn("Header content difference in file $dir/$file_name:") + hasdiff = true + break + end + end + end + end + if hasdiff + error("Found header differences between source files!") + end + info("Header is same in all $nfiles files.") + return true +end + +export checkheader diff --git a/src/checktabs.jl b/src/checktabs.jl new file mode 100644 index 0000000..b448de8 --- /dev/null +++ b/src/checktabs.jl @@ -0,0 +1,37 @@ +# This file is a part of JuliaFEM. +# License is MIT: see https://github.com/JuliaFEM/PkgTestSuite.jl/blob/master/LICENSE + +""" + checktabs(pkg_name) + +Read all julia source files of package and check that no tabulators are found +from files. +""" +function checktabs(package::String) + pkg_dir = Pkg.dir(package) + dirs = ["src", "test"] + hastabs = false + nfiles = 0 + for dir in dirs + isdir(joinpath(pkg_dir, dir)) || continue + all_files = readdir(joinpath(pkg_dir, dir)) + for file_name in all_files + endswith(file_name, ".jl") || continue + nfiles += 1 + src_file = joinpath(pkg_dir, dir, file_name) + src_lines = readlines(open(src_file)) + for (i, line) in enumerate(src_lines) + if '\t' in line + warn("use of tabulator found at file $file_name, at line $i:") + println(line) + hastabs = true + end + end + end + end + if hastabs + error("Source files has tabs. Please fix files.") + end + info("No use of tabulator found from $nfiles source files.") + return true +end diff --git a/test/runtests.jl b/test/runtests.jl new file mode 100644 index 0000000..7d6403c --- /dev/null +++ b/test/runtests.jl @@ -0,0 +1,13 @@ +# This file is a part of JuliaFEM. +# License is MIT: see https://github.com/JuliaFEM/PkgTestSuite.jl/blob/master/LICENSE + +using PkgTestSuite +using Base.Test + +@testset "test checkheader" begin + include("test_checkheader.jl") +end + +@testset "test checktabs" begin + include("test_checktabs.jl") +end diff --git a/test/test_checkheader.jl b/test/test_checkheader.jl new file mode 100644 index 0000000..e718a0b --- /dev/null +++ b/test/test_checkheader.jl @@ -0,0 +1,24 @@ +# This file is a part of JuliaFEM. +# License is MIT: see https://github.com/JuliaFEM/PkgTestSuite.jl/blob/master/LICENSE + +using PkgTestSuite: checkheader +using Base.Test + +new_file_path = Pkg.dir("PkgTestSuite", "src", "new_file_with_wrong_license_header.jl") +if isfile(new_file_path) + rm(new_file_path) +end + +@test checkheader("PkgTestSuite") + +fid = open(new_file_path, "w") +write(fid, """ +# This file is not a part of JuliaFEM. +# License is not MIT: don't see https://github.com/JuliaFEM/PkgTestSuite.jl/blob/master/LICENSE + +function foo() + return 1 +end +""") +close(fid) +@test_throws Exception checkheader("PkgTestSuite") diff --git a/test/test_checktabs.jl b/test/test_checktabs.jl new file mode 100644 index 0000000..750e3d0 --- /dev/null +++ b/test/test_checktabs.jl @@ -0,0 +1,24 @@ +# This file is a part of JuliaFEM. +# License is MIT: see https://github.com/JuliaFEM/PkgTestSuite.jl/blob/master/LICENSE + +using PkgTestSuite: checktabs +using Base.Test + +new_file_path = Pkg.dir("PkgTestSuite", "src", "new_file_with_tabs.jl") +if isfile(new_file_path) + rm(new_file_path) +end + +@test checktabs("PkgTestSuite") + +fid = open(new_file_path, "w") +write(fid, """ +# This file is a part of JuliaFEM. +# License is MIT: see https://github.com/JuliaFEM/PkgTestSuite.jl/blob/master/LICENSE + +function foo() +\treturn 1 +end +""") +close(fid) +@test_throws Exception checktabs("PkgTestSuite")