From 622c07a34e2738dc80d7e0893dd917805bda99fa Mon Sep 17 00:00:00 2001 From: Andy Hayden Date: Fri, 25 Sep 2015 15:25:20 -0700 Subject: [PATCH] Add a basic runtests.jl and update travis Fix for some deprecations. --- .travis.yml | 24 ++++++++++++------------ src/Autoreload.jl | 8 ++++---- src/constants.jl | 6 +++--- src/dependencies.jl | 4 ++-- src/files.jl | 2 +- src/smart_types.jl | 6 +++--- test/runtests.jl | 40 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 65 insertions(+), 25 deletions(-) create mode 100644 test/runtests.jl diff --git a/.travis.yml b/.travis.yml index 784039d..0102793 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,13 @@ -language: cpp -compiler: - - clang -notifications: - email: false -before_install: - - sudo add-apt-repository ppa:staticfloat/julia-deps -y - - sudo add-apt-repository ppa:staticfloat/julianightlies -y - - sudo apt-get update -qq -y - - sudo apt-get install libpcre3-dev julia -y +language: julia +os: + - linux + - osx +julia: + - 0.3 + - 0.4 + - nightly script: - - julia -e 'Pkg.init(); run(`ln -s $(pwd()) $(Pkg.dir("Autoreload"))`); Pkg.pin("Autoreload"); Pkg.resolve()' - - julia -e 'using Autoreload; @assert isdefined(:Autoreload); @assert typeof(Autoreload) === Module' + - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi + - julia --check-bounds=yes -e 'Pkg.clone(pwd()); Pkg.build("Autoreload"); Pkg.test("Autoreload"; coverage=true)' +after_success: + - julia -e 'cd(Pkg.dir("Autoreload")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(process_folder()); Codecov.submit(process_folder())' diff --git a/src/Autoreload.jl b/src/Autoreload.jl index 5a1ddfe..d76de8e 100644 --- a/src/Autoreload.jl +++ b/src/Autoreload.jl @@ -42,7 +42,7 @@ function remove_file(filename) pop!(files, filename) end -function arequire(filename=""; command= :on, depends_on=String[]) +function arequire(filename=""; command= :on, depends_on=UTF8String[]) if isempty(filename) return collect(keys(files)) end @@ -50,7 +50,7 @@ function arequire(filename=""; command= :on, depends_on=String[]) filename = find_file(standarize(filename), constants=options[:constants]) filename == nothing && error("File $original_filename not found") if command in [:on, :on_depends] - if filename in files + if filename in keys(files) remove_file(filename) end if command == :on @@ -58,7 +58,7 @@ function arequire(filename=""; command= :on, depends_on=String[]) else should_reload = false end - files[filename] = AFile(should_reload, reload_mtime(filename), String[]) + files[filename] = AFile(should_reload, reload_mtime(filename), UTF8String[]) parsed_file = parse_file(filename) auto_depends = extract_deps(parsed_file) auto_depends = [_.name for _ in auto_depends] #todo respect reload flag @@ -153,7 +153,7 @@ function areload(command= :force; kwargs...) dependencies = get_dependency_graph() file_order = topological_sort(dependencies) should_reload = [filename=>false for filename in file_order] - marked_for_mtime_update = String[] + marked_for_mtime_update = UTF8String[] for (i, file) in enumerate(file_order) file_time = files[file].mtime if reload_mtime(file) > file_time diff --git a/src/constants.jl b/src/constants.jl index 614dda1..24df8ca 100644 --- a/src/constants.jl +++ b/src/constants.jl @@ -1,15 +1,15 @@ type AFile should_reload::Bool mtime::Float64 - deps::Vector{String} + deps::Vector{UTF8String} end type Dep should_reload::Bool - name::String + name::UTF8String end suppress_warnings = false -const files = Dict{String,AFile}() +const files = Dict{UTF8String,AFile}() const options = @compat Dict{Symbol,Any}(:constants=>false, :strip_types=>true, :smart_types=>true, :verbose_level=>:warn, :state=>:on) # verbose_level = :warn # state = :on diff --git a/src/dependencies.jl b/src/dependencies.jl index 709ba96..2f7522a 100644 --- a/src/dependencies.jl +++ b/src/dependencies.jl @@ -50,11 +50,11 @@ end function _extract_deps(e::Expr, deps::Vector{Dep}) if e.head == :call if e.args[1] == :include - if isa(e.args[2], String) + if isa(e.args[2], AbstractString) push!(deps, Dep(false, e.args[2])) end # elseif e.args[1] == :require - # if isa(e.args[2], String) + # if isa(e.args[2], AbstractString) # push!(deps, Dep(true, e.args[2])) # end end diff --git a/src/files.jl b/src/files.jl index 465e35f..29a2917 100644 --- a/src/files.jl +++ b/src/files.jl @@ -1,4 +1,4 @@ -function find_in_path(name::String; constants::Bool=true) +function find_in_path(name::AbstractString; constants::Bool=true) isabspath(name) && return name isfile(name) && return abspath(name) base = name diff --git a/src/smart_types.jl b/src/smart_types.jl index a4f26fc..11170db 100644 --- a/src/smart_types.jl +++ b/src/smart_types.jl @@ -1,5 +1,5 @@ function should_symbol_recurse(var) - taboo = [Module, String, Dict, Array, Tuple, DataType, Function] + taboo = [Module, AbstractString, Dict, Array, Tuple, DataType, Function] for datatype in taboo if isa(var, datatype) return false @@ -120,7 +120,7 @@ function eval_includes(e_block) e.head == :call && e.args[1] == :include local f - if isa(e.args[2], String) + if isa(e.args[2], AbstractString) f = e.args[2] elseif isa(e.args[2], Expr) try @@ -286,7 +286,7 @@ function _collect_symbols(m, vars, depth) end function unsafe_alter_type!(x, T::DataType) - ptr = convert(Ptr{Uint64}, pointer_from_objref(x)) + ptr = convert(Ptr{@compat UInt64}, pointer_from_objref(x)) ptr_array = pointer_to_array(ptr, 1) ptr_array[1] = pointer_from_objref(T) x diff --git a/test/runtests.jl b/test/runtests.jl new file mode 100644 index 0000000..7087475 --- /dev/null +++ b/test/runtests.jl @@ -0,0 +1,40 @@ +using Base.Test +using Autoreload + +m1_before = """ +module M +type MyType + x::Int +end + +f(var::MyType) = 1 +end +""" + +m1_after = """ +module M +type MyType + x::Int +end + +f(var::MyType) = 2 +end +""" + +open(joinpath(dirname(@__FILE__), "M.jl"), "w") do f + write(f, m1_before) +end + +using Autoreload +arequire("M") +my_var = M.MyType(5) +M.f(my_var) + +open(joinpath(dirname(@__FILE__), "M.jl"), "w") do f + write(f, m1_after) +end + +areload() +@test M.f(my_var) == 2 + +rm(joinpath(dirname(@__FILE__), "M.jl"))