From 4f628c49d096dcf93e40cb0c05fdabd2dd27e7df Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Mon, 9 Dec 2024 21:42:55 -0500 Subject: [PATCH] Skeleton updates (#3) --- .github/workflows/CI.yml | 79 ----------------------------- .github/workflows/Documentation.yml | 23 +++++++++ .github/workflows/FormatCheck.yml | 36 +++---------- .github/workflows/LiterateCheck.yml | 42 +++------------ .github/workflows/Tests.yml | 42 +++++++++++++++ .pre-commit-config.yaml | 7 +-- Project.toml | 12 ----- README.md | 18 +++++-- docs/Project.toml | 3 -- examples/Project.toml | 3 -- examples/README.jl | 22 ++++++-- src/GradedUnitRanges.jl | 47 +++++++++++++++++ src/blockedunitrange.jl | 18 ------- src/dual.jl | 2 - src/fusion.jl | 6 --- src/gradedunitrange.jl | 34 +------------ src/gradedunitrangedual.jl | 9 ---- src/labelledunitrangedual.jl | 2 - src/onetoone.jl | 3 -- test/Project.toml | 10 +++- test/runtests.jl | 65 +++++++++++++++++++++--- test/test_aqua.jl | 7 +++ 22 files changed, 238 insertions(+), 252 deletions(-) delete mode 100644 .github/workflows/CI.yml create mode 100644 .github/workflows/Documentation.yml create mode 100644 .github/workflows/Tests.yml create mode 100644 test/test_aqua.jl diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml deleted file mode 100644 index 5173033..0000000 --- a/.github/workflows/CI.yml +++ /dev/null @@ -1,79 +0,0 @@ -name: CI -on: - push: - branches: - - main - tags: ['*'] - pull_request: - workflow_dispatch: -concurrency: - # Skip intermediate builds: always. - # Cancel intermediate builds: only if it is a pull request build. - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} -jobs: - test: - name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - runs-on: ${{ matrix.os }} - timeout-minutes: 60 - permissions: # needed to allow julia-actions/cache to proactively delete old caches that it has created - actions: write - contents: read - strategy: - fail-fast: false - matrix: - version: - # - 'lts' # TODO: Bring back once dependencies are registered. - - '1' - os: - - ubuntu-latest - - macOS-latest - - windows-latest - arch: - - x64 - steps: - - uses: actions/checkout@v4 - - uses: julia-actions/setup-julia@v2 - with: - version: ${{ matrix.version }} - arch: ${{ matrix.arch }} - - uses: julia-actions/cache@v2 - - uses: julia-actions/julia-buildpkg@v1 - - uses: julia-actions/julia-runtest@v1 - - uses: julia-actions/julia-processcoverage@v1 - - uses: codecov/codecov-action@v5 - with: - files: lcov.info - token: ${{ secrets.CODECOV_TOKEN }} - fail_ci_if_error: false - docs: - name: Documentation - runs-on: ubuntu-latest - permissions: - actions: write # needed to allow julia-actions/cache to proactively delete old caches that it has created - contents: write - statuses: write - steps: - - uses: actions/checkout@v4 - - uses: julia-actions/setup-julia@v2 - with: - version: '1' - - uses: julia-actions/cache@v2 - - name: Configure doc environment - shell: julia --project=docs --color=yes {0} - run: | - using Pkg - Pkg.develop(PackageSpec(path=pwd())) - Pkg.instantiate() - - uses: julia-actions/julia-buildpkg@v1 - - uses: julia-actions/julia-docdeploy@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} - - name: Run doctests - shell: julia --project=docs --color=yes {0} - run: | - using Documenter: DocMeta, doctest - using GradedUnitRanges - DocMeta.setdocmeta!(GradedUnitRanges, :DocTestSetup, :(using GradedUnitRanges); recursive=true) - doctest(GradedUnitRanges) diff --git a/.github/workflows/Documentation.yml b/.github/workflows/Documentation.yml new file mode 100644 index 0000000..01a7f7a --- /dev/null +++ b/.github/workflows/Documentation.yml @@ -0,0 +1,23 @@ +name: "Documentation" + +on: + push: + branches: + - main + tags: '*' + pull_request: + schedule: + - cron: '1 4 * * 4' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref_name != github.event.repository.default_branch || github.ref != 'refs/tags/v*' }} + +jobs: + build-and-deploy-docs: + name: "Documentation" + uses: "ITensor/ITensorActions/.github/workflows/Documentation.yml@main" + with: + localregistry: https://github.com/ITensor/ITensorRegistry.git + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/FormatCheck.yml b/.github/workflows/FormatCheck.yml index bb6d933..3f78afc 100644 --- a/.github/workflows/FormatCheck.yml +++ b/.github/workflows/FormatCheck.yml @@ -1,35 +1,13 @@ -name: Format check +name: "Format Check" + on: push: - branches: [main] - tags: [v*] + branches: + - 'main' + tags: '*' pull_request: jobs: - format: + format-check: name: "Format Check" - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: julia-actions/setup-julia@v2 - with: - version: 1 - - name: Install JuliaFormatter and format - run: | - julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))' - julia -e 'using JuliaFormatter; format(".", verbose=true)' - - name: Check format - run: | - julia -e ' - out = Cmd(`git diff --name-only`) |> read |> String - if out == "" - exit(0) - else - @error "The following files have not been formatted:" - write(stdout, out) - out_diff = Cmd(`git diff`) |> read |> String - @error "Diff:" - write(stdout, out_diff) - exit(1) - @error "" - end' + uses: "ITensor/ITensorActions/.github/workflows/FormatCheck.yml@main" diff --git a/.github/workflows/LiterateCheck.yml b/.github/workflows/LiterateCheck.yml index a071729..2ca5f27 100644 --- a/.github/workflows/LiterateCheck.yml +++ b/.github/workflows/LiterateCheck.yml @@ -1,41 +1,15 @@ -name: Literate check +name: "Literate Check" + on: push: - branches: [main] - tags: [v*] + branches: + - 'main' + tags: '*' pull_request: jobs: literate: name: "Literate Check" - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: julia-actions/setup-julia@v2 - with: - version: 1 - - name: Install Literate and generate docs - run: | - julia -e ' - using Pkg - # TODO: Delete once they are registered. - Pkg.add(url="https://github.com/ITensor/LabelledNumbers.jl") - Pkg.develop(PackageSpec(path=pwd())) - Pkg.instantiate() - Pkg.add(PackageSpec(name="Literate"))' - julia -e 'include("docs/make_readme.jl")' - - name: Check if docs need to be updated - run: | - julia -e ' - out = Cmd(`git diff --name-only`) |> read |> String - if out == "" - exit(0) - else - @error "The docs are outdated, rerun Literate to regenerate them." - write(stdout, out) - out_diff = Cmd(`git diff`) |> read |> String - @error "Diff:" - write(stdout, out_diff) - exit(1) - @error "" - end' + uses: "ITensor/ITensorActions/.github/workflows/LiterateCheck.yml@main" + with: + localregistry: https://github.com/ITensor/ITensorRegistry.git diff --git a/.github/workflows/Tests.yml b/.github/workflows/Tests.yml new file mode 100644 index 0000000..5a0a306 --- /dev/null +++ b/.github/workflows/Tests.yml @@ -0,0 +1,42 @@ +name: Tests +on: + push: + branches: + - 'master' + - 'main' + - 'release-' + tags: '*' + paths-ignore: + - 'docs/**' + pull_request: + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + # Cancel intermediate builds: only if it is a pull request build. + cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} + +jobs: + tests: + name: "Tests" + strategy: + fail-fast: false + matrix: + version: + - 'lts' # minimal supported version + - '1' # latest released Julia version + # group: + # - 'core' + # - 'optional' + os: + - ubuntu-latest + - macOS-latest + - windows-latest + uses: "ITensor/ITensorActions/.github/workflows/Tests.yml@main" + with: + group: "${{ matrix.group }}" + julia-version: "${{ matrix.version }}" + os: "${{ matrix.os }}" + localregistry: https://github.com/ITensor/ITensorRegistry.git + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bff1fb7..6599365 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,7 +7,8 @@ repos: - id: check-yaml - id: end-of-file-fixer exclude_types: [markdown] # incompatible with Literate.jl -- repo: https://github.com/qiaojunfeng/pre-commit-julia-format - rev: v0.2.0 + +- repo: "https://github.com/domluna/JuliaFormatter.jl" + rev: v1.0.62 hooks: - - id: julia-format + - id: "julia-formatter" diff --git a/Project.toml b/Project.toml index a2a4f5c..7b2cd01 100644 --- a/Project.toml +++ b/Project.toml @@ -10,22 +10,10 @@ FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b" LabelledNumbers = "f856a3a6-4152-4ec4-b2a7-02c1a55d7993" SplitApplyCombine = "03a91e81-4c3e-53e1-a0a4-9c0c8f19dd66" -[sources] -LabelledNumbers = {url = "https://github.com/ITensor/LabelledNumbers.jl"} - [compat] -Aqua = "0.8.9" BlockArrays = "1.2.0" Compat = "4.16.0" FillArrays = "1.13.0" LabelledNumbers = "0.1.0" SplitApplyCombine = "1.2.3" -Test = "1.10" julia = "1.10" - -[extras] -Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" - -[targets] -test = ["Aqua", "Test"] diff --git a/README.md b/README.md index 0a53259..f036abf 100644 --- a/README.md +++ b/README.md @@ -2,19 +2,31 @@ [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://ITensor.github.io/GradedUnitRanges.jl/stable/) [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://ITensor.github.io/GradedUnitRanges.jl/dev/) -[![Build Status](https://github.com/ITensor/GradedUnitRanges.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/ITensor/GradedUnitRanges.jl/actions/workflows/CI.yml?query=branch%3Amain) +[![Build Status](https://github.com/ITensor/GradedUnitRanges.jl/actions/workflows/Tests.yml/badge.svg?branch=main)](https://github.com/ITensor/GradedUnitRanges.jl/actions/workflows/Tests.yml?query=branch%3Amain) [![Coverage](https://codecov.io/gh/ITensor/GradedUnitRanges.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/ITensor/GradedUnitRanges.jl) [![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle) [![Aqua](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl) ## Installation instructions +This package resides in the `ITensor/ITensorRegistry` local registry. +In order to install, simply add that registry through your package manager. +This step is only required once. ```julia julia> using Pkg: Pkg -julia> Pkg.add(url="https://github.com/ITensor/LabelledNumbers.jl") +julia> Pkg.Registry.add(url="https://github.com/ITensor/ITensorRegistry") +``` +or: +```julia +julia> Pkg.Registry.add(url="git@github.com:ITensor/ITensorRegistry.git") +``` +if you want to use SSH credentials, which can make it so you don't have to enter your Github ursername and password when registering packages. -julia> Pkg.add(url="https://github.com/ITensor/GradedUnitRanges.jl") +Then, the package can be added as usual through the package manager: + +```julia +julia> Pkg.add("GradedUnitRanges") ``` ## Examples diff --git a/docs/Project.toml b/docs/Project.toml index c41c00b..183946f 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -3,6 +3,3 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" GradedUnitRanges = "e2de450a-8a67-46c7-b59c-01d5a3d041c5" LabelledNumbers = "f856a3a6-4152-4ec4-b2a7-02c1a55d7993" Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306" - -[sources] -LabelledNumbers = {url = "https://github.com/ITensor/LabelledNumbers.jl"} diff --git a/examples/Project.toml b/examples/Project.toml index e7d1fa8..221122b 100644 --- a/examples/Project.toml +++ b/examples/Project.toml @@ -1,6 +1,3 @@ [deps] GradedUnitRanges = "e2de450a-8a67-46c7-b59c-01d5a3d041c5" LabelledNumbers = "f856a3a6-4152-4ec4-b2a7-02c1a55d7993" - -[sources] -LabelledNumbers = {url = "https://github.com/ITensor/LabelledNumbers.jl"} diff --git a/examples/README.jl b/examples/README.jl index bc9799a..26492dc 100644 --- a/examples/README.jl +++ b/examples/README.jl @@ -2,20 +2,36 @@ # # [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://ITensor.github.io/GradedUnitRanges.jl/stable/) # [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://ITensor.github.io/GradedUnitRanges.jl/dev/) -# [![Build Status](https://github.com/ITensor/GradedUnitRanges.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/ITensor/GradedUnitRanges.jl/actions/workflows/CI.yml?query=branch%3Amain) +# [![Build Status](https://github.com/ITensor/GradedUnitRanges.jl/actions/workflows/Tests.yml/badge.svg?branch=main)](https://github.com/ITensor/GradedUnitRanges.jl/actions/workflows/Tests.yml?query=branch%3Amain) # [![Coverage](https://codecov.io/gh/ITensor/GradedUnitRanges.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/ITensor/GradedUnitRanges.jl) # [![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle) # [![Aqua](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl) # ## Installation instructions +# This package resides in the `ITensor/ITensorRegistry` local registry. +# In order to install, simply add that registry through your package manager. +# This step is only required once. #= ```julia julia> using Pkg: Pkg -julia> Pkg.add(url="https://github.com/ITensor/LabelledNumbers.jl") +julia> Pkg.Registry.add(url="https://github.com/ITensor/ITensorRegistry") +``` +=# +# or: +#= +```julia +julia> Pkg.Registry.add(url="git@github.com:ITensor/ITensorRegistry.git") +``` +=# +# if you want to use SSH credentials, which can make it so you don't have to enter your Github ursername and password when registering packages. + +# Then, the package can be added as usual through the package manager: -julia> Pkg.add(url="https://github.com/ITensor/GradedUnitRanges.jl") +#= +```julia +julia> Pkg.add("GradedUnitRanges") ``` =# diff --git a/src/GradedUnitRanges.jl b/src/GradedUnitRanges.jl index 8ee4cdb..027ca17 100644 --- a/src/GradedUnitRanges.jl +++ b/src/GradedUnitRanges.jl @@ -1,4 +1,50 @@ module GradedUnitRanges + +using BlockArrays: + BlockArrays, + AbstractBlockVector, + AbstractBlockedUnitRange, + Block, + BlockIndex, + BlockRange, + BlockSlice, + BlockVector, + BlockedOneTo, + BlockedUnitRange, + BlockedVector, + blockedrange, + BlockIndexRange, + block, + blocks, + blockaxes, + blockfirsts, + blocklasts, + blockisequal, + blocklength, + blocklengths, + blockindex, + findblock, + findblockindex, + combine_blockaxes, + mortar, + sortedunion +using Compat: allequal +using FillArrays: Fill +using LabelledNumbers: + LabelledNumbers, + LabelledInteger, + LabelledUnitRange, + LabelledStyle, + IsLabelled, + NotLabelled, + label, + label_type, + labelled, + labelled_isequal, + unlabel, + islabelled +using SplitApplyCombine: groupcount + include("blockedunitrange.jl") include("gradedunitrange.jl") include("dual.jl") @@ -6,4 +52,5 @@ include("labelledunitrangedual.jl") include("gradedunitrangedual.jl") include("onetoone.jl") include("fusion.jl") + end diff --git a/src/blockedunitrange.jl b/src/blockedunitrange.jl index d913dd6..9be42a6 100644 --- a/src/blockedunitrange.jl +++ b/src/blockedunitrange.jl @@ -1,21 +1,3 @@ -using BlockArrays: - BlockArrays, - AbstractBlockVector, - AbstractBlockedUnitRange, - Block, - BlockIndex, - BlockIndexRange, - BlockRange, - BlockSlice, - BlockVector, - BlockedOneTo, - BlockedUnitRange, - BlockedVector, - block, - blockindex, - findblock, - findblockindex - # Custom `BlockedUnitRange` constructor that takes a unit range # and a set of block lengths, similar to `BlockArray(::AbstractArray, blocklengths...)`. function blockedunitrange(a::AbstractUnitRange, blocklengths) diff --git a/src/dual.jl b/src/dual.jl index e39c5c6..a543736 100644 --- a/src/dual.jl +++ b/src/dual.jl @@ -8,8 +8,6 @@ dual_type(T::Type) = T nondual_type(x) = nondual_type(typeof(x)) nondual_type(T::Type) = T -using LabelledNumbers: LabelledStyle, IsLabelled, NotLabelled, label, labelled, unlabel - dual(i::LabelledInteger) = labelled(unlabel(i), dual(label(i))) label_dual(x) = label_dual(LabelledStyle(x), x) label_dual(::NotLabelled, x) = x diff --git a/src/fusion.jl b/src/fusion.jl index 1e69467..fd270cd 100644 --- a/src/fusion.jl +++ b/src/fusion.jl @@ -1,5 +1,3 @@ -using BlockArrays: AbstractBlockedUnitRange, blocklengths - # https://github.com/ITensor/ITensors.jl/blob/v0.3.57/NDTensors/src/lib/GradedAxes/src/tensor_product.jl # https://en.wikipedia.org/wiki/Tensor_product # https://github.com/KeitaNakamura/Tensorial.jl @@ -45,13 +43,11 @@ function fuse_blocklengths(x::Integer, y::Integer) return blockedrange([x * y]) end -using LabelledNumbers: LabelledInteger, label, labelled, unlabel function fuse_blocklengths(x::LabelledInteger, y::LabelledInteger) # return blocked unit range to keep non-abelian interface return blockedrange([labelled(x * y, fuse_labels(label(x), label(y)))]) end -using BlockArrays: blockedrange, blocks function tensor_product(a1::AbstractBlockedUnitRange, a2::AbstractBlockedUnitRange) nested = map(Iterators.flatten((Iterators.product(blocks(a1), blocks(a2)),))) do it return mapreduce(length, fuse_blocklengths, it) @@ -65,8 +61,6 @@ function blocksortperm(a::AbstractUnitRange) return Block.(sortperm(blocklabels(nondual(a)))) end -using BlockArrays: Block, BlockVector -using SplitApplyCombine: groupcount # Get the permutation for sorting, then group by common elements. # groupsortperm([2, 1, 2, 3]) == [[2], [1, 3], [4]] function groupsortperm(v; kwargs...) diff --git a/src/gradedunitrange.jl b/src/gradedunitrange.jl index 487552c..fb431be 100644 --- a/src/gradedunitrange.jl +++ b/src/gradedunitrange.jl @@ -1,36 +1,3 @@ -using BlockArrays: - BlockArrays, - AbstractBlockVector, - AbstractBlockedUnitRange, - Block, - BlockIndex, - BlockRange, - BlockSlice, - BlockVector, - BlockedOneTo, - BlockedUnitRange, - blockedrange, - BlockIndexRange, - blockfirsts, - blockisequal, - blocklength, - blocklengths, - findblock, - findblockindex, - mortar, - sortedunion -using Compat: allequal -using FillArrays: Fill -using LabelledNumbers: - LabelledNumbers, - LabelledInteger, - LabelledUnitRange, - label, - label_type, - labelled, - labelled_isequal, - unlabel - abstract type AbstractGradedUnitRange{T,BlockLasts} <: AbstractBlockedUnitRange{T,BlockLasts} end @@ -71,6 +38,7 @@ blocklabels(r::AbstractUnitRange) = Fill(NoLabel(), blocklength(r)) blocklabels(la::LabelledUnitRange) = [label(la)] function LabelledNumbers.labelled_isequal(a1::AbstractUnitRange, a2::AbstractUnitRange) + # TODO: fix type piracy return blockisequal(a1, a2) && (blocklabels(a1) == blocklabels(a2)) end diff --git a/src/gradedunitrangedual.jl b/src/gradedunitrangedual.jl index 2d26d91..f0c3486 100644 --- a/src/gradedunitrangedual.jl +++ b/src/gradedunitrangedual.jl @@ -39,8 +39,6 @@ function blockedunitrange_getindices( return dual(getindex(nondual(a), indices)) end -using BlockArrays: Block, BlockIndexRange, BlockRange - function blockedunitrange_getindices(a::GradedUnitRangeDual, indices::Integer) return label_dual(getindex(nondual(a), indices)) end @@ -111,26 +109,19 @@ end Base.axes(a::GradedUnitRangeDual) = axes(nondual(a)) -using BlockArrays: BlockArrays, Block, BlockSlice -using LabelledNumbers: LabelledUnitRange function BlockArrays.BlockSlice(b::Block, a::LabelledUnitRange) return BlockSlice(b, unlabel(a)) end -using BlockArrays: BlockArrays, BlockSlice -using GradedUnitRanges: GradedUnitRangeDual, dual function BlockArrays.BlockSlice(b::Block, r::GradedUnitRangeDual) return BlockSlice(b, dual(r)) end -using LabelledNumbers: LabelledNumbers, LabelledUnitRange, label function Base.iterate(a::GradedUnitRangeDual, i) i == last(a) && return nothing return dual.(iterate(nondual(a), i)) end -using LabelledNumbers: LabelledInteger, label, labelled, unlabel -using BlockArrays: BlockArrays, blockaxes, blocklasts, combine_blockaxes, findblock BlockArrays.blockaxes(a::GradedUnitRangeDual) = blockaxes(nondual(a)) BlockArrays.blockfirsts(a::GradedUnitRangeDual) = label_dual.(blockfirsts(nondual(a))) BlockArrays.blocklasts(a::GradedUnitRangeDual) = label_dual.(blocklasts(nondual(a))) diff --git a/src/labelledunitrangedual.jl b/src/labelledunitrangedual.jl index b2ca841..e1c600c 100644 --- a/src/labelledunitrangedual.jl +++ b/src/labelledunitrangedual.jl @@ -1,7 +1,5 @@ # LabelledUnitRangeDual is obtained by slicing a GradedUnitRangeDual with a block -using LabelledNumbers: LabelledNumbers, label, labelled, unlabel - struct LabelledUnitRangeDual{T,NondualUnitRange<:AbstractUnitRange{T}} <: AbstractUnitRange{T} nondual_unitrange::NondualUnitRange diff --git a/src/onetoone.jl b/src/onetoone.jl index 6b572fc..785fe84 100644 --- a/src/onetoone.jl +++ b/src/onetoone.jl @@ -1,6 +1,3 @@ -using BlockArrays: AbstractBlockedUnitRange -using LabelledNumbers: islabelled - # Represents the range `1:1` or `Base.OneTo(1)`. struct OneToOne{T} <: AbstractUnitRange{T} end OneToOne() = OneToOne{Bool}() diff --git a/test/Project.toml b/test/Project.toml index d059149..2076916 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -2,7 +2,13 @@ BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e" GradedUnitRanges = "e2de450a-8a67-46c7-b59c-01d5a3d041c5" LabelledNumbers = "f856a3a6-4152-4ec4-b2a7-02c1a55d7993" +Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" +SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" +Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" -[sources] -LabelledNumbers = {url = "https://github.com/ITensor/LabelledNumbers.jl"} +[compat] +Aqua = "0.8.9" +SafeTestsets = "0.1" +Suppressor = "0.2" +Test = "1.10" diff --git a/test/runtests.jl b/test/runtests.jl index fe2c61a..bd97441 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,12 +1,61 @@ -@eval module $(gensym()) -using Test: @testset +using SafeTestsets: @safetestset +using Suppressor: Suppressor -@testset "GradedUnitRanges.jl" begin - filenames = filter(readdir(@__DIR__)) do f - startswith("test_")(f) && endswith(".jl")(f) +# check for filtered groups +# either via `--group=ALL` or through ENV["GROUP"] +const pat = r"(?:--group=)(\w+)" +arg_id = findfirst(contains(pat), ARGS) +const GROUP = uppercase( + if isnothing(arg_id) + get(ENV, "GROUP", "ALL") + else + only(match(pat, ARGS[arg_id]).captures) + end, +) + +"match files of the form `test_*.jl`, but exclude `*setup*.jl`" +istestfile(fn) = + endswith(fn, ".jl") && startswith(basename(fn), "test_") && !contains(fn, "setup") +"match files of the form `*.jl`, but exclude `*_notest.jl` and `*setup*.jl`" +isexamplefile(fn) = + endswith(fn, ".jl") && !endswith(fn, "_notest.jl") && !contains(fn, "setup") + +@time begin + # tests in groups based on folder structure + for testgroup in filter(isdir, readdir(@__DIR__)) + if GROUP == "ALL" || GROUP == uppercase(testgroup) + for file in filter(istestfile, readdir(joinpath(@__DIR__, testgroup); join=true)) + @eval @safetestset $file begin + include($file) + end + end + end + end + + # single files in top folder + for file in filter(istestfile, readdir(@__DIR__)) + (file == basename(@__FILE__)) && continue # exclude this file to avoid infinite recursion + @eval @safetestset $file begin + include($file) + end end - @testset "Test $filename" for filename in filenames - include(filename) + + # test examples + examplepath = joinpath(@__DIR__, "..", "examples") + for (root, _, files) in walkdir(examplepath) + contains(chopprefix(root, @__DIR__), "setup") && continue + for file in filter(isexamplefile, files) + filename = joinpath(root, file) + @eval begin + @safetestset $file begin + $(Expr( + :macrocall, + GlobalRef(Suppressor, Symbol("@suppress")), + LineNumberNode(@__LINE__, @__FILE__), + :(include($filename)), + )) + end + end + end end end -end diff --git a/test/test_aqua.jl b/test/test_aqua.jl new file mode 100644 index 0000000..d6bf1e5 --- /dev/null +++ b/test/test_aqua.jl @@ -0,0 +1,7 @@ +using GradedUnitRanges: GradedUnitRanges +using Aqua: Aqua +using Test: @testset + +@testset "Code quality (Aqua.jl)" begin + Aqua.test_all(GradedUnitRanges; ambiguities=false, piracies=false) +end