Skip to content

Commit

Permalink
Fix Windows escaping
Browse files Browse the repository at this point in the history
Closes gleam#3648
  • Loading branch information
lpil authored and PgBiel committed Dec 21, 2024
1 parent 90417da commit d9bcce0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
12 changes: 4 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
# Gleam's Changelog

## Unreleased
## v1.5.1 - 2024-09-26

### Build tool

### Compiler

### Formatter
### Bug Fixes

### Language Server
- Fixed a bug where Erlang file paths would not be escaped on Windows.
([Louis Pilfold](https://github.com/lpil))

### Bug Fixes
1 change: 1 addition & 0 deletions compiler-core/src/erlang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ fn file_attribute<'a>(
line_numbers: &'a LineNumbers,
) -> Document<'a> {
let line = line_numbers.line_number(function.location.start);
let path = path.replace("\\", "\\\\");
docvec!["-file(\"", path, "\", ", line, ")."]
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: compiler-core/src/erlang/tests.rs
assertion_line: 944
expression: "pub fn main() { Nil }"
---
-module(my@mod).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).

-export([main/0]).

-file("C:\\root\\project\\test\\my\\mod.gleam", 1).
-spec main() -> nil.
main() ->
nil.
20 changes: 17 additions & 3 deletions compiler-core/src/erlang/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ mod type_params;
mod use_;
mod variables;

pub fn compile_test_project(src: &str, dep: Option<(&str, &str, &str)>) -> String {
pub fn compile_test_project(src: &str, src_path: &str, dep: Option<(&str, &str, &str)>) -> String {
let mut modules = im::HashMap::new();
let ids = UniqueIdGenerator::new();
// DUPE: preludeinsertion
Expand Down Expand Up @@ -73,7 +73,7 @@ pub fn compile_test_project(src: &str, dep: Option<(&str, &str, &str)>) -> Strin
let _ = modules.insert(dep_name.into(), dep.type_info);
let _ = direct_dependencies.insert(dep_package.into(), ());
}
let path = Utf8PathBuf::from("/root/project/test/my/mod.gleam");
let path = Utf8PathBuf::from(src_path);
let parsed = crate::parse::parse_module(path.clone(), src, &WarningEmitter::null())
.expect("syntax error");
let mut config = PackageConfig::default();
Expand Down Expand Up @@ -102,13 +102,18 @@ macro_rules! assert_erl {
(($dep_package:expr, $dep_name:expr, $dep_src:expr), $src:expr $(,)?) => {{
let output = $crate::erlang::tests::compile_test_project(
$src,
"/root/project/test/my/mod.gleam",
Some(($dep_package, $dep_name, $dep_src)),
);
insta::assert_snapshot!(insta::internals::AutoName, output, $src);
}};

($src:expr $(,)?) => {{
let output = $crate::erlang::tests::compile_test_project($src, None);
let output = $crate::erlang::tests::compile_test_project(
$src,
"/root/project/test/my/mod.gleam",
None,
);
insta::assert_snapshot!(insta::internals::AutoName, output, $src);
}};
}
Expand Down Expand Up @@ -929,3 +934,12 @@ pub fn main() {
"
);
}

// https://github.com/gleam-lang/gleam/issues/3648
#[test]
fn windows_file_escaping_bug() {
let src = "pub fn main() { Nil }";
let path = "C:\\root\\project\\test\\my\\mod.gleam";
let output = compile_test_project(src, path, None);
insta::assert_snapshot!(insta::internals::AutoName, output, src);
}

0 comments on commit d9bcce0

Please sign in to comment.