Skip to content

Commit a77e2e6

Browse files
committed
fix(flake): Nix builds release + always specifies target triple
Patch is necessary because Nix doesn't believe in testing what's not being distributed (the release version). See (unofficial) https://ryantm.github.io/nixpkgs/languages-frameworks/rust/#tests-relying-on-the-structure-of-the-target-directory. And since Nix supports distributing to multiple architectures, target architecture is always specified.
1 parent 157e7c8 commit a77e2e6

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

flake.nix

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,80 @@
2525
pkgs = import inputs.nixpkgs {
2626
inherit system overlays;
2727
};
28+
integrationTestPatch = pkgs.writeTextFile {
29+
name = "integration-tests-nix-fix.patch";
30+
text =
31+
# patch
32+
''
33+
diff --git a/tests/main.rs b/tests/main.rs
34+
index c19811d..33c3829 100644
35+
--- a/tests/main.rs
36+
+++ b/tests/main.rs
37+
@@ -15,7 +15,7 @@ fn failure_with_invalid_config() {
38+
let config_file = dir.path().join("nufmt.nuon");
39+
fs::write(&config_file, r#"{unknown: 1}"#).unwrap();
40+
41+
- let output = Command::new("target/debug/nufmt")
42+
+ let output = Command::new("target/@target_triple@/release/nufmt")
43+
.arg("--config")
44+
.arg(config_file.to_str().unwrap())
45+
.arg(dir.path().to_str().unwrap())
46+
@@ -29,7 +29,7 @@ fn failure_with_invalid_config() {
47+
48+
#[test]
49+
fn failure_with_invalid_config_file() {
50+
- let output = Command::new("target/debug/nufmt")
51+
+ let output = Command::new("target/@target_triple@/release/nufmt")
52+
.arg("--config")
53+
.arg("path/that/does/not/exist/nufmt.nuon")
54+
.output()
55+
@@ -42,7 +42,7 @@ fn failure_with_invalid_config_file() {
56+
57+
#[test]
58+
fn failure_with_invalid_file_to_format() {
59+
- let output = Command::new("target/debug/nufmt")
60+
+ let output = Command::new("target/@target_triple@/release/nufmt")
61+
.arg("path/that/does/not/exist/a.nu")
62+
.output()
63+
.unwrap();
64+
@@ -56,7 +56,7 @@ fn failure_with_invalid_file_to_format() {
65+
fn warning_when_no_files_are_detected() {
66+
let dir = tempdir().unwrap();
67+
68+
- let output = Command::new("target/debug/nufmt")
69+
+ let output = Command::new("target/@target_triple@/release/nufmt")
70+
.arg("--dry-run")
71+
.arg(dir.path().to_str().unwrap())
72+
.output()
73+
@@ -75,7 +75,7 @@ fn warning_is_displayed_when_no_files_are_detected_with_excluded_files() {
74+
fs::write(&config_file, r#"{exclude: ["a*"]}"#).unwrap();
75+
fs::write(&file_a, INVALID).unwrap();
76+
77+
- let output = Command::new("target/debug/nufmt")
78+
+ let output = Command::new("target/@target_triple@/release/nufmt")
79+
.arg("--config")
80+
.arg(config_file.to_str().unwrap())
81+
.arg("--dry-run")
82+
@@ -98,7 +98,7 @@ fn files_are_reformatted() {
83+
fs::write(&file_a, INVALID).unwrap();
84+
fs::write(&file_b, INVALID).unwrap();
85+
86+
- let output = Command::new("target/debug/nufmt")
87+
+ let output = Command::new("target/@target_triple@/release/nufmt")
88+
.arg("--config")
89+
.arg(config_file.to_str().unwrap())
90+
.arg(dir.path().to_str().unwrap())
91+
@@ -122,7 +122,7 @@ fn files_are_checked() {
92+
fs::write(&file_a, INVALID).unwrap();
93+
fs::write(&file_b, INVALID).unwrap();
94+
95+
- let output = Command::new("target/debug/nufmt")
96+
+ let output = Command::new("target/@target_triple@/release/nufmt")
97+
.arg("--config")
98+
.arg(config_file.to_str().unwrap())
99+
.arg("--dry-run")
100+
'';
101+
};
28102
in
29103
{
30104
devShells.default = pkgs.mkShell {
@@ -41,6 +115,11 @@
41115
packages.nufmt = pkgs.rustPlatform.buildRustPackage {
42116
name = "nufmt";
43117
src = ./.;
118+
patches = [
119+
(pkgs.replaceVars "${integrationTestPatch}" {
120+
target_triple = pkgs.stdenv.hostPlatform.rust.rustcTarget;
121+
})
122+
];
44123
cargoLock.lockFile = ./Cargo.lock;
45124
};
46125

0 commit comments

Comments
 (0)