Skip to content
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

Tests #140

Merged
merged 13 commits into from
Jul 7, 2024
Merged

Tests #140

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: 2 additions & 0 deletions .github/workflows/nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ jobs:
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: Build
run: nix build
- name: Check
run: nix flake check -L

19 changes: 6 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ on:
schedule:
- cron: '0 1 * * *'


jobs:
stable-idris:
runs-on: ubuntu-latest
Expand All @@ -28,12 +27,9 @@ jobs:
idris2 --version
echo ''
make
- name: Check Executable
run: |
./harmony help > output.txt
git diff --no-index -- test/expected_help.txt output.txt
# - name: Test
# run: make test
- name: Test
shell: bash
run: INTERACTIVE='' make test

nightly-idris:
runs-on: ubuntu-latest
Expand All @@ -52,10 +48,7 @@ jobs:
idris2 --version
echo ''
make
- name: Check Executable
run: |
./harmony help > output.txt
git diff --no-index -- test/expected_help.txt output.txt
# - name: Test
# run: make test
- name: Test
shell: bash
run: INTERACTIVE='' make test

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ harmony-npm.tar.gz
*.idr~

result

test/**/output
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ else
ised = sed -I ''
endif

.PHONY: all build nix-build install package publish clean version
.PHONY: all build test nix-build install package publish clean version

all: build

Expand Down Expand Up @@ -147,10 +147,14 @@ publish : package
install: harmony
npm install --global

test:
$(MAKE) -C test test

clean:
rm -rf ./depends
rm -rf ./build
rm -rf ./node_modules
rm -rf ./harmony-npm
rm -f ./harmony
rm -f ./harmony-npm.tar.gz
$(MAKE) -C test clean
5 changes: 5 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@
--zsh <($out/bin/harmony --zsh-completion-script) \
'';

installCheckPhase = ''
export harmony=$out/bin/harmony
INTERACTIVE="" make test
'';

meta = with lib; {
description = "Harmony GitHub collaboration tool";
homepage = "https://github.com/mattpolzin/harmony";
Expand Down
7 changes: 7 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
default = self.packages.${system}.harmony;
}
);
checks = forAllSystems (
system: let
harmony = self.packages.${system}.harmony;
in {
tests = harmony.overrideAttrs { doInstallCheck = true; };
}
);
devShells = forAllSystems (
system: let
pkgs = nixpkgs.legacyPackages.${system};
Expand Down
19 changes: 19 additions & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

PWD = $(shell pwd)
harmony ?= $(shell realpath "${PWD}/../harmony")

.PHONY: test clean

INTERACTIVE ?= "--interactive"

IDR_SOURCES := $(wildcard *.idr)

build/exec/test: $(IDR_SOURCES)
idris2 --build harmony-tests.ipkg

export harmony
test: build/exec/test
build/exec/test runtests $(INTERACTIVE)

clean:
rm -rf ./test/build
64 changes: 64 additions & 0 deletions test/Test.idr
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
module Test

import Data.SnocList
import Data.String
import Test.Golden
import System.File
import System

%default total

splitOn : (sbustr : String) -> String -> Maybe (String, String)
splitOn substr str =
let sub = unpack substr
in mapHom pack <$> go sub sub [<] [<] (unpack str)
where
go : (fullSubstr : List Char) -> (remainingToMatch : List Char) -> (beforeMatch : SnocList Char) -> (throughMatch : SnocList Char) -> List Char -> Maybe (List Char, List Char)
go fullSubstr [] beforeMatch throughMatch cs = Just (cast beforeMatch, cs)
go fullSubstr (x :: xs) beforeMatch throughMatch [] = Nothing
go fullSubstr (x :: xs) beforeMatch throughMatch (y :: ys) =
if x == y
then go fullSubstr xs beforeMatch (throughMatch :< y) ys
else go fullSubstr fullSubstr (throughMatch :< y) (throughMatch :< y) ys

req : List Requirement
req = []

mkTests : List String -> TestPool
mkTests = MkTestPool "Misc"
req
Nothing

misc : TestPool
misc = mkTests
[ "help-command"
]

configTests : IO TestPool
configTests = testsInDir "config-command" "Config Command"

||| We want to avoid Harmony performing a sync as part of tests that read the
||| test configuration file so we mark the configuration file as updated.
covering
markConfigsAsUpdated : IO ()
markConfigsAsUpdated = do
Right config <- readFile "./config-command/harmony.json"
| Left e => die (show e)
let Just (before, after) = splitOn #""updatedAt":"# config
| Nothing => die "could not update config timestamp"
let (_, rest) = break (\c => c == ',' || c == '}') after
let ts = show !time
let config' = before ++ "\"updatedAt\":" ++ ts ++ rest
Right _ <- writeFile "./config-command/harmony.json" config'
| Left e => die (show e)
pure ()

covering
main : IO ()
main = do
markConfigsAsUpdated
runner
[ misc
, !configTests
]

2 changes: 2 additions & 0 deletions test/config-command/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

rm ./harmony.json
1 change: 1 addition & 0 deletions test/config-command/harmony.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"requestTeams":true,"requestUsers":false,"commentOnRequest":"at-mention","org":"mattpolzin","repo":"harmony","defaultRemote":"origin","mainBranch":"main","theme":"dark","orgMembers":[],"teamSlugs":[],"repoLabels":["WIP","bug","documentation","duplicate","enhancement","good first issue","help wanted","invalid","question","wontfix"],"ignoredPRs":[],"githubPAT":null,"updatedAt":1720239789}
9 changes: 9 additions & 0 deletions test/config-command/no-args/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The config command expects one or two arguments. Specify a property to read it out or specify both a property and a value to set it to.

requestTeams: [true/false] Determines whether or not to request reviews from teams when requesting individual reviewers from a team.
requestUsers: [true/false] Determines whether or not to request reviews from an individual user based on Harmony's heuristics when requestin review from teams. You might want to disable `requestUsers` to allow GitHub to pick users to request based on the team. This setting does not affect the ability to request reviews from individual users withe Harmony's `+<username>` syntax.
commentOnRequest: [none/name/at-mention] Determines whether- and how to comment on PR indicating that Harmony chose a reviewer.
defaultRemote: [string] The name of the default Git remote to use (e.g. 'origin').
mainBranch: [string] The name of the default Git base branch for new PRs.
theme: [dark/light]
githubPAT: [string] The Personal Access Token Harmony should use to authenticate with GitHub. You can leave this unset if you want to set a PAT via the GITHUB_PAT environment variable.
8 changes: 8 additions & 0 deletions test/config-command/no-args/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
. ../../setup.sh
. ../setup.sh

set +e

$harmony config 2>&1

. ../cleanup.sh
2 changes: 2 additions & 0 deletions test/config-command/no-request-warning/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
`requestUsers` and `requestTeams` are both False. This means `harmony request` commands will only ever request reviews from users that are specified with the `+<userlogin>` syntax. More commonly, you want Harmony to at least request review for either a team or a user from a team when you say `harmony request teamname`; It's suggested to either `harmony config requestUsers true` or `harmony config requestTeams true` (or both).

6 changes: 6 additions & 0 deletions test/config-command/no-request-warning/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
. ../../setup.sh
. ../setup.sh

${harmony} config requestTeams no

. ../cleanup.sh
7 changes: 7 additions & 0 deletions test/config-command/read-args/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
False
True
at-mention
"origin"
"main"
dark
Not set (will use $GITHUB_PAT environment variable)
14 changes: 14 additions & 0 deletions test/config-command/read-args/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
. ../../setup.sh
. ../setup.sh

keys="requestUsers
requestTeams
commentOnRequest
defaultRemote
mainBranch
theme
githubPAT"

echo $keys | xargs -n1 ${harmony} config

. ../cleanup.sh
2 changes: 2 additions & 0 deletions test/config-command/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

cp ../harmony.json ./harmony.json
7 changes: 7 additions & 0 deletions test/config-command/write-args/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
True
False
name
"upstream"
"root"
light
xxxxxxxx (hidden)
25 changes: 25 additions & 0 deletions test/config-command/write-args/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
. ../../setup.sh
. ../setup.sh

${harmony} config requestUsers yes
${harmony} config requestUsers

${harmony} config requestTeams no
${harmony} config requestTeams

${harmony} config commentOnRequest name
${harmony} config commentOnRequest

${harmony} config defaultRemote upstream
${harmony} config defaultRemote

${harmony} config mainBranch root
${harmony} config mainBranch

${harmony} config theme light
${harmony} config theme

${harmony} config githubPAT 1234ABCD
${harmony} config githubPAT

. ../cleanup.sh
47 changes: 47 additions & 0 deletions test/harmony-tests.ipkg
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package harmony-tests
-- version =
authors = "Mathew Polzin"
-- maintainers =
-- license =
-- brief =
-- readme =
-- homepage =
-- sourceloc =
-- bugtracker =

-- the Idris2 version required (e.g. langversion >= 0.5.1)
-- langversion

-- packages to add to search path
depends = test

-- modules to install
-- modules =

-- main file (i.e. file to load at REPL)
main = Test

-- name of executable
executable = test
-- opts =
-- sourcedir =
-- builddir =
-- outputdir =

-- script to run before building
-- prebuild =

-- script to run after building
-- postbuild =

-- script to run after building, before installing
-- preinstall =

-- script to run after installing
-- postinstall =

-- script to run before cleaning
-- preclean =

-- script to run after cleaning
-- postclean =
File renamed without changes.
3 changes: 3 additions & 0 deletions test/help-command/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
. ../setup.sh

$harmony help
1 change: 1 addition & 0 deletions test/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading