diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index 4fc4fc4..ebb00aa 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -27,4 +27,6 @@ jobs: authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' - name: Build run: nix build + - name: Check + run: nix flake check -L diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 29b6dff..4edbf83 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,6 @@ on: schedule: - cron: '0 1 * * *' - jobs: stable-idris: runs-on: ubuntu-latest @@ -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 @@ -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 diff --git a/.gitignore b/.gitignore index f60b4de..c3c8bd4 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,5 @@ harmony-npm.tar.gz *.idr~ result + +test/**/output diff --git a/Makefile b/Makefile index d6f6ed2..559dd12 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -147,6 +147,9 @@ publish : package install: harmony npm install --global +test: + $(MAKE) -C test test + clean: rm -rf ./depends rm -rf ./build @@ -154,3 +157,4 @@ clean: rm -rf ./harmony-npm rm -f ./harmony rm -f ./harmony-npm.tar.gz + $(MAKE) -C test clean diff --git a/default.nix b/default.nix index 1cb903c..62e00f7 100644 --- a/default.nix +++ b/default.nix @@ -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"; diff --git a/flake.nix b/flake.nix index b35079f..df69fa6 100644 --- a/flake.nix +++ b/flake.nix @@ -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}; diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..6be0ac6 --- /dev/null +++ b/test/Makefile @@ -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 diff --git a/test/Test.idr b/test/Test.idr new file mode 100644 index 0000000..ad96b60 --- /dev/null +++ b/test/Test.idr @@ -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 + ] + diff --git a/test/config-command/cleanup.sh b/test/config-command/cleanup.sh new file mode 100644 index 0000000..4c22f87 --- /dev/null +++ b/test/config-command/cleanup.sh @@ -0,0 +1,2 @@ + +rm ./harmony.json diff --git a/test/config-command/harmony.json b/test/config-command/harmony.json new file mode 100644 index 0000000..322df9a --- /dev/null +++ b/test/config-command/harmony.json @@ -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} \ No newline at end of file diff --git a/test/config-command/no-args/expected b/test/config-command/no-args/expected new file mode 100644 index 0000000..8c0051f --- /dev/null +++ b/test/config-command/no-args/expected @@ -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 `+` 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. diff --git a/test/config-command/no-args/run b/test/config-command/no-args/run new file mode 100644 index 0000000..a83da95 --- /dev/null +++ b/test/config-command/no-args/run @@ -0,0 +1,8 @@ +. ../../setup.sh +. ../setup.sh + +set +e + +$harmony config 2>&1 + +. ../cleanup.sh diff --git a/test/config-command/no-request-warning/expected b/test/config-command/no-request-warning/expected new file mode 100644 index 0000000..fe89ffc --- /dev/null +++ b/test/config-command/no-request-warning/expected @@ -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 `+` 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). + diff --git a/test/config-command/no-request-warning/run b/test/config-command/no-request-warning/run new file mode 100644 index 0000000..e4437d2 --- /dev/null +++ b/test/config-command/no-request-warning/run @@ -0,0 +1,6 @@ +. ../../setup.sh +. ../setup.sh + +${harmony} config requestTeams no + +. ../cleanup.sh diff --git a/test/config-command/read-args/expected b/test/config-command/read-args/expected new file mode 100644 index 0000000..43deed1 --- /dev/null +++ b/test/config-command/read-args/expected @@ -0,0 +1,7 @@ +False +True +at-mention +"origin" +"main" +dark +Not set (will use $GITHUB_PAT environment variable) diff --git a/test/config-command/read-args/run b/test/config-command/read-args/run new file mode 100644 index 0000000..52517f9 --- /dev/null +++ b/test/config-command/read-args/run @@ -0,0 +1,14 @@ +. ../../setup.sh +. ../setup.sh + +keys="requestUsers +requestTeams +commentOnRequest +defaultRemote +mainBranch +theme +githubPAT" + +echo $keys | xargs -n1 ${harmony} config + +. ../cleanup.sh diff --git a/test/config-command/setup.sh b/test/config-command/setup.sh new file mode 100644 index 0000000..9cf5fbc --- /dev/null +++ b/test/config-command/setup.sh @@ -0,0 +1,2 @@ + +cp ../harmony.json ./harmony.json diff --git a/test/config-command/write-args/expected b/test/config-command/write-args/expected new file mode 100644 index 0000000..50a827b --- /dev/null +++ b/test/config-command/write-args/expected @@ -0,0 +1,7 @@ +True +False +name +"upstream" +"root" +light +xxxxxxxx (hidden) diff --git a/test/config-command/write-args/run b/test/config-command/write-args/run new file mode 100644 index 0000000..7c069d3 --- /dev/null +++ b/test/config-command/write-args/run @@ -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 diff --git a/test/harmony-tests.ipkg b/test/harmony-tests.ipkg new file mode 100644 index 0000000..77b5a15 --- /dev/null +++ b/test/harmony-tests.ipkg @@ -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 = diff --git a/test/expected_help.txt b/test/help-command/expected similarity index 100% rename from test/expected_help.txt rename to test/help-command/expected diff --git a/test/help-command/run b/test/help-command/run new file mode 100644 index 0000000..b160aff --- /dev/null +++ b/test/help-command/run @@ -0,0 +1,3 @@ +. ../setup.sh + +$harmony help diff --git a/test/setup.sh b/test/setup.sh new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/test/setup.sh @@ -0,0 +1 @@ +