apache / openserverless

Apache OpenServerless (incubating)
https://openserverless.apache.org
Apache License 2.0
382 stars 14 forks source link

[CLI] prereq_yml test fails on Macos #46

Closed d4rkstar closed 2 months ago

d4rkstar commented 3 months ago

On macos arm64 the test fails.

❯ task itest T=prereq_yml                                                    
task: Task "bats" is up to date
task: [itest] rm -Rf ~/.ops/olaris
task: [itest] if test -z "prereq_yml"
then bats/bin/bats  .
else bats/bin/bats  prereq_yml.bats
fi

prereq_yml.bats
 ✗ OS=linux ARCH=amd64
   (from function `assert_equal' in file test_helper/bats-assert/src/assert_equal.bash, line 40,
    in test file prereq_yml.bats, line 32)
     `assert_equal "$(cat _count)" $COUNT' failed
          1

   -- values do not equal --
   expected : 1
   actual   :        1
   --

 ✗ OS=linux ARCH=arm64
   (from function `assert_equal' in file test_helper/bats-assert/src/assert_equal.bash, line 40,
    in test file prereq_yml.bats, line 40)
     `assert_equal "$(cat _count)" $COUNT' failed
          1

   -- values do not equal --
   expected : 1
   actual   :        1
   --

 ✗ OS=darwin ARCH=amd64
   (from function `assert_equal' in file test_helper/bats-assert/src/assert_equal.bash, line 40,
    in test file prereq_yml.bats, line 48)
     `assert_equal "$(cat _count)" $COUNT' failed
          2

   -- values do not equal --
   expected : 1
   actual   :        2
   --

 ✗ OS=darwin ARCH=arm64
   (from function `assert_equal' in file test_helper/bats-assert/src/assert_equal.bash, line 40,
    in test file prereq_yml.bats, line 56)
     `assert_equal "$(cat _count)" $COUNT' failed
          3

   -- values do not equal --
   expected : 1
   actual   :        3
   --

 ✗ OS=windows ARCH=amd64
   (from function `assert_equal' in file test_helper/bats-assert/src/assert_equal.bash, line 40,
    in test file prereq_yml.bats, line 64)
     `assert_equal "$(cat _count)" $COUNT' failed
          1

   -- values do not equal --
   expected : 1
   actual   :        1
   --

5 tests, 5 failures

task: Failed to run task "itest": exit status 1

After a preliminary analysis it seems that there are two small "bugs": 1) the _count contains a string with spaces while the $COUNT contains 1 without spaces 2) on macos the 7zz executable is multi-arch binary, so the _count will contain 2 instead of 1 because of the grep expression.

In fact, while on linux platform the file command will return 1 line for multi-arch binaries.

❯ file 7zz
7zz: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit x86_64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|WEAK_DEFINES|BINDS_TO_WEAK|PIE>] [arm64]```

On mac, the `file` command will return multiple lines

```bash
❯ file 7zz             
7zz: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64]
7zz (for architecture x86_64):  Mach-O 64-bit executable x86_64
7zz (for architecture arm64):   Mach-O 64-bit executable arm64