Skip to content

Fix behavior of copy and similar #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ReadOnlyArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Base.iterate(x::ReadOnlyArray, args...) = iterate(x.parent, args...)

Base.length(x::ReadOnlyArray) = length(x.parent)

Base.similar(x::ReadOnlyArray) = similar(x.parent) |> ReadOnlyArray
Base.similar(x::ReadOnlyArray) = similar(x.parent)

Base.axes(x::ReadOnlyArray) = axes(x.parent)

Expand Down
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ end
fa = f()
@test fa isa ReadOnlyArray{Float64,2}
@test fa == x

a = ReadOnly([1, 2])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReadOnly doesn't seem to be defined:

(ReadOnlyArrays) pkg> test
  No Changes to `~/.julia/dev/ReadOnlyArrays/Project.toml`
  No Changes to `~/.julia/dev/ReadOnlyArrays/Manifest.toml`
     Testing ReadOnlyArrays
      Status `/tmp/jl_Dsjfkt/Project.toml`
  [988b38a3] ReadOnlyArrays v0.2.0 `~/.julia/dev/ReadOnlyArrays`
  [8dfed614] Test
      Status `/tmp/jl_Dsjfkt/Manifest.toml`
  [988b38a3] ReadOnlyArrays v0.2.0 `~/.julia/dev/ReadOnlyArrays`
  [2a0f44e3] Base64
  [b77e0a4c] InteractiveUtils
  [56ddb016] Logging
  [d6f4376e] Markdown
  [9a3f8284] Random
  [ea8e919c] SHA v0.7.0
  [9e88b42a] Serialization
  [8dfed614] Test
     Testing Running tests...
Test Summary: | Pass  Total  Time
Constructors  |    3      3  0.0s
misc: Error During Test at /home/tim/.julia/dev/ReadOnlyArrays/test/runtests.jl:46
  Got exception outside of a @test
  UndefVarError: `ReadOnly` not defined
  Stacktrace:
    [1] macro expansion
      @ ~/.julia/dev/ReadOnlyArrays/test/runtests.jl:55 [inlined]
    [2] macro expansion
      @ ~/.julia/juliaup/julia-1.10.2+0.x64.linux.gnu/share/julia/stdlib/v1.10/Test/src/Test.jl:1577 [inlined]
    [3] macro expansion
      @ ~/.julia/dev/ReadOnlyArrays/test/runtests.jl:47 [inlined]
    [4] macro expansion
      @ ~/.julia/juliaup/julia-1.10.2+0.x64.linux.gnu/share/julia/stdlib/v1.10/Test/src/Test.jl:1577 [inlined]
    [5] top-level scope
      @ ~/.julia/dev/ReadOnlyArrays/test/runtests.jl:14
    [6] include(fname::String)
      @ Base.MainInclude ./client.jl:489
    [7] top-level scope
      @ none:6
    [8] eval
      @ ./boot.jl:385 [inlined]
    [9] exec_options(opts::Base.JLOptions)
      @ Base ./client.jl:291
   [10] _start()
      @ Base ./client.jl:552
Test Summary: | Pass  Error  Total  Time
Interface     |   22      1     23  1.7s
  size        |    4             4  0.0s
  indexing    |    3             3  0.0s
  iteration   |   11            11  0.1s
  misc        |    4      1      5  1.6s
ERROR: LoadError: Some tests did not pass: 22 passed, 0 failed, 1 errored, 0 broken.
in expression starting at /home/tim/.julia/dev/ReadOnlyArrays/test/runtests.jl:13
ERROR: Package ReadOnlyArrays errored during testing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xref #14

@test typeof(similar(a)) === Vector{Int64}

@test copy(a) == [1, 2]
@test typeof(copy(a)) === Vector{Int64}
end
end

Expand Down