Skip to content

copilot-core: Increase test coverage for Copilot.Core.Type.Array. Refs #767. - #768

Merged
ivanperez-keera merged 3 commits into
Copilot-Language:masterfrom
ivanperez-keera:develop-tests-core-type-array
Oct 12, 2026
Merged

ivanperez-keera merged 3 commits into
Copilot-Language:masterfrom
ivanperez-keera:develop-tests-core-type-array

Conversation

@ivanperez-keera

Copy link
Copy Markdown
Member

Add two tests and force evaluation of a Proxy, thus achieving full coverage in all three main categories used by hpc, as prescribed in the solution proposed for #767.

@ivanperez-keera
ivanperez-keera force-pushed the develop-tests-core-type-array branch from 6f15f61 to d84f302 Compare October 12, 2026 00:26
….Array`. Refs Copilot-Language#767.

The module `copilot-core:Copilot.Core.Type.Array` achieves less than full
coverage in the two of the three main categories used by `hpc`, namely "Top
Level Definitions" and "Expressions". For the former, only 4 out of 6
definitions are covered, and for the latter, only 47 out of 48. To make Copilot
ready for use in future missions, we want to achieve maximum coverage possible.

The lower coverage of "Expressions" is due to a `Proxy` value not being forced
in a call to `natVal`, which only needs the type-level information for the
`Proxy` being provided.

This commit modifies the code of `copilot-core:Copilot.Core.Type.Array` to
force the evaluation of a `Proxy` value being passed to `natVal`. Specifically,
it uses `($!)`, which achieves the evaluation of the value at the point where
it is being used, making `hpc` mark it as evaluated. Other alternatives (e.g.,
use of `seq`, use of `Proxy#`) either do not achieve the desired effect or
require more extensive changes and the use of language extensions.
…Refs Copilot-Language#767.

The module `copilot-core:Copilot.Core.Type.Array` achieves less than full
coverage in the two of the three main categories used by `hpc`, namely "Top
Level Definitions" and "Expressions". For the former, only 4 out of 6
definitions are covered, and for the latter, only 47 out of 48. To make Copilot
ready for use in future missions, we want to achieve maximum coverage possible.

The module `copilot-core:Copilot.Core.Type.Array` includes an instance of the
class `Show` for the type `Array`. That instance implicitly declares `showList`
and `showsPrec`, set to their default values per the class definition. However,
there is no guarantee that the definitions are correct for this specific
instance, and `hpc` marks them as not covered unless we explicitly test them,
affecting the "Top Level Definitions" score for this library.

This commit adds two tests for functions that are implicitly set to their
default definitions in the `Show` instance for `Array`.
@ivanperez-keera
ivanperez-keera force-pushed the develop-tests-core-type-array branch from d84f302 to 34cc907 Compare October 12, 2026 00:54
@ivanperez-keera

Copy link
Copy Markdown
Member Author

Change Manager: Verified that:

  • Solution is implemented:
    • The code proposed compiles and passes all tests. Details:
      Build log: https://app.travis-ci.com/github/Copilot-Language/copilot/builds/278972667
    • The solution proposed produces the expected result. Details:
      The following Dockerfile tests copilot-core with coverage enabled; generates the hpc report for the specific module Copilot.Core.Type.Array, and compares the covered items from the main hpc categories to the total items to ensure full coverage, after which it prints the message "Success":
      --- Dockerfile-verify-767
      FROM ubuntu:jammy
      
      WORKDIR /root
      SHELL ["/bin/bash", "-c"]
      
      ENV DEBIAN_FRONTEND=noninteractive
      RUN apt-get update
      
      RUN apt-get install --yes \
            bc \
            curl \
            g++ \
            gcc \
            git \
            libgmp3-dev  \
            libz-dev \
            make \
            pkg-config \
            z3
      
      RUN mkdir -p $HOME/.ghcup/bin
      RUN curl https://downloads.haskell.org/~ghcup/0.1.40.0/x86_64-linux-ghcup-0.1.40.0 -o $HOME/.ghcup/bin/ghcup
      RUN chmod a+x $HOME/.ghcup/bin/ghcup
      ENV PATH=$PATH:/root/.ghcup/bin/
      ENV PATH=$PATH:/root/.cabal/bin/
      
      RUN ghcup install ghc 9.10.1
      RUN ghcup install cabal 3.2
      RUN ghcup set ghc 9.10.1
      RUN cabal user-config init
      RUN sed -i -e "s;-- \(secure.\) True;\1 False;g" /root/.cabal/config
      RUN cabal update
      
      ARG GIT_COMMIT=HEAD
      ARG NAME=copilot
      ARG REPO=https://github.com/copilot-language/copilot
      
      RUN git clone ${REPO} ${NAME}
      RUN cd ${NAME} && git checkout ${GIT_COMMIT}
      
      WORKDIR ${NAME}
      
      RUN cabal v1-sandbox init
      RUN cabal v1-install alex happy
      
      WORKDIR copilot-core
      RUN cabal v1-sandbox init --sandbox=$PWD/../.cabal-sandbox/
      
      RUN cabal v1-install --enable-tests --only-dependencies
      RUN cabal v1-configure --enable-library-coverage
      RUN cabal v1-test
      RUN VERSION="$(grep -e '^version:' copilot-core.cabal | grep -oe '[[:digit:]].*')" && \
          hpc report unit-tests.tix --include='Copilot.Core.Type.Array' $(find dist -type d -name "mix" -exec echo --hpcdir={}/copilot-core-$VERSION \;) > output
      RUN grep -e 'used' output | grep -oe '[[:digit:]]\+/' | grep -oe '[[:digit:]]\+' > covered
      RUN grep -e 'used' output | grep -oe '/[[:digit:]]\+' | grep -oe '[[:digit:]]\+' > total
      RUN [ $(wc -l < covered) -eq 4 ] && diff covered total
      RUN echo "Success"
      Command (substitute variables based on new path after merge):
      $ docker build --build-arg "REPO=https://github.com/ivanperez-keera/copilot" --build-arg "NAME=copilot" --build-arg "GIT_COMMIT=34cc90741e8b792d8f55ad7e875a3bdcffe4a122" -t copilot-verify-767 -f Dockerfile-verify-767 .
      
  • Implementation is documented. Details:
    New top-level definitions include documentation.
  • Change history is clear.
  • Commit messages are clear.
  • Changelogs are updated.
  • Examples are updated. Details:
    No updates needed; change is internal and to the tests and does not affect existing examples.
  • Author is internal or has provided signed CLA.
  • Required version bumps are evaluated. Details:
    Bump not needed; change is internal and to the tests and does not affect public API.

@ivanperez-keera
ivanperez-keera merged commit 094316c into Copilot-Language:master Oct 12, 2026
1 check passed
@ivanperez-keera
ivanperez-keera deleted the develop-tests-core-type-array branch October 12, 2026 06:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant