diff --git a/cmd/nixtest/main.go b/cmd/nixtest/main.go index 18a9a6b..fd73b17 100644 --- a/cmd/nixtest/main.go +++ b/cmd/nixtest/main.go @@ -88,8 +88,17 @@ func runTest(spec TestSpec) TestResult { var actual any var expected any - if spec.Type == "snapshot" { + if spec.ActualDrv != "" { + var err error + actual, err = buildAndParse(spec.ActualDrv) + if err != nil { + result.Error = fmt.Sprintf("[system] failed to parse drv output: %v", err.Error()) + goto end + } + } else { actual = spec.Actual + } + if spec.Type == "snapshot" { filePath := path.Join( *snapshotDir, fmt.Sprintf("%s.snap.json", strings.ToLower(spec.Name)), @@ -111,16 +120,6 @@ func runTest(spec TestSpec) TestResult { goto end } } else if spec.Type == "unit" { - if spec.ActualDrv != "" { - var err error - actual, err = buildAndParse(spec.ActualDrv) - if err != nil { - result.Error = fmt.Sprintf("[system] failed to parse drv output: %v", err.Error()) - goto end - } - } else { - actual = spec.Actual - } expected = spec.Expected } else { log.Panic().Str("type", spec.Type).Msg("Invalid test type") diff --git a/flake.nix b/flake.nix index 9e7ddbf..a1c5ab2 100644 --- a/flake.nix +++ b/flake.nix @@ -52,6 +52,7 @@ } { name = "fail"; + pos = __curPos; expected = 0; actual = "meow"; } @@ -61,11 +62,20 @@ pos = __curPos; actual = "test"; } + { + name = "test-snapshot-drv"; + type = "snapshot"; + pos = __curPos; + actualDrv = pkgs.runCommand "test-snapshot" {} '' + echo '"snapshot drv"' > $out + ''; + } ]; "other-suite" = [ { name = "obj-snapshot"; type = "snapshot"; + pos = __curPos; actual = {hello = "world";}; } { diff --git a/snapshots/test-snapshot-drv.snap.json b/snapshots/test-snapshot-drv.snap.json new file mode 100644 index 0000000..a4386c7 --- /dev/null +++ b/snapshots/test-snapshot-drv.snap.json @@ -0,0 +1 @@ +"snapshot drv" \ No newline at end of file