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

test suite #126

Merged
merged 70 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
a7ddb18
add some ignored things
cdmistman Sep 8, 2023
561a9d4
use go 1.20
cdmistman Sep 8, 2023
7d84029
go mod tidy
cdmistman Sep 8, 2023
b6eda31
fix deprecated stdlib APIs from minor version releases cause thats to…
cdmistman Sep 8, 2023
23fb31a
fix deprecated flake output
cdmistman Sep 8, 2023
83f56db
here wigo
cdmistman Sep 22, 2023
08b849f
full nodejs which-language testing
cdmistman Sep 22, 2023
566fe49
more tests
cdmistman Sep 22, 2023
0030043
another test, cleanup
cdmistman Sep 22, 2023
582f469
move some things around, fix some fails
cdmistman Sep 22, 2023
ca8d934
fix testremove logic
cdmistman Sep 22, 2023
26f373c
test guessing
cdmistman Sep 23, 2023
4ec1e89
better test layout
cdmistman Sep 23, 2023
28c0a1f
better search testing
cdmistman Sep 23, 2023
b2517d5
better info testing
cdmistman Sep 23, 2023
4a6f3b7
better add testing
cdmistman Sep 25, 2023
5ee3957
better remove testing
cdmistman Sep 25, 2023
66dfac9
better lock testing
cdmistman Sep 25, 2023
d314465
better install testing
cdmistman Sep 25, 2023
475cebe
better list testing
cdmistman Sep 25, 2023
086adac
better guess testing
cdmistman Sep 25, 2023
eafb537
Merge branch 'main' of github.com:replit/upm into cad/test-suite
cdmistman Oct 2, 2023
9d477be
add package managers to devshell for testing
cdmistman Oct 2, 2023
ec9eb4c
exclude test suite from upm src
cdmistman Oct 2, 2023
4cd86c2
skip test suites that dont have tests
cdmistman Oct 2, 2023
2e6c041
cleanup
cdmistman Oct 3, 2023
9f5f131
add test-suite to ci
cdmistman Oct 3, 2023
69ffccc
add nix to test-suite task
cdmistman Oct 3, 2023
1bdfdb4
share nix store, run make generated
cdmistman Oct 3, 2023
96f78aa
fix dependencies list i think
cdmistman Oct 3, 2023
baebb7e
bleh
cdmistman Oct 3, 2023
74f2e16
dont go run statik just run statik
cdmistman Oct 3, 2023
6f17179
i really hope directly invoking statik in the makefile works
cdmistman Oct 3, 2023
c63816a
remove statik
cdmistman Oct 6, 2023
7110f38
fix vendorhash
cdmistman Oct 6, 2023
efaa523
embed.FS has different expectations to statik.FS
cdmistman Oct 6, 2023
a16644c
lint
cdmistman Oct 6, 2023
38b4396
fix statik->embed paths
cdmistman Oct 6, 2023
7b7a5de
Merge branch 'cad/remove-statik' of github.com:replit/upm into cad/te…
cdmistman Oct 6, 2023
7c6b626
get rid of statik
cdmistman Oct 10, 2023
6ecc2ad
tweak semaphore test task
cdmistman Oct 10, 2023
4492cec
try with self-hosted agent
cdmistman Oct 10, 2023
94ab269
remove some stuff from ci
cdmistman Oct 10, 2023
43961ab
oops
cdmistman Oct 10, 2023
7a563cb
use nix container image
cdmistman Oct 10, 2023
999057c
oops
cdmistman Oct 10, 2023
7457ba1
change image pull secret
cdmistman Oct 10, 2023
c2bb97d
try this instead
cdmistman Oct 10, 2023
07bdd33
use just self-hosted
cdmistman Oct 12, 2023
dff1d5a
install_nix script
cdmistman Oct 12, 2023
f93384a
forgot to source nix
cdmistman Oct 12, 2023
9cf6129
forgot i dont need the brackets
cdmistman Oct 12, 2023
8e7a54c
set semaphore cache backend
cdmistman Oct 12, 2023
21c7cb6
set cache gcs bucket
cdmistman Oct 12, 2023
12b2e60
nocache
cdmistman Oct 12, 2023
8a8826a
make script more debuggable
cdmistman Oct 12, 2023
c5b656c
source the install_nix script
cdmistman Oct 12, 2023
8c30b5b
publish test results
cdmistman Oct 12, 2023
1991251
go get gotestsum first
cdmistman Oct 12, 2023
16f03a5
try inline nix develop/shell
cdmistman Oct 12, 2023
0b232e1
use makefile for the tests
cdmistman Oct 12, 2023
bf1023e
fix golangci-lint invocation
cdmistman Oct 12, 2023
32e7c30
fix lint
cdmistman Oct 12, 2023
8b69a8d
remove backend tests
cdmistman Oct 12, 2023
4f3e548
Merge branch 'main' into cad/test-suite
cdmistman Oct 12, 2023
a842f33
cleanup
cdmistman Oct 12, 2023
6290c1b
allowlist for upm derivation instead of blocklist
cdmistman Oct 12, 2023
0579a3a
go back to blocklist
cdmistman Oct 13, 2023
3ce2c34
add test-suite command for local dev
cdmistman Oct 13, 2023
37738f9
fix expected string
cdmistman Oct 13, 2023
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/cmd/upm/upm
/dist/
/internal/statik/
/packaging/aur/*.tar.gz
/packaging/aur/*.tar.xz
/packaging/aur/pkg/
Expand Down
20 changes: 20 additions & 0 deletions .semaphore/install_nix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env sh

set -e
set -o xtrace

install_script_cache_key="install-nix-2.16.1"
install_script="/tmp/$install_script_cache_key"

# Install Nix. Install the base version if the currently installed version is
# not what we expect.
if [ \
! -f ~/.nix-profile/etc/profile.d/nix.sh -o \
"$(~/.nix-profile/bin/nix --version)" != "nix (Nix) 2.16.1" \
]; then
curl -L https://releases.nixos.org/nix/nix-2.16.1/install | sh
fi

source ~/.nix-profile/etc/profile.d/nix.sh

set +e
116 changes: 22 additions & 94 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,121 +3,49 @@ version: v1.0
name: UPM
agent:
machine:
type: e1-standard-2
os_image: ubuntu2004
type: s1-goval

global_job_config:
env_vars:
- name: UPM_CI
value: "1"
prologue:
commands:
- checkout
- git switch --detach
- export PATH="/tmp:$PATH"
- source ./.semaphore/install_nix.sh

blocks:
- name: setup
dependencies: []
task:
jobs:
- name: cache nix installer
commands:
- >-
cache has_key nix-installer || (
curl
--proto '=https'
-o /tmp/nix-installer
--tlsv1.2 -sSf -L
https://github.com/DeterminateSystems/nix-installer/releases/download/v0.7.0/nix-installer-x86_64-linux
&& chmod +x /tmp/nix-installer
&& cache store nix-installer /tmp/nix-installer
)
# TODO: cache the dependencies of the nix package
# this might be possible based on exploratory:
# ```
# $ DERIVATION="$(nix path-info --derivation .)"
# $ declare -p DERIVATION
# $ nix-store --query --references "${DERIVATION}"
# ```
# The above spits out the deps of the derivation
# just have to filter out the `-source`
- name: cache golint-ci
commands:
- >-
cache has_key golangci-lint || (
mkdir -p bin &&
curl
-sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh
| sh -s -- -b /tmp v1.52.2
&& cache store golangci-lint /tmp/golangci-lint
)

- name: build
dependencies: [ setup ]
dependencies: [ ]
task:
prologue:
commands:
- cache restore nix-installer
- sudo /tmp/nix-installer install linux --no-confirm --logger compact
- . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
jobs:
- name: nix
commands:
- cache restore nix-store
- nix build
- ./result/bin/upm --version
- cache store nix-store /nix
# TODO: get this working again
# - name: docker
# commands:
# - make light full

- name: lint
dependencies: [ setup ]

- name: test
dependencies: [ build ]
task:
jobs:
- name: golang lint
- name: test-suite
commands:
- make generated
- cache restore golangci-lint
- golangci-lint run
- nix develop -c nix shell -c make test-suite
epilogue:
commands:
- test-results publish junit.xml

- name: release
dependencies: [ build, lint ]
run:
# git tag can be eg 'v1.0', 'v1.0.1', 'v1.0-alpha', or 'v1.0-alpha-4'
when: "tag =~ 'v[0-9]+\.[0-9]+(\.[0-9]+)?(-.*)*'"
- name: lint
dependencies: [ ]
task:
prologue:
commands:
- cache restore dist
jobs:
- name: goreleaser
- name: golang lint
commands:
- make generated
- cache restore golangci-lint
- >-
cache has_key goreleaser || (
curl
--proto '=https'
-o /tmp/goreleaser
-sL https://git.io/goreleaser
&& chmod +x /tmp/goreleaser
&& cache store goreleaser /tmp/goreleaser
)
- cache restore goreleaser
- goreleaser --release-notes=<(scripts/extract-changelog.py)
# - name: snapcraft
# commands:
# - >-
# snapcraft login --with <(
# echo "$SNAPCRAFT_LOGIN_FILE" |
# base64 --decode --ignore-garbage
# )
# - scripts/upload-snap.bash
# - name: deploy
# commands:
# - >-
# echo "$DOCKER_PASSWORD" |
# docker login
# --username "$DOCKER_USERNAME"
# --password-stdin
# - make deploy
# - |
# git tag "semaphoreci_pipeline_"
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh
| sh -s -- -b /tmp v1.52.2
- /tmp/golangci-lint run
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,13 @@ help: ## Show this message
.PHONY: test
test:
go test ./... -v

.PHONY: test-suite
ifdef UPM_CI
test-suite:
go get gotest.tools/gotestsum
go run gotest.tools/gotestsum --junitfile ./junit.xml ./test-suite
else
test-suite:
nix develop -c nix shell -c go test ./test-suite
endif
2 changes: 1 addition & 1 deletion internal/backends/backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var languageBackends = []api.LanguageBackend{
python.Python2Backend,
nodejs.BunBackend,
nodejs.NodejsNPMBackend,
nodejs.NodejsPNPMBackend,
nodejs.NodejsPNPMBackend,
nodejs.NodejsYarnBackend,
ruby.RubyBackend,
elisp.ElispBackend,
Expand Down
7 changes: 7 additions & 0 deletions nix/devshell/default.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
{
bun,
go,
mkShell,
nodejs,
nodePackages,
}:
mkShell {
name = "upm";
packages = [
bun
go
nodejs
nodePackages.pnpm
nodePackages.yarn
];
}
17 changes: 15 additions & 2 deletions nix/upm/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,24 @@
rev,
makeWrapper,
}:
buildGoModule {
buildGoModule rec {
pname = "upm";
version = rev;

src = ../../.;
src = builtins.path {
name = "${pname}-${version}-src";
path = ../../.;
filter = path: _: builtins.all (block: (builtins.baseNameOf path) != block) [
".github"
".semaphore"
"packaging"
"scripts"
"test-suite"
".goreleaser.yml"
".replit"
"replit.nix"
];
};

vendorHash = "sha256-2F2/BcHUEpbYxmAW1SsIBbn6U2VWinWjdxMvsbzfKsc=";

Expand Down
65 changes: 65 additions & 0 deletions test-suite/Add_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package testSuite

import (
"testing"

testUtils "github.com/replit/upm/test-suite/utils"
)

func TestAdd(t *testing.T) {
for _, bt := range languageBackends {
bt.Start(t)

var pkgs []string
switch bt.Backend.Name {
default:
t.Run(bt.Backend.Name, func(t *testing.T) {
t.Skip("no test")
})
continue
}
ryantm marked this conversation as resolved.
Show resolved Hide resolved

bt.Subtest(bt.Backend.Name, func(bt testUtils.BackendT) {
doAdd(bt, pkgs...)
})
}
}

func doAdd(bt testUtils.BackendT, pkgs ...string) {
for _, tmpl := range standardTemplates {
template := bt.Backend.Name + "/" + tmpl + "/"
bt.Subtest(tmpl, func(bt testUtils.BackendT) {
if tmpl != "no-deps" {
bt.Subtest("locked", func(bt testUtils.BackendT) {
bt.Subtest("each", func(bt testUtils.BackendT) {
bt.AddTestFile(template+bt.Backend.Specfile, bt.Backend.Specfile)
bt.AddTestFile(template+bt.Backend.Lockfile, bt.Backend.Lockfile)
for _, pkg := range pkgs {
bt.UpmAdd(pkg)
}
})

bt.Subtest("all", func(bt testUtils.BackendT) {
bt.AddTestFile(template+bt.Backend.Specfile, bt.Backend.Specfile)
bt.AddTestFile(template+bt.Backend.Lockfile, bt.Backend.Lockfile)
bt.UpmAdd(pkgs...)
})
})
}

bt.Subtest("unlocked", func(bt testUtils.BackendT) {
bt.Subtest("each", func(bt testUtils.BackendT) {
bt.AddTestFile(template+bt.Backend.Specfile, bt.Backend.Specfile)
for _, pkg := range pkgs {
bt.UpmAdd(pkg)
}
})

bt.Subtest("all", func(bt testUtils.BackendT) {
bt.AddTestFile(template+bt.Backend.Specfile, bt.Backend.Specfile)
bt.UpmAdd(pkgs...)
})
})
})
}
}
67 changes: 67 additions & 0 deletions test-suite/Guess_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package testSuite

import (
"io"
"strings"
"testing"

"github.com/replit/upm/test-suite/templates"
testUtils "github.com/replit/upm/test-suite/utils"
)

func TestGuess(t *testing.T) {
for _, bt := range languageBackends {
bt.Start(t)

tests := make(map[string]map[string][]string)
switch bt.Backend.Name {
default:
t.Run(bt.Backend.Name, func(t *testing.T) {
t.Skip("no test")
})
continue
}

for ext, guessSuites := range tests {
bt.Subtest(ext, func(bt testUtils.BackendT) {
for template, tests := range guessSuites {
bt.Subtest(template, func(bt testUtils.BackendT) {
for _, test := range tests {
testSrcFile := "guess/" + template + "/" + test

bt.Subtest(test, func(bt testUtils.BackendT) {
bt.AddTestFile(testSrcFile, test+"."+ext)
bt.AddTestFile(bt.Backend.Name+"/no-deps/"+bt.Backend.Specfile, bt.Backend.Specfile)

expectFile, err := templates.FS.Open(testSrcFile + ".expect")
if err != nil {
bt.Fail("No expect file found for %s: %v", testSrcFile, err)
}

var expectsText strings.Builder
_, err = io.Copy(&expectsText, expectFile)
if err != nil {
bt.Fail("Failed to read expect file for %s: %v", testSrcFile, err)
}

expects := strings.Split(strings.TrimSpace(expectsText.String()), "\n")

bt.UpmGuess(expects...)
})
}
})
}
})
}
}
}

var js = []string{
"basic",
"dedup",
"nested",
}

var ts = []string{
"typeImports",
}
Loading