Skip to content

Commit

Permalink
std/os: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Feb 19, 2025
1 parent 4fb6dee commit 1300a82
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/std_tests_clang_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ jobs:
julec test --compiler clang -o test std/net/url
./test
- name: Test - std/os
run: |
julec test --compiler clang -o test std/os/test
./test
- name: Test - std/path
run: |
julec test --compiler clang -o test std/path
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/std_tests_clang_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ jobs:
julec test --compiler clang -o test std/net/url
./test
- name: Test - std/os
run: |
julec test --compiler clang -o test std/os/test
./test
- name: Test - std/path
run: |
julec test --compiler clang -o test std/path
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/std_tests_clang_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ jobs:
.\bin\julec test --compiler clang -o test std/net/url
./test
- name: Test - std/os
run: |
.\bin\julec test --compiler clang -o test std/os/test
./test
- name: Test - std/path
run: |
.\bin\julec test --compiler clang -o test std/path
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/std_tests_gcc_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ jobs:
g++-13 -w --std=c++17 -O0 -Wl,-ld_classic -o test dist/ir.cpp
./test
- name: Test - std/os
run: |
julec test --compiler gcc --compiler-path g++-13 -o test -t std/os/test
g++-13 -w --std=c++17 -O0 -Wl,-ld_classic -o test dist/ir.cpp
./test
- name: Test - std/path
run: |
julec test --compiler gcc --compiler-path g++-13 -o test -t std/path
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/std_tests_gcc_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ jobs:
julec test --compiler gcc -o test std/net/url
./test
- name: Test - std/os
run: |
julec test --compiler gcc -o test std/os/test
./test
- name: Test - std/path
run: |
julec test --compiler gcc -o test std/path
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/std_tests_gcc_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ jobs:
.\bin\julec test --compiler gcc -o test std/net/url
./test
- name: Test - std/os
run: |
.\bin\julec test --compiler gcc -o test std/os/test
./test
- name: Test - std/path
run: |
.\bin\julec test --compiler gcc -o test std/path
Expand Down
6 changes: 6 additions & 0 deletions std/os/export_windows.test.jule
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright 2025 The Jule Programming Language.
// Use of this source code is governed by a BSD 3-Clause
// license that can be found in the LICENSE file.

// Export for testing.
static AddExtendedPrefix = addExtendedPrefix
115 changes: 115 additions & 0 deletions std/os/test/path_windows_test.jule
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Copyright 2025 The Jule Programming Language.
// Use of this source code is governed by a BSD 3-Clause
// license that can be found in the LICENSE file.

use "std/os"
use "std/os/filepath"
use "std/strings"
use "std/testing"

struct addExtendedPrefixTest {
input: str
want: str
}

#test
fn testAddExtendedPrefix(t: &testing::T) {
// Test addExtendedPrefix instead of fixLongPath so the path manipulation code
// is exercised even if long path are supported by the system, else the
// function might not be tested at all if/when all test builders support long paths.
mut cwd := os::Getwd()!
drive := strings::ToLower(filepath::VolumeName(cwd))
cwd = strings::ToLower(cwd[len(drive)+1:])
// Build a very long pathname. Paths in Go are supposed to be arbitrarily long,
// so let's make a long path which is comfortably bigger than MAX_PATH on Windows
// (256) and thus requires fixLongPath to be correctly interpreted in I/O syscalls.
veryLong := "l" + strings::Repeat("o", 500) + "ng"
for _, test in []addExtendedPrefixTest([
// Test cases use word substitutions:
// * "long" is replaced with a very long pathname
// * "c:" or "C:" are replaced with the drive of the current directory (preserving case)
// * "cwd" is replaced with the current directory

// Drive Absolute
{`C:\long\foo.txt`, `\\?\C:\long\foo.txt`},
{`C:/long/foo.txt`, `\\?\C:\long\foo.txt`},
{`C:\\\long///foo.txt`, `\\?\C:\long\foo.txt`},
{`C:\long\.\foo.txt`, `\\?\C:\long\foo.txt`},
{`C:\long\..\foo.txt`, `\\?\C:\foo.txt`},
{`C:\long\..\..\foo.txt`, `\\?\C:\foo.txt`},

// Drive Relative
{`C:long\foo.txt`, `\\?\C:\cwd\long\foo.txt`},
{`C:long/foo.txt`, `\\?\C:\cwd\long\foo.txt`},
{`C:long///foo.txt`, `\\?\C:\cwd\long\foo.txt`},
{`C:long\.\foo.txt`, `\\?\C:\cwd\long\foo.txt`},
{`C:long\..\foo.txt`, `\\?\C:\cwd\foo.txt`},

// Rooted
{`\long\foo.txt`, `\\?\C:\long\foo.txt`},
{`/long/foo.txt`, `\\?\C:\long\foo.txt`},
{`\long///foo.txt`, `\\?\C:\long\foo.txt`},
{`\long\.\foo.txt`, `\\?\C:\long\foo.txt`},
{`\long\..\foo.txt`, `\\?\C:\foo.txt`},

// Relative
{`long\foo.txt`, `\\?\C:\cwd\long\foo.txt`},
{`long/foo.txt`, `\\?\C:\cwd\long\foo.txt`},
{`long///foo.txt`, `\\?\C:\cwd\long\foo.txt`},
{`long\.\foo.txt`, `\\?\C:\cwd\long\foo.txt`},
{`long\..\foo.txt`, `\\?\C:\cwd\foo.txt`},
{`.\long\foo.txt`, `\\?\C:\cwd\long\foo.txt`},

// UNC Absolute
{`\\srv\share\long`, `\\?\UNC\srv\share\long`},
{`//srv/share/long`, `\\?\UNC\srv\share\long`},
{`/\srv/share/long`, `\\?\UNC\srv\share\long`},
{`\\srv\share\long\`, `\\?\UNC\srv\share\long\`},
{`\\srv\share\bar\.\long`, `\\?\UNC\srv\share\bar\long`},
{`\\srv\share\bar\..\long`, `\\?\UNC\srv\share\long`},
{`\\srv\share\bar\..\..\long`, `\\?\UNC\srv\share\long`}, // share name is not removed by ".."

// Local Device
{`\\.\C:\long\foo.txt`, `\\.\C:\long\foo.txt`},
{`//./C:/long/foo.txt`, `\\.\C:\long\foo.txt`},
{`/\./C:/long/foo.txt`, `\\.\C:\long\foo.txt`},
{`\\.\C:\long///foo.txt`, `\\.\C:\long\foo.txt`},
{`\\.\C:\long\.\foo.txt`, `\\.\C:\long\foo.txt`},
{`\\.\C:\long\..\foo.txt`, `\\.\C:\foo.txt`},

// Misc tests
{`C:\short.txt`, `C:\short.txt`},
{`C:\`, `C:\`},
{`C:`, `C:`},
{`\\srv\path`, `\\srv\path`},
{`long.txt`, `\\?\C:\cwd\long.txt`},
{`C:long.txt`, `\\?\C:\cwd\long.txt`},
{`C:\long\.\bar\baz`, `\\?\C:\long\bar\baz`},
{`C:long\.\bar\baz`, `\\?\C:\cwd\long\bar\baz`},
{`C:\long\..\bar\baz`, `\\?\C:\bar\baz`},
{`C:long\..\bar\baz`, `\\?\C:\cwd\bar\baz`},
{`C:\long\foo\\bar\.\baz\\`, `\\?\C:\long\foo\bar\baz\`},
{`C:\long\..`, `\\?\C:\`},
{`C:\.\long\..\.`, `\\?\C:\`},
{`\\?\C:\long\foo.txt`, `\\?\C:\long\foo.txt`},
{`\\?\C:\long/foo.txt`, `\\?\C:\long/foo.txt`},
]) {
mut input := strings::ReplaceAll(test.input, "long", veryLong)
input = strings::ToLower(input)
input = strings::ReplaceAll(input, "c:", drive)

mut want := strings::ReplaceAll(test.want, "long", veryLong)
want = strings::ToLower(want)
want = strings::ReplaceAll(want, "c:", drive)
want = strings::ReplaceAll(want, "cwd", cwd)

mut got := os::AddExtendedPrefix(input)
got = strings::ToLower(got)
if got != want {
input = strings::ReplaceAll(input, veryLong, "long")
got = strings::ReplaceAll(got, veryLong, "long")
want = strings::ReplaceAll(want, veryLong, "long")
t.Errorf("addExtendedPrefix({}) = {}; want {}", input, got, want)
}
}
}

0 comments on commit 1300a82

Please sign in to comment.