online-judge-tools / verification-helper

a testing framework for snippet libraries used in competitive programming
MIT License
227 stars 54 forks source link

The case-sensitivity of file systems depends OS and make confusing errors #259

Open kmyk opened 4 years ago

kmyk commented 4 years ago

Paths are case-insensitive in Windows and macOS but case-sensitive in Linux and GitHub Actions (which uses Ubuntu).

This problem appears as No such file or directory errors in the phase to analyze dependencies of files, and also users cannot reproduce it on their local environments. As the result, it's very difficult for users to recognize what is wrong.

INFO:onlinejudge_verify.verify:verify: /home/runner/work/CompetitiveProgramming/CompetitiveProgramming/kyopro/test/unionfind_yosupo-judge.test.cpp
/home/runner/work/CompetitiveProgramming/CompetitiveProgramming/kyopro/test/unionfind_yosupo-judge.test.cpp:5:10: fatal error: ../Library/DataStructure/unionfind.cpp: No such file or directory
 #include "../Library/DataStructure/unionfind.cpp"
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

被害者1

@kmyk ありがとうございます。

https://github.com/knshnb/competitive_library/runs/618276854?check_suite_focus=true ここに書くべきでは無いかもしれませんが、そもそもこれがコンパイル通っていない原因もわかっていません(テストで落ちるのでとりあえずファイルをignoreしたりファイル名変更して対応しようとした結果が先程のissueです)。

手元のMac環境ではoj-verify runは通っていて、依存関係は特に問題ないように思えるのですが… (問題ファイル: https://github.com/knshnb/competitive_library/blob/e4a8328a5afcafb5a4604fbb9fe781df8b4a9e0c/test/yukicoder/1036_segment_tree.test.cpp)

https://github.com/online-judge-tools/verification-helper/issues/228#issuecomment-619986014

被害者2

kmyk commented 4 years ago

GitHub Actions 上で検出して対処しようとすると「パス名の曖昧検索」みたいなのが必要になってしんどそう。 ユーザのローカル環境上で再現しないのが問題なので、ユーザ環境上で検出するので十分そう。ユーザ環境なら勝手に自動で曖昧検索が有効と同義な状況なので、普通に実行して得られた依存関係のグラフを見れば検出ができる。

kmyk commented 4 years ago

これはおそらくみな高確率でひっかかる罠なので警告を出しておきたい。しかし私は Windows も macOS も持ってないのでデバッグが不可能です。よって協力者を募集したい。たすけて


以下を順番に実行すると deps.txt というファイルができるはずなので、その中身を教えてください。Windows の場合と macOS の場合の両方が知りたいです。なお Windows の人は必ず cmd.exe や PowerShell 上で実行してください (WSL はだめです)。

  1. 中身が空の hoge/FUGA/piyo.h という名前のファイルを作る
  2. 中身に #include "hoge/fuga/PIYO.h" と書かれた test.cpp という名前のファイルを作る
  3. $ g++ -std=c++14 -MD -MF deps.txt -MM test.cpp を実行する

cc @knshnb @null0124 @wakuwinmail

null0124 commented 4 years ago

@kmyk これはフォルダに入れずに / の入った名前で試すということであっていますか そうであるとすると、Windows 環境でファイル名に /, \, などを含めるファイルは作成できないらしいので実行できなさそうです

kmyk commented 4 years ago

@null0124 いいえ、hoge というフォルダの中の FUGA というフォルダの中に piyo.h というファイルを作ってください。

\ で書くとmacOS の場合に紛らわしいなと思って / で書いたのですが、今度は Windows の場合で紛らわしかったですね :bow:

null0124 commented 4 years ago

@kmyk 回答ありがとうございます。 deps.txt の中身は test.o: test.cpp hoge/fuga/PIYO.h になってました

knshnb commented 4 years ago

MacOS (Catalina 10.15.2)でも test.o: test.cpp hoge/fuga/PIYO.h になりました。

kmyk commented 4 years ago

@null0124 @knshnb ありがとうございます。

ということは g++ は #include "..." に書かれた文字列をそのまま出力しているぽいですね。g++ の出力を .resolve() して変化がないか判定するのが楽そうというのが分かりました。

kmyk commented 4 years ago

この手の微妙な仕様に依存するのは実はあまりよくないのだけど (壊れやすいので)、ここが嘘でも致命的ではないので、いきなり完璧は書かずにまずはお手軽実装で誤魔化していきます

kmyk commented 4 years ago

A hint message is added at https://github.com/online-judge-tools/verification-helper/pull/265

kmyk commented 4 years ago

「分かりにくい形で落ちるバグ」から「エラーの表示がすこし不親切なだけ」に緩和されました。とりあえずこれでいいかなと思うけど、まだ改善の余地はあるので issue 自体は残しておく