treewide: migrate to gensokyo.uk/nix
This commit is contained in:
parent
92ac3275c1
commit
fdc969afb6
2
build.go
2
build.go
@ -1,4 +1,4 @@
|
|||||||
package nixbuild
|
package nix
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package nixbuild_test
|
package nix_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@ -9,7 +9,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.gensokyo.uk/yonah/nixbuild"
|
"gensokyo.uk/nix"
|
||||||
"hakurei.app/command"
|
"hakurei.app/command"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -23,14 +23,14 @@ func init() {
|
|||||||
flagBuildPBL bool
|
flagBuildPBL bool
|
||||||
flagBuildVerbose bool
|
flagBuildVerbose bool
|
||||||
)
|
)
|
||||||
c.NewCommand(nixbuild.CommandBuild, "emit samples for various `nix build` cases", func(args []string) error {
|
c.NewCommand(nix.CommandBuild, "emit samples for various `nix build` cases", func(args []string) error {
|
||||||
switch {
|
switch {
|
||||||
default:
|
default:
|
||||||
return os.ErrInvalid
|
return os.ErrInvalid
|
||||||
|
|
||||||
case len(args) == 7 && slices.Equal(args[1:], []string{
|
case len(args) == 7 && slices.Equal(args[1:], []string{
|
||||||
nixbuild.FlagOption, nixbuild.OptionEvalCache, nixbuild.ValueFalse,
|
nix.FlagOption, nix.OptionEvalCache, nix.ValueFalse,
|
||||||
nixbuild.FlagDryRun, nixbuild.FlagPrintBuildLogs, nixbuild.FlagDebug,
|
nix.FlagDryRun, nix.FlagPrintBuildLogs, nix.FlagDebug,
|
||||||
}): // InstantiatedEvaluator
|
}): // InstantiatedEvaluator
|
||||||
return stubInstantiatedEvaluator(args)
|
return stubInstantiatedEvaluator(args)
|
||||||
|
|
||||||
@ -53,12 +53,12 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).
|
}).
|
||||||
Flag(&flagBuildKeepGoing, trimFlagName(nixbuild.FlagKeepGoing), command.BoolFlag(false), nixbuild.FlagKeepGoing).
|
Flag(&flagBuildKeepGoing, trimFlagName(nix.FlagKeepGoing), command.BoolFlag(false), nix.FlagKeepGoing).
|
||||||
Flag(&flagBuildNoLink, trimFlagName(nixbuild.FlagNoLink), command.BoolFlag(false), nixbuild.FlagNoLink).
|
Flag(&flagBuildNoLink, trimFlagName(nix.FlagNoLink), command.BoolFlag(false), nix.FlagNoLink).
|
||||||
Flag(&flagBuildStdin, trimFlagName(nixbuild.FlagStdin), command.BoolFlag(false), nixbuild.FlagStdin).
|
Flag(&flagBuildStdin, trimFlagName(nix.FlagStdin), command.BoolFlag(false), nix.FlagStdin).
|
||||||
Flag(&flagBuildQuiet, trimFlagName(nixbuild.FlagQuiet), command.BoolFlag(false), nixbuild.FlagQuiet).
|
Flag(&flagBuildQuiet, trimFlagName(nix.FlagQuiet), command.BoolFlag(false), nix.FlagQuiet).
|
||||||
Flag(&flagBuildPBL, trimFlagName(nixbuild.FlagPrintBuildLogs), command.BoolFlag(false), nixbuild.FlagPrintBuildLogs).
|
Flag(&flagBuildPBL, trimFlagName(nix.FlagPrintBuildLogs), command.BoolFlag(false), nix.FlagPrintBuildLogs).
|
||||||
Flag(&flagBuildVerbose, trimFlagName(nixbuild.FlagVerbose), command.BoolFlag(false), nixbuild.FlagVerbose)
|
Flag(&flagBuildVerbose, trimFlagName(nix.FlagVerbose), command.BoolFlag(false), nix.FlagVerbose)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ func TestBuild(t *testing.T) {
|
|||||||
stubNixCommand(t)
|
stubNixCommand(t)
|
||||||
check := func(stdout, stderr io.Writer, v ...string) {
|
check := func(stdout, stderr io.Writer, v ...string) {
|
||||||
t.Run(strings.Join(v, " "), func(t *testing.T) {
|
t.Run(strings.Join(v, " "), func(t *testing.T) {
|
||||||
if err := nixbuild.Build(
|
if err := nix.Build(
|
||||||
newStubContext(t.Context(), nil, stdout, stderr),
|
newStubContext(t.Context(), nil, stdout, stderr),
|
||||||
slices.Values(v),
|
slices.Values(v),
|
||||||
); err != nil {
|
); err != nil {
|
||||||
@ -84,8 +84,8 @@ func TestBuild(t *testing.T) {
|
|||||||
func TestBuildBadCommand(t *testing.T) {
|
func TestBuildBadCommand(t *testing.T) {
|
||||||
wantErr := os.ErrNotExist
|
wantErr := os.ErrNotExist
|
||||||
breakNixCommand(t)
|
breakNixCommand(t)
|
||||||
if err := nixbuild.Build(
|
if err := nix.Build(
|
||||||
nixbuild.New(t.Context(), nil, nil, nil),
|
nix.New(t.Context(), nil, nil, nil),
|
||||||
nil,
|
nil,
|
||||||
); !errors.Is(err, wantErr) {
|
); !errors.Is(err, wantErr) {
|
||||||
t.Errorf("Build: error = %v, want %v", err, wantErr)
|
t.Errorf("Build: error = %v, want %v", err, wantErr)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package nixbuild
|
package nix
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package nixbuild
|
package nix
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package nixbuild_test
|
package nix_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@ -9,13 +9,13 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.gensokyo.uk/yonah/nixbuild"
|
"gensokyo.uk/nix"
|
||||||
"hakurei.app/command"
|
"hakurei.app/command"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
stubCommandInit = append(stubCommandInit, func(c command.Command) {
|
stubCommandInit = append(stubCommandInit, func(c command.Command) {
|
||||||
c.NewCommand(nixbuild.CommandDerivation, "emit samples for various `nix derivation` cases", func(args []string) error {
|
c.NewCommand(nix.CommandDerivation, "emit samples for various `nix derivation` cases", func(args []string) error {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return syscall.ENOSYS
|
return syscall.ENOSYS
|
||||||
}
|
}
|
||||||
@ -24,7 +24,7 @@ func init() {
|
|||||||
default:
|
default:
|
||||||
return syscall.EINVAL
|
return syscall.EINVAL
|
||||||
|
|
||||||
case nixbuild.CommandDerivationShow:
|
case nix.CommandDerivationShow:
|
||||||
if len(args) != 2 {
|
if len(args) != 2 {
|
||||||
return syscall.ENOSYS
|
return syscall.ENOSYS
|
||||||
}
|
}
|
||||||
@ -33,9 +33,9 @@ func init() {
|
|||||||
default:
|
default:
|
||||||
return syscall.EINVAL
|
return syscall.EINVAL
|
||||||
|
|
||||||
case nixbuild.FlagStdin:
|
case nix.FlagStdin:
|
||||||
var testName string
|
var testName string
|
||||||
if want, err := nixbuild.ReadStdin(os.Stdin); err != nil {
|
if want, err := nix.ReadStdin(os.Stdin); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
for n, w := range instWant {
|
for n, w := range instWant {
|
||||||
@ -72,7 +72,7 @@ func TestDerivationShow(t *testing.T) {
|
|||||||
{"pluiedev pappardelle"},
|
{"pluiedev pappardelle"},
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
got, err := nixbuild.DerivationShow(
|
got, err := nix.DerivationShow(
|
||||||
newStubContext(t.Context(), nil, os.Stdout, os.Stderr),
|
newStubContext(t.Context(), nil, os.Stdout, os.Stderr),
|
||||||
slices.Values(instWant[tc.name]),
|
slices.Values(instWant[tc.name]),
|
||||||
)
|
)
|
||||||
@ -80,7 +80,7 @@ func TestDerivationShow(t *testing.T) {
|
|||||||
t.Fatalf("DerivationShow: error = %v", err)
|
t.Fatalf("DerivationShow: error = %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var want nixbuild.DerivationMap
|
var want nix.DerivationMap
|
||||||
if err = json.Unmarshal(drvShow[tc.name], &want); err != nil {
|
if err = json.Unmarshal(drvShow[tc.name], &want); err != nil {
|
||||||
t.Fatalf("cannot unmarshal: %v", err)
|
t.Fatalf("cannot unmarshal: %v", err)
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ func TestDerivationShow(t *testing.T) {
|
|||||||
|
|
||||||
func TestDerivationShowAlreadySet(t *testing.T) {
|
func TestDerivationShowAlreadySet(t *testing.T) {
|
||||||
stubNixCommand(t)
|
stubNixCommand(t)
|
||||||
if _, err := nixbuild.DerivationShow(
|
if _, err := nix.DerivationShow(
|
||||||
newStubContextCommand(func(cmd *exec.Cmd) { cmd.Stdout = os.Stdout }, t.Context(), nil, os.Stdout, os.Stderr),
|
newStubContextCommand(func(cmd *exec.Cmd) { cmd.Stdout = os.Stdout }, t.Context(), nil, os.Stdout, os.Stderr),
|
||||||
nil,
|
nil,
|
||||||
); err == nil {
|
); err == nil {
|
||||||
@ -102,7 +102,7 @@ func TestDerivationShowAlreadySet(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkShowUnmarshal(b *testing.B) {
|
func BenchmarkShowUnmarshal(b *testing.B) {
|
||||||
var v nixbuild.DerivationMap
|
var v nix.DerivationMap
|
||||||
data := drvShow["pluiedev pappardelle"]
|
data := drvShow["pluiedev pappardelle"]
|
||||||
for b.Loop() {
|
for b.Loop() {
|
||||||
if err := json.Unmarshal(data, &v); err != nil {
|
if err := json.Unmarshal(data, &v); err != nil {
|
||||||
|
2
exec.go
2
exec.go
@ -1,4 +1,4 @@
|
|||||||
package nixbuild
|
package nix
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package nixbuild_test
|
package nix_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@ -8,13 +8,12 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.gensokyo.uk/yonah/nixbuild"
|
"gensokyo.uk/nix"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNixWriteStdin(t *testing.T) {
|
func TestNixWriteStdin(t *testing.T) {
|
||||||
ctx := nixbuild.New(t.Context(), nil, os.Stdout, os.Stderr)
|
|
||||||
|
|
||||||
t.Run("already set", func(t *testing.T) {
|
t.Run("already set", func(t *testing.T) {
|
||||||
|
ctx := nix.New(t.Context(), nil, os.Stdout, os.Stderr)
|
||||||
cmd := exec.CommandContext(t.Context(), "/proc/nonexistent")
|
cmd := exec.CommandContext(t.Context(), "/proc/nonexistent")
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
if _, err := ctx.WriteStdin(cmd, nil, nil); err == nil {
|
if _, err := ctx.WriteStdin(cmd, nil, nil); err == nil {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package nixbuild_test
|
package nix_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@ -7,7 +7,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.gensokyo.uk/yonah/nixbuild"
|
"gensokyo.uk/nix"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestStdin(t *testing.T) {
|
func TestStdin(t *testing.T) {
|
||||||
@ -25,7 +25,7 @@ func TestStdin(t *testing.T) {
|
|||||||
t.Run("write", func(t *testing.T) {
|
t.Run("write", func(t *testing.T) {
|
||||||
w := new(strings.Builder)
|
w := new(strings.Builder)
|
||||||
|
|
||||||
if _, err := nixbuild.WriteStdin(w, slices.Values(tc.col)); err != nil {
|
if _, err := nix.WriteStdin(w, slices.Values(tc.col)); err != nil {
|
||||||
t.Fatalf("cannot write: %v", err)
|
t.Fatalf("cannot write: %v", err)
|
||||||
}
|
}
|
||||||
if w.String() != tc.raw {
|
if w.String() != tc.raw {
|
||||||
@ -35,7 +35,7 @@ func TestStdin(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("read", func(t *testing.T) {
|
t.Run("read", func(t *testing.T) {
|
||||||
r := strings.NewReader(tc.raw)
|
r := strings.NewReader(tc.raw)
|
||||||
got, err := nixbuild.ReadStdin(r)
|
got, err := nix.ReadStdin(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("cannot read: %v", err)
|
t.Fatalf("cannot read: %v", err)
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ func TestStdin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.Run("write error", func(t *testing.T) {
|
t.Run("write error", func(t *testing.T) {
|
||||||
n, err := nixbuild.WriteStdin(errorWriter{}, slices.Values([]string{"/nix/store"}))
|
n, err := nix.WriteStdin(errorWriter{}, slices.Values([]string{"/nix/store"}))
|
||||||
if n != 0 {
|
if n != 0 {
|
||||||
panic("unreachable")
|
panic("unreachable")
|
||||||
}
|
}
|
||||||
@ -65,7 +65,7 @@ func TestInstallable(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
got := nixbuild.NixOSInstallable(tc.flake, tc.host)
|
got := nix.NixOSInstallable(tc.flake, tc.host)
|
||||||
if got != tc.want {
|
if got != tc.want {
|
||||||
t.Errorf("Installable(%q, %q): %q, want %q",
|
t.Errorf("Installable(%q, %q): %q, want %q",
|
||||||
tc.flake, tc.host, got, tc.want)
|
tc.flake, tc.host, got, tc.want)
|
||||||
|
2
go.mod
2
go.mod
@ -1,4 +1,4 @@
|
|||||||
module git.gensokyo.uk/yonah/nixbuild
|
module gensokyo.uk/nix
|
||||||
|
|
||||||
go 1.24.4
|
go 1.24.4
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package nixbuild
|
package nix
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package nixbuild_test
|
package nix_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@ -9,7 +9,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.gensokyo.uk/yonah/nixbuild"
|
"gensokyo.uk/nix"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestInstantiated(t *testing.T) {
|
func TestInstantiated(t *testing.T) {
|
||||||
@ -20,11 +20,11 @@ func TestInstantiated(t *testing.T) {
|
|||||||
want []string
|
want []string
|
||||||
wantErr error
|
wantErr error
|
||||||
}{
|
}{
|
||||||
{"bad fields", nil, &nixbuild.MalformedInstantiatedError{Type: nixbuild.InstantiatedBadFields}},
|
{"bad fields", nil, &nix.MalformedInstantiatedError{Type: nix.InstantiatedBadFields}},
|
||||||
{"unexpected quotes left", nil, &nixbuild.MalformedInstantiatedError{Type: nixbuild.InstantiatedUnexpectedQuotes}},
|
{"unexpected quotes left", nil, &nix.MalformedInstantiatedError{Type: nix.InstantiatedUnexpectedQuotes}},
|
||||||
{"unexpected quotes right", nil, &nixbuild.MalformedInstantiatedError{Type: nixbuild.InstantiatedUnexpectedQuotes}},
|
{"unexpected quotes right", nil, &nix.MalformedInstantiatedError{Type: nix.InstantiatedUnexpectedQuotes}},
|
||||||
{"unexpected quotes short", nil, &nixbuild.MalformedInstantiatedError{Type: nixbuild.InstantiatedUnexpectedQuotes}},
|
{"unexpected quotes short", nil, &nix.MalformedInstantiatedError{Type: nix.InstantiatedUnexpectedQuotes}},
|
||||||
{"not absolute", nil, &nixbuild.MalformedInstantiatedError{Type: nixbuild.InstantiatedNotAbsolute}},
|
{"not absolute", nil, &nix.MalformedInstantiatedError{Type: nix.InstantiatedNotAbsolute}},
|
||||||
|
|
||||||
{"good segment", []string{
|
{"good segment", []string{
|
||||||
"/nix/store/3zilrlmq7r6rpzfd94mwss32b62yinj5-bootstrap-stage0-stdenv-linux.drv",
|
"/nix/store/3zilrlmq7r6rpzfd94mwss32b62yinj5-bootstrap-stage0-stdenv-linux.drv",
|
||||||
@ -49,7 +49,7 @@ func TestInstantiated(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("decoder", func(t *testing.T) {
|
t.Run("decoder", func(t *testing.T) {
|
||||||
out := strings.NewReader(sample)
|
out := strings.NewReader(sample)
|
||||||
decoder := nixbuild.NewInstantiatedDecoder(out, stderr)
|
decoder := nix.NewInstantiatedDecoder(out, stderr)
|
||||||
got, err := decoder.Decode()
|
got, err := decoder.Decode()
|
||||||
if !errors.Is(err, tc.wantErr) {
|
if !errors.Is(err, tc.wantErr) {
|
||||||
t.Fatalf("Decode: error = %v, want %v", err, tc.wantErr)
|
t.Fatalf("Decode: error = %v, want %v", err, tc.wantErr)
|
||||||
@ -71,7 +71,7 @@ func TestInstantiated(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("evaluator", func(t *testing.T) {
|
t.Run("evaluator", func(t *testing.T) {
|
||||||
ctx := newStubContext(t.Context(), nil, os.Stdout, stderr)
|
ctx := newStubContext(t.Context(), nil, os.Stdout, stderr)
|
||||||
got, err := nixbuild.EvalInstantiated(ctx, tc.name)
|
got, err := nix.EvalInstantiated(ctx, tc.name)
|
||||||
if !errors.Is(err, tc.wantErr) {
|
if !errors.Is(err, tc.wantErr) {
|
||||||
t.Fatalf("EvalInstantiated: error = %v, want %v", err, tc.wantErr)
|
t.Fatalf("EvalInstantiated: error = %v, want %v", err, tc.wantErr)
|
||||||
}
|
}
|
||||||
@ -99,7 +99,7 @@ func TestInstantiatedDecoderStopEarly(t *testing.T) {
|
|||||||
"/nix/store/nbsdqpfzh1jlpmh95s69b3iivfcvv3lh-config.sub-948ae97.drv",
|
"/nix/store/nbsdqpfzh1jlpmh95s69b3iivfcvv3lh-config.sub-948ae97.drv",
|
||||||
}
|
}
|
||||||
|
|
||||||
decoder := nixbuild.NewInstantiatedDecoder(strings.NewReader(segmentPrefix+segmentBody+segmentSuffix), os.Stderr)
|
decoder := nix.NewInstantiatedDecoder(strings.NewReader(segmentPrefix+segmentBody+segmentSuffix), os.Stderr)
|
||||||
counter := 3
|
counter := 3
|
||||||
got := make([]string, 0, counter)
|
got := make([]string, 0, counter)
|
||||||
for drv := range decoder.Instantiated() {
|
for drv := range decoder.Instantiated() {
|
||||||
@ -119,8 +119,8 @@ func TestInstantiatedEvaluatorBadCommand(t *testing.T) {
|
|||||||
wantErr := os.ErrNotExist
|
wantErr := os.ErrNotExist
|
||||||
breakNixCommand(t)
|
breakNixCommand(t)
|
||||||
|
|
||||||
if _, err := nixbuild.EvalInstantiated(
|
if _, err := nix.EvalInstantiated(
|
||||||
nixbuild.New(t.Context(), nil, os.Stdout, os.Stderr),
|
nix.New(t.Context(), nil, os.Stdout, os.Stderr),
|
||||||
"",
|
"",
|
||||||
); !errors.Is(err, wantErr) {
|
); !errors.Is(err, wantErr) {
|
||||||
t.Errorf("EvalInstantiated: error = %v, want %v", err, wantErr)
|
t.Errorf("EvalInstantiated: error = %v, want %v", err, wantErr)
|
||||||
@ -129,7 +129,7 @@ func TestInstantiatedEvaluatorBadCommand(t *testing.T) {
|
|||||||
|
|
||||||
func TestInstantiatedEvaluatorAlreadySet(t *testing.T) {
|
func TestInstantiatedEvaluatorAlreadySet(t *testing.T) {
|
||||||
stubNixCommand(t)
|
stubNixCommand(t)
|
||||||
if _, err := nixbuild.EvalInstantiated(
|
if _, err := nix.EvalInstantiated(
|
||||||
newStubContextCommand(func(cmd *exec.Cmd) { cmd.Stderr = os.Stderr }, t.Context(), nil, os.Stdout, os.Stderr),
|
newStubContextCommand(func(cmd *exec.Cmd) { cmd.Stderr = os.Stderr }, t.Context(), nil, os.Stdout, os.Stderr),
|
||||||
"",
|
"",
|
||||||
); err == nil {
|
); err == nil {
|
||||||
@ -140,13 +140,13 @@ func TestInstantiatedEvaluatorAlreadySet(t *testing.T) {
|
|||||||
func TestMalformedInstantiatedError(t *testing.T) {
|
func TestMalformedInstantiatedError(t *testing.T) {
|
||||||
t.Run("bad type", func(t *testing.T) {
|
t.Run("bad type", func(t *testing.T) {
|
||||||
badErr := errors.New("")
|
badErr := errors.New("")
|
||||||
if errors.Is(new(nixbuild.MalformedInstantiatedError), badErr) {
|
if errors.Is(new(nix.MalformedInstantiatedError), badErr) {
|
||||||
t.Error("unexpected MalformedInstantiatedError equivalence")
|
t.Error("unexpected MalformedInstantiatedError equivalence")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("nil", func(t *testing.T) {
|
t.Run("nil", func(t *testing.T) {
|
||||||
if errors.Is(new(nixbuild.MalformedInstantiatedError), (*nixbuild.MalformedInstantiatedError)(nil)) {
|
if errors.Is(new(nix.MalformedInstantiatedError), (*nix.MalformedInstantiatedError)(nil)) {
|
||||||
t.Error("unexpected MalformedInstantiatedError equivalence")
|
t.Error("unexpected MalformedInstantiatedError equivalence")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -158,12 +158,12 @@ func TestMalformedInstantiatedError(t *testing.T) {
|
|||||||
t.Errorf("Error: panic = %q, want %q", r, wantPanic)
|
t.Errorf("Error: panic = %q, want %q", r, wantPanic)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
_ = (&nixbuild.MalformedInstantiatedError{Type: -1}).Error()
|
_ = (&nix.MalformedInstantiatedError{Type: -1}).Error()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchmarkInstantiatedDecoder(b *testing.B, out string) {
|
func benchmarkInstantiatedDecoder(b *testing.B, out string) {
|
||||||
decoder := nixbuild.NewInstantiatedDecoder(strings.NewReader(out), nil)
|
decoder := nix.NewInstantiatedDecoder(strings.NewReader(out), nil)
|
||||||
for b.Loop() {
|
for b.Loop() {
|
||||||
retry:
|
retry:
|
||||||
if !decoder.Scan() {
|
if !decoder.Scan() {
|
||||||
@ -171,7 +171,7 @@ func benchmarkInstantiatedDecoder(b *testing.B, out string) {
|
|||||||
if err := decoder.Err(); err != nil {
|
if err := decoder.Err(); err != nil {
|
||||||
b.Fatalf("Decode: error = %v", err)
|
b.Fatalf("Decode: error = %v", err)
|
||||||
}
|
}
|
||||||
decoder = nixbuild.NewInstantiatedDecoder(strings.NewReader(out), nil)
|
decoder = nix.NewInstantiatedDecoder(strings.NewReader(out), nil)
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
goto retry
|
goto retry
|
||||||
}
|
}
|
||||||
@ -189,7 +189,7 @@ func BenchmarkInstantiatedDecoder(b *testing.B) {
|
|||||||
|
|
||||||
func benchmarkInstantiated(b *testing.B, out string, want []string) {
|
func benchmarkInstantiated(b *testing.B, out string, want []string) {
|
||||||
for b.Loop() {
|
for b.Loop() {
|
||||||
v, _ := nixbuild.NewInstantiatedDecoder(strings.NewReader(out), nil).Decode()
|
v, _ := nix.NewInstantiatedDecoder(strings.NewReader(out), nil).Decode()
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
if !slices.Equal(v, want) {
|
if !slices.Equal(v, want) {
|
||||||
b.Fatalf("Decode: %#v, want %#v", v, want)
|
b.Fatalf("Decode: %#v, want %#v", v, want)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package nixbuild_test
|
package nix_test
|
||||||
|
|
||||||
import _ "embed"
|
import _ "embed"
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package nixbuild_test
|
package nix_test
|
||||||
|
|
||||||
import _ "embed"
|
import _ "embed"
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package nixbuild_test
|
package nix_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package nixbuild_test
|
package nix_test
|
||||||
|
|
||||||
import "strings"
|
import "strings"
|
||||||
|
|
||||||
|
34
stub_test.go
34
stub_test.go
@ -1,4 +1,4 @@
|
|||||||
package nixbuild_test
|
package nix_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -12,7 +12,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.gensokyo.uk/yonah/nixbuild"
|
"gensokyo.uk/nix"
|
||||||
"hakurei.app/command"
|
"hakurei.app/command"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -29,9 +29,9 @@ var (
|
|||||||
|
|
||||||
// stubNixCommand causes all nix command invocations to invoke the stub for the current test.
|
// stubNixCommand causes all nix command invocations to invoke the stub for the current test.
|
||||||
func stubNixCommand(t *testing.T) {
|
func stubNixCommand(t *testing.T) {
|
||||||
n := nixbuild.Nix
|
n := nix.Nix
|
||||||
nixbuild.Nix = os.Args[0]
|
nix.Nix = os.Args[0]
|
||||||
t.Cleanup(func() { nixbuild.Nix = n })
|
t.Cleanup(func() { nix.Nix = n })
|
||||||
|
|
||||||
cur, ok := os.LookupEnv(runAsNixStub)
|
cur, ok := os.LookupEnv(runAsNixStub)
|
||||||
if err := os.Setenv(runAsNixStub, "1"); err != nil {
|
if err := os.Setenv(runAsNixStub, "1"); err != nil {
|
||||||
@ -51,14 +51,14 @@ func stubNixCommand(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// newStubContext creates a context for use with the nix command stub.
|
// newStubContext creates a context for use with the nix command stub.
|
||||||
func newStubContext(ctx context.Context, extraArgs []string, stdout, stderr io.Writer) nixbuild.Context {
|
func newStubContext(ctx context.Context, extraArgs []string, stdout, stderr io.Writer) nix.Context {
|
||||||
return nixbuild.New(ctx, append(stubExtraArgs, extraArgs...), stdout, stderr)
|
return nix.New(ctx, append(stubExtraArgs, extraArgs...), stdout, stderr)
|
||||||
}
|
}
|
||||||
|
|
||||||
type stubContextCommand struct {
|
type stubContextCommand struct {
|
||||||
f func(*exec.Cmd)
|
f func(*exec.Cmd)
|
||||||
|
|
||||||
nixbuild.Context
|
nix.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stubContextCommand) Nix(ctx context.Context, arg ...string) *exec.Cmd {
|
func (s *stubContextCommand) Nix(ctx context.Context, arg ...string) *exec.Cmd {
|
||||||
@ -70,15 +70,15 @@ func (s *stubContextCommand) Nix(ctx context.Context, arg ...string) *exec.Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// newStubContext creates a context for use with the nix command stub with a function injected into [nixbuild.Context.Nix].
|
// newStubContext creates a context for use with the nix command stub with a function injected into [nixbuild.Context.Nix].
|
||||||
func newStubContextCommand(f func(*exec.Cmd), ctx context.Context, extraArgs []string, stdout, stderr io.Writer) nixbuild.Context {
|
func newStubContextCommand(f func(*exec.Cmd), ctx context.Context, extraArgs []string, stdout, stderr io.Writer) nix.Context {
|
||||||
return &stubContextCommand{f, newStubContext(ctx, extraArgs, stdout, stderr)}
|
return &stubContextCommand{f, newStubContext(ctx, extraArgs, stdout, stderr)}
|
||||||
}
|
}
|
||||||
|
|
||||||
// breakNixCommand makes all nix invocations fail for the current test.
|
// breakNixCommand makes all nix invocations fail for the current test.
|
||||||
func breakNixCommand(t *testing.T) {
|
func breakNixCommand(t *testing.T) {
|
||||||
n := nixbuild.Nix
|
n := nix.Nix
|
||||||
nixbuild.Nix = "/proc/nonexistent"
|
nix.Nix = "/proc/nonexistent"
|
||||||
t.Cleanup(func() { nixbuild.Nix = n })
|
t.Cleanup(func() { nix.Nix = n })
|
||||||
}
|
}
|
||||||
|
|
||||||
type stubCommandInitFunc func(c command.Command)
|
type stubCommandInitFunc func(c command.Command)
|
||||||
@ -95,15 +95,15 @@ func TestNixStub(t *testing.T) {
|
|||||||
flagExtraExperimentalFeatures string
|
flagExtraExperimentalFeatures string
|
||||||
)
|
)
|
||||||
c := command.New(os.Stderr, t.Logf, "nix", func(args []string) error {
|
c := command.New(os.Stderr, t.Logf, "nix", func(args []string) error {
|
||||||
if flagExtraExperimentalFeatures != nixbuild.ExperimentalFeaturesFlakes {
|
if flagExtraExperimentalFeatures != nix.ExperimentalFeaturesFlakes {
|
||||||
t.Fatalf("%s: %q, want %q",
|
t.Fatalf("%s: %q, want %q",
|
||||||
nixbuild.ExtraExperimentalFeatures, flagExtraExperimentalFeatures, nixbuild.ExperimentalFeaturesFlakes)
|
nix.ExtraExperimentalFeatures, flagExtraExperimentalFeatures, nix.ExperimentalFeaturesFlakes)
|
||||||
return syscall.ENOTRECOVERABLE
|
return syscall.ENOTRECOVERABLE
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}).
|
}).
|
||||||
Flag(&flagExtraExperimentalFeatures, trimFlagName(nixbuild.ExtraExperimentalFeatures), command.StringFlag(""),
|
Flag(&flagExtraExperimentalFeatures, trimFlagName(nix.ExtraExperimentalFeatures), command.StringFlag(""),
|
||||||
fmt.Sprintf("expects exactly %q", nixbuild.ExperimentalFeaturesFlakes))
|
fmt.Sprintf("expects exactly %q", nix.ExperimentalFeaturesFlakes))
|
||||||
|
|
||||||
c.Command("true", command.UsageInternal, func([]string) error { return nil })
|
c.Command("true", command.UsageInternal, func([]string) error { return nil })
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ func TestNixStub(t *testing.T) {
|
|||||||
|
|
||||||
// checkStdin checks whether entries read from r is equivalent to want.
|
// checkStdin checks whether entries read from r is equivalent to want.
|
||||||
func checkStdin(r io.Reader, want ...string) error {
|
func checkStdin(r io.Reader, want ...string) error {
|
||||||
if got, err := nixbuild.ReadStdin(r); err != nil {
|
if got, err := nix.ReadStdin(r); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if !slices.Equal(got, want) {
|
} else if !slices.Equal(got, want) {
|
||||||
return errors.New(fmt.Sprintf("got build %#v, want %#v", got, want))
|
return errors.New(fmt.Sprintf("got build %#v, want %#v", got, want))
|
||||||
|
12
util_test.go
12
util_test.go
@ -1,4 +1,4 @@
|
|||||||
package nixbuild_test
|
package nix_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@ -6,7 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.gensokyo.uk/yonah/nixbuild"
|
"gensokyo.uk/nix"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCollectFromDerivations(t *testing.T) {
|
func TestCollectFromDerivations(t *testing.T) {
|
||||||
@ -19,11 +19,11 @@ func TestCollectFromDerivations(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
var derivations nixbuild.DerivationMap
|
var derivations nix.DerivationMap
|
||||||
if err := json.Unmarshal(drvShow[tc.name], &derivations); err != nil {
|
if err := json.Unmarshal(drvShow[tc.name], &derivations); err != nil {
|
||||||
t.Fatalf("cannot unmarshal test data: %v", err)
|
t.Fatalf("cannot unmarshal test data: %v", err)
|
||||||
}
|
}
|
||||||
got := nixbuild.CollectFromDerivations(derivations)
|
got := nix.CollectFromDerivations(derivations)
|
||||||
want := collectWant[tc.name]
|
want := collectWant[tc.name]
|
||||||
if !slices.Equal(got, want) {
|
if !slices.Equal(got, want) {
|
||||||
t.Errorf("CollectFromDerivations:\n%s, want\n%s",
|
t.Errorf("CollectFromDerivations:\n%s, want\n%s",
|
||||||
@ -35,9 +35,9 @@ func TestCollectFromDerivations(t *testing.T) {
|
|||||||
t.Run("edge cases", func(t *testing.T) {
|
t.Run("edge cases", func(t *testing.T) {
|
||||||
// this exclusively tests edge cases for nil values and buffer growing, so the data doesn't have to make sense
|
// this exclusively tests edge cases for nil values and buffer growing, so the data doesn't have to make sense
|
||||||
want := []string{"", "big"}
|
want := []string{"", "big"}
|
||||||
got := nixbuild.CollectFromDerivations(nixbuild.DerivationMap{
|
got := nix.CollectFromDerivations(nix.DerivationMap{
|
||||||
"nil": nil,
|
"nil": nil,
|
||||||
"big": &nixbuild.Derivation{InputSources: make([]string, 1<<18)},
|
"big": &nix.Derivation{InputSources: make([]string, 1<<18)},
|
||||||
})
|
})
|
||||||
if !slices.Equal(got, want) {
|
if !slices.Equal(got, want) {
|
||||||
t.Errorf("CollectFromDerivations: %#v, want %#v", got, want)
|
t.Errorf("CollectFromDerivations: %#v, want %#v", got, want)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user