Skip to content

Commit

Permalink
Simplify the location expansion integration test
Browse files Browse the repository at this point in the history
It now only tests the correct mapping of paths in the local workspace
and in an external workspace. The parsing of more complicated location
strings is tested in the unit tests.

Addressing review comment
#132 (comment)
  • Loading branch information
aherrmann committed Nov 11, 2020
1 parent 17d5f61 commit c5e464f
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 36 deletions.
21 changes: 11 additions & 10 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -174,25 +174,26 @@ nixpkgs_package(
repository = "@remote_nixpkgs",
)

local_repository(
name = "nixpkgs_location_expansion_test_file",
path = "tests/location_expansion/test_repo",
)

nixpkgs_package(
name = "nixpkgs_location_expansion_test",
build_file_content = "exports_files(glob(['out/**']))",
nix_file = "//tests:location_expansion.nix",
nix_file_deps = [
"//:nixpkgs.json",
"//:nixpkgs.nix",
"@io_tweag_rules_nixpkgs//tests:relative_imports/nixpkgs.nix",
"//tests:location_expansion/test_file",
"@nixpkgs_location_expansion_test_file//:test_file",
],
nixopts = [
"--arg",
"attrs",
"{ nixpkgs_json = $(location //:nixpkgs.json); nixpkgs_nix = $(location //:nixpkgs.nix); }",
"local_file",
"$(location //tests:location_expansion/test_file)",
"--arg",
"relative_imports",
"$(location @io_tweag_rules_nixpkgs//tests:relative_imports/nixpkgs.nix)",
"--argstr",
"escaped_string",
"$$ $$(location //:does-not-exist) )(",
"external_file",
"$(location @nixpkgs_location_expansion_test_file//:test_file)",
],
repository = "@remote_nixpkgs",
)
Expand Down
22 changes: 6 additions & 16 deletions tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,14 @@ sh_test(
srcs = ["location_expansion.sh"],
args = [
"$(POSIX_DIFF)",
"$(rootpath //:nixpkgs.json)",
"$(rootpath //:nixpkgs.nix)",
"$(rootpath //tests:relative_imports/nixpkgs.nix)",
"$(rootpath //tests:location_expansion/escaped_string)",
"$(rootpath @nixpkgs_location_expansion_test//:out/nixpkgs.json)",
"$(rootpath @nixpkgs_location_expansion_test//:out/nixpkgs.nix)",
"$(rootpath @nixpkgs_location_expansion_test//:out/relative_imports.nix)",
"$(rootpath @nixpkgs_location_expansion_test//:out/escaped_string)",
"$(rootpath //tests:location_expansion/test_file)",
"$(rootpath @nixpkgs_location_expansion_test//:out/local_file)",
"$(rootpath @nixpkgs_location_expansion_test//:out/external_file)",
],
data = [
"//:nixpkgs.json",
"//:nixpkgs.nix",
"//tests:location_expansion/escaped_string",
"//tests:relative_imports/nixpkgs.nix",
"@nixpkgs_location_expansion_test//:out/escaped_string",
"@nixpkgs_location_expansion_test//:out/nixpkgs.json",
"@nixpkgs_location_expansion_test//:out/nixpkgs.nix",
"@nixpkgs_location_expansion_test//:out/relative_imports.nix",
"//tests:location_expansion/test_file",
"@nixpkgs_location_expansion_test//:out/external_file",
"@nixpkgs_location_expansion_test//:out/local_file",
],
toolchains = ["@rules_sh//sh/posix:make_variables"],
)
Expand Down
8 changes: 3 additions & 5 deletions tests/location_expansion.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
with import <nixpkgs> { config = {}; overlays = []; };

{ attrs, relative_imports, escaped_string }:
{ local_file, external_file }:
let
inherit (attrs) nixpkgs_json nixpkgs_nix;
in
Expand All @@ -11,8 +11,6 @@ in
}
''
mkdir -p $out/out
cp ${nixpkgs_json} $out/out/nixpkgs.json
cp ${nixpkgs_nix} $out/out/nixpkgs.nix
cp ${relative_imports} $out/out/relative_imports.nix
echo '${escaped_string}' >$out/out/escaped_string
cp ${local_file} $out/out/local_file
cp ${external_file} $out/out/external_file
''
15 changes: 11 additions & 4 deletions tests/location_expansion.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#!/usr/bin/env bash
set -euo pipefail

# USAGE:
# location_expansion.sh DIFF REFERENCE FILE...
#
# Compares the given files to the reference file and fails if there is a difference.
DIFF="$1"
REFERENCE="$2"

diff "$2" "$6"
diff "$3" "$7"
diff "$4" "$8"
diff "$5" "$9"
for file in "${@:3}"; do
"$DIFF" "$file" "$REFERENCE"
done
1 change: 0 additions & 1 deletion tests/location_expansion/escaped_string

This file was deleted.

11 changes: 11 additions & 0 deletions tests/location_expansion/test_file
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# A few random numbers
3030205
68380721
93196393
70110283
92132420
98602836
37655207
12502743
73421895
75878115
1 change: 1 addition & 0 deletions tests/location_expansion/test_repo/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports_files(glob(["*"]))
Empty file.
1 change: 1 addition & 0 deletions tests/location_expansion/test_repo/test_file

0 comments on commit c5e464f

Please sign in to comment.