FabioBatSilva / ArduinoFake

Arduino mocking made easy
https://platformio.org/lib/show/1689/ArduinoFake
MIT License
102 stars 47 forks source link

Add support for faking (Two|)Wire #26

Closed wrong-kendall closed 2 years ago

wrong-kendall commented 2 years ago

Maybe a little premature... I verified in a PIO project that the mocking works; however, I'm having trouble verifying the integrated tests. I'm not very familiar with cmake so it'll take me some time to chase this down. I'm posting the error below in case something jumps out at you that might save me time.

/usr/bin/cmake -E cmake_link_script CMakeFiles/main.dir/link.txt --verbose=1
/usr/bin/c++    -rdynamic CMakeFiles/main.dir/main.o  -o main -lProject -lunity 
/usr/bin/ld: cannot find -lProject
/usr/bin/ld: cannot find -lunity
collect2: error: ld returned 1 exit status
CMakeFiles/main.dir/build.make:83: recipe for target 'main' failed
make[2]: *** [main] Error 1
make[2]: Leaving directory '/home/kendall/development/src/ArduinoFake'
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/main.dir/all' failed
make[1]: *** [CMakeFiles/main.dir/all] Error 2
make[1]: Leaving directory '/home/kendall/development/src/ArduinoFake'
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
FabioBatSilva commented 2 years ago

Thanks @wrong-kendall..

I need to migrate the checks to gh actions..

Not sure why the cmake error, i get something different.. Might be related to the compiler version you have instated

$ cc --version
cc (Ubuntu 10.3.0-1ubuntu1) 10.3.0

$ c++ --version
c++ (Ubuntu 10.3.0-1ubuntu1) 10.3.0

$ cmake --version
cmake version 3.18.4

Ran the tests locally and looks like the compiler is complaining about TwoWire::requestFrom

Branch 'wrong-kendall' set up to track remote branch 'master' from 'wrong-kendall'.
Switched to a new branch 'wrong-kendall'

$ make 
-- The C compiler identification is GNU 10.3.0
-- The CXX compiler identification is GNU 10.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Git: /usr/bin/git (found version "2.30.2") 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/fsilva/workspace/ArduinoFake/build
make[1]: Entering directory '/home/fsilva/workspace/ArduinoFake/build'
make[2]: Entering directory '/home/fsilva/workspace/ArduinoFake/build'
make[3]: Entering directory '/home/fsilva/workspace/ArduinoFake/build'
Scanning dependencies of target unity
make[3]: Leaving directory '/home/fsilva/workspace/ArduinoFake/build'
make[3]: Entering directory '/home/fsilva/workspace/ArduinoFake/build'
[  6%] Building C object external/unity/CMakeFiles/unity.dir/unity-repo/src/unity.c.o
[ 13%] Linking C static library libunity.a
make[3]: Leaving directory '/home/fsilva/workspace/ArduinoFake/build'
[ 13%] Built target unity
make[3]: Entering directory '/home/fsilva/workspace/ArduinoFake/build'
Scanning dependencies of target ArduinoFake
make[3]: Leaving directory '/home/fsilva/workspace/ArduinoFake/build'
make[3]: Entering directory '/home/fsilva/workspace/ArduinoFake/build'
[ 20%] Building CXX object src/CMakeFiles/ArduinoFake.dir/ArduinoFake.cpp.o
[ 26%] Building CXX object src/CMakeFiles/ArduinoFake.dir/ClientFake.cpp.o
[ 33%] Building CXX object src/CMakeFiles/ArduinoFake.dir/FunctionFake.cpp.o
[ 40%] Building CXX object src/CMakeFiles/ArduinoFake.dir/PrintFake.cpp.o
[ 46%] Building CXX object src/CMakeFiles/ArduinoFake.dir/SerialFake.cpp.o
[ 53%] Building CXX object src/CMakeFiles/ArduinoFake.dir/StreamFake.cpp.o
[ 60%] Building CXX object src/CMakeFiles/ArduinoFake.dir/WireFake.cpp.o
[ 66%] Building CXX object src/CMakeFiles/ArduinoFake.dir/arduino/IPAddress.cpp.o
[ 73%] Building CXX object src/CMakeFiles/ArduinoFake.dir/arduino/WString.cpp.o
[ 80%] Building C object src/CMakeFiles/ArduinoFake.dir/arduino/noniso.c.o
[ 86%] Linking CXX shared library libArduinoFake.so
make[3]: Leaving directory '/home/fsilva/workspace/ArduinoFake/build'
[ 86%] Built target ArduinoFake
make[3]: Entering directory '/home/fsilva/workspace/ArduinoFake/build'
Scanning dependencies of target main
make[3]: Leaving directory '/home/fsilva/workspace/ArduinoFake/build'
make[3]: Entering directory '/home/fsilva/workspace/ArduinoFake/build'
[ 93%] Building CXX object test/CMakeFiles/main.dir/main.cpp.o
In file included from /home/fsilva/workspace/ArduinoFake/test/main.cpp:12:
/home/fsilva/workspace/ArduinoFake/test/test_wire.h: In function ‘void WireTest::test_basics()’:
/home/fsilva/workspace/ArduinoFake/test/test_wire.h:80:50: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
   80 |   Wire.requestFrom(device_addr, num_bytes_to_read);
      |                                                  ^
In file included from /home/fsilva/workspace/ArduinoFake/test/../src/WireFake.h:4,
                 from /home/fsilva/workspace/ArduinoFake/test/../src/ArduinoFake.h:18,
                 from /home/fsilva/workspace/ArduinoFake/test/../src/Arduino.h:1,
                 from /home/fsilva/workspace/ArduinoFake/test/main.cpp:1:
/home/fsilva/workspace/ArduinoFake/test/../src/arduino/Wire.h:25:13: note: candidate 1: ‘uint8_t TwoWire::requestFrom(int, int)’
   25 |     uint8_t requestFrom(int, int);
      |             ^~~~~~~~~~~
/home/fsilva/workspace/ArduinoFake/test/../src/arduino/Wire.h:22:13: note: candidate 2: ‘uint8_t TwoWire::requestFrom(uint8_t, uint8_t)’
   22 |     uint8_t requestFrom(uint8_t, uint8_t);
      |             ^~~~~~~~~~~
[100%] Linking CXX executable main
make[3]: Leaving directory '/home/fsilva/workspace/ArduinoFake/build'
[100%] Built target main
make[2]: Leaving directory '/home/fsilva/workspace/ArduinoFake/build'
make[1]: Leaving directory '/home/fsilva/workspace/ArduinoFake/build'
make[1]: Entering directory '/home/fsilva/workspace/ArduinoFake/build'
Running tests...
Test project /home/fsilva/workspace/ArduinoFake/build
    Start 1: main
1/1 Test #1: main .............................Child aborted***Exception:   0.09 sec
terminate called after throwing an instance of 'fakeit::UnexpectedMethodCallException'

0% tests passed, 1 tests failed out of 1

Total Test time (real) =   0.09 sec

The following tests FAILED:
      1 - main (Child aborted)
Errors while running CTest
make[1]: *** [Makefile:103: test] Error 8
make[1]: Leaving directory '/home/fsilva/workspace/ArduinoFake/build'
make: *** [Makefile:16: test] Error 2
wrong-kendall commented 2 years ago

Thanks for the prompt response and confirming that the problem is definitely with my setup. I'll do some digging and update here once I've figured it out.

wrong-kendall commented 2 years ago

You called it, @FabioBatSilva . Thanks! Now ready for review.

kendall@LAPTOP-NOB8B23P:/mnt/c/Users/kenda/development/src/ArduinoFake$ make
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Git: /usr/bin/git (found version "2.25.1")
Cloning branch v2.4.1 from https://github.com/ThrowTheSwitch/Unity.git into directory /mnt/c/Users/kenda/development/src/ArduinoFake/external/unity/unity-repo
Cloning into '/mnt/c/Users/kenda/development/src/ArduinoFake/external/unity/unity-repo'...
Note: switching to 'f96c05532b3e00c9ca77e58fc07f9401cd46510d'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/c/Users/kenda/development/src/ArduinoFake/build
make[1]: Entering directory '/mnt/c/Users/kenda/development/src/ArduinoFake/build'
make[2]: Entering directory '/mnt/c/Users/kenda/development/src/ArduinoFake/build'
make[2]: Warning: File 'CMakeFiles/Makefile2' has modification time 0.27 s in the future
make[3]: Entering directory '/mnt/c/Users/kenda/development/src/ArduinoFake/build'
make[3]: Warning: File 'external/unity/CMakeFiles/unity.dir/progress.make' has modification time 0.18 s in the future
Scanning dependencies of target unity
make[3]: warning:  Clock skew detected.  Your build may be incomplete.
make[3]: Leaving directory '/mnt/c/Users/kenda/development/src/ArduinoFake/build'
make[3]: Entering directory '/mnt/c/Users/kenda/development/src/ArduinoFake/build'
make[3]: Warning: File 'external/unity/CMakeFiles/unity.dir/progress.make' has modification time 0.016 s in the future
[  6%] Building C object external/unity/CMakeFiles/unity.dir/unity-repo/src/unity.c.o
[ 13%] Linking C static library libunity.a
make[3]: warning:  Clock skew detected.  Your build may be incomplete.
make[3]: Leaving directory '/mnt/c/Users/kenda/development/src/ArduinoFake/build'
[ 13%] Built target unity
make[3]: Entering directory '/mnt/c/Users/kenda/development/src/ArduinoFake/build'
Scanning dependencies of target ArduinoFake
make[3]: Leaving directory '/mnt/c/Users/kenda/development/src/ArduinoFake/build'
make[3]: Entering directory '/mnt/c/Users/kenda/development/src/ArduinoFake/build'
make[3]: Warning: File 'src/CMakeFiles/ArduinoFake.dir/depend.make' has modification time 0.25 s in the future
[ 20%] Building CXX object src/CMakeFiles/ArduinoFake.dir/ArduinoFake.cpp.o
[ 26%] Building CXX object src/CMakeFiles/ArduinoFake.dir/ClientFake.cpp.o
[ 33%] Building CXX object src/CMakeFiles/ArduinoFake.dir/FunctionFake.cpp.o
[ 40%] Building CXX object src/CMakeFiles/ArduinoFake.dir/PrintFake.cpp.o
[ 46%] Building CXX object src/CMakeFiles/ArduinoFake.dir/SerialFake.cpp.o
[ 53%] Building CXX object src/CMakeFiles/ArduinoFake.dir/StreamFake.cpp.o
[ 60%] Building CXX object src/CMakeFiles/ArduinoFake.dir/WireFake.cpp.o
[ 66%] Building CXX object src/CMakeFiles/ArduinoFake.dir/arduino/IPAddress.cpp.o
[ 73%] Building CXX object src/CMakeFiles/ArduinoFake.dir/arduino/WString.cpp.o
[ 80%] Building C object src/CMakeFiles/ArduinoFake.dir/arduino/noniso.c.o
[ 86%] Linking CXX shared library libArduinoFake.so
make[3]: warning:  Clock skew detected.  Your build may be incomplete.
make[3]: Leaving directory '/mnt/c/Users/kenda/development/src/ArduinoFake/build'
[ 86%] Built target ArduinoFake
make[3]: Entering directory '/mnt/c/Users/kenda/development/src/ArduinoFake/build'
Scanning dependencies of target main
make[3]: Leaving directory '/mnt/c/Users/kenda/development/src/ArduinoFake/build'
make[3]: Entering directory '/mnt/c/Users/kenda/development/src/ArduinoFake/build'
make[3]: Warning: File 'test/CMakeFiles/main.dir/depend.make' has modification time 0.3 s in the future
[ 93%] Building CXX object test/CMakeFiles/main.dir/main.cpp.o
[100%] Linking CXX executable main
make[3]: warning:  Clock skew detected.  Your build may be incomplete.
make[3]: Leaving directory '/mnt/c/Users/kenda/development/src/ArduinoFake/build'
[100%] Built target main
make[2]: warning:  Clock skew detected.  Your build may be incomplete.
make[2]: Leaving directory '/mnt/c/Users/kenda/development/src/ArduinoFake/build'
make[1]: Leaving directory '/mnt/c/Users/kenda/development/src/ArduinoFake/build'
make[1]: Entering directory '/mnt/c/Users/kenda/development/src/ArduinoFake/build'
Running tests...
Test project /mnt/c/Users/kenda/development/src/ArduinoFake/build
    Start 1: main
1/1 Test #1: main .............................   Passed    0.10 sec

100% tests passed, 0 tests failed out of 1

Total Test time (real) =   0.14 sec
make[1]: Leaving directory '/mnt/c/Users/kenda/development/src/ArduinoFake/build'
FabioBatSilva commented 2 years ago

Thanks @wrong-kendall :+1: