Skip to content

Commit f65fd78

Browse files
authored
tests(modules.symlinkScript): update tests for symlinkScript (#533)
check that binaries work, and also use our new testing lib.
1 parent 616a22a commit f65fd78

1 file changed

Lines changed: 76 additions & 66 deletions

File tree

Lines changed: 76 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,85 @@
11
{
2-
pkgs,
32
self,
3+
pkgs,
4+
tlib,
45
...
56
}:
67

78
let
8-
# Create a dummy package with a desktop file that references itself
9-
dummyPackage =
10-
(pkgs.runCommand "dummy-app" { } ''
11-
mkdir -p $out/bin
12-
mkdir -p $out/share/applications
13-
14-
# Create a simple executable
15-
cat > $out/bin/dummy-app <<'EOF'
16-
#!/bin/sh
17-
echo "Hello from dummy app"
18-
EOF
19-
chmod +x $out/bin/dummy-app
20-
21-
# Create a desktop file that references the package path
22-
cat > $out/share/applications/dummy-app.desktop <<EOF
23-
[Desktop Entry]
24-
Name=Dummy App
25-
Exec=$out/bin/dummy-app
26-
Icon=$out/share/icons/dummy-app.png
27-
Type=Application
28-
EOF
29-
'')
30-
// {
31-
meta.mainProgram = "dummy-app";
32-
};
33-
34-
# Wrap the package
35-
wrappedPackage = self.lib.wrapPackage {
36-
inherit pkgs;
37-
package = dummyPackage;
38-
};
39-
9+
inherit (tlib) isFile fileContains test;
4010
in
41-
pkgs.runCommand "filesToPatch-test"
42-
{
43-
originalPath = "${dummyPackage}";
44-
wrappedPath = "${wrappedPackage}";
45-
}
46-
''
47-
echo "Testing filesToPatch functionality..."
48-
echo "Original package path: $originalPath"
49-
echo "Wrapped package path: $wrappedPath"
50-
51-
# Read the desktop file
52-
desktopFile="${wrappedPackage}/share/applications/dummy-app.desktop"
53-
54-
if [ ! -f "$desktopFile" ]; then
55-
echo "FAIL: Desktop file not found at $desktopFile"
56-
exit 1
57-
fi
11+
test "filesToPatch-test" {
12+
regular =
13+
let
14+
wrappedPackage = self.lib.wrapPackage {
15+
inherit pkgs;
16+
# Create a dummy package with a desktop file that references itself
17+
package =
18+
(pkgs.runCommand "dummy-app" { } ''
19+
mkdir -p $out/bin
20+
mkdir -p $out/share/applications
5821
59-
# The desktop file should NOT contain references to the original package
60-
if grep -qF "$originalPath" "$desktopFile"; then
61-
echo "FAIL: Desktop file still contains reference to original package"
62-
echo "Original path: $originalPath"
63-
exit 1
64-
fi
22+
cat > $out/bin/dummy-app <<'EOF'
23+
#!/bin/sh
24+
echo "Hello from dummy app"
25+
EOF
26+
chmod +x $out/bin/dummy-app
6527
66-
# The desktop file SHOULD contain references to the wrapped package
67-
if ! grep -qF "$wrappedPath" "$desktopFile"; then
68-
echo "FAIL: Desktop file does not contain reference to wrapped package"
69-
echo "Wrapped path: $wrappedPath"
70-
exit 1
71-
fi
72-
73-
echo "SUCCESS: Desktop file was properly patched"
74-
touch $out
75-
''
28+
cat > $out/share/applications/dummy-app.desktop <<EOF
29+
[Desktop Entry]
30+
Name=Dummy App
31+
Exec=$out/bin/dummy-app
32+
Icon=$out/share/icons/dummy-app.png
33+
Type=Application
34+
EOF
35+
'')
36+
// {
37+
meta.mainProgram = "dummy-app";
38+
};
39+
};
40+
originalPath = "${wrappedPackage.configuration.package}";
41+
wrappedPath = "${wrappedPackage}";
42+
desktopFile = "${wrappedPackage}/share/applications/dummy-app.desktop";
43+
in
44+
{
45+
desktopFileExists = isFile desktopFile;
46+
noOriginalReferences = {
47+
cond = "! grep -qF '${originalPath}' '${desktopFile}' ";
48+
msg = "Desktop file still contains reference to original package. Original path: ${originalPath}";
49+
};
50+
containsWrappedReferences = fileContains desktopFile wrappedPath;
51+
};
52+
binary =
53+
let
54+
wrappedPackage = self.lib.wrapPackage [
55+
{ inherit pkgs; }
56+
(
57+
{ wlib, pkgs, ... }:
58+
{
59+
filesToPatch = [ "bin/fileToBePatched" ];
60+
package = wlib.wrapPackage [
61+
{ inherit pkgs; }
62+
(
63+
{ pkgs, ... }:
64+
{
65+
package = pkgs.hello;
66+
wrapperImplementation = "binary";
67+
wrapperVariants.fileToBePatched.exePath = "bin/hello"; # <- not the main one, the outer wrapper module will thus not wrap it automatically.
68+
flags."--greeting" = "Hello, ${placeholder "out"}";
69+
}
70+
)
71+
];
72+
}
73+
)
74+
];
75+
originalPath = "${wrappedPackage.configuration.package}";
76+
wrappedPath = "${wrappedPackage}/bin/fileToBePatched";
77+
in
78+
{
79+
noOriginalReferences = {
80+
cond = "! grep -qF '${originalPath}' '${wrappedPath}' ";
81+
msg = "Desktop file still contains reference to original package. Original path: ${originalPath}";
82+
};
83+
containsWrappedReferences = fileContains wrappedPath wrappedPackage;
84+
};
85+
}

0 commit comments

Comments
 (0)